Skip to content

Fetchcord 3 release#229

Open
BlivionIaG wants to merge 68 commits intomasterfrom
testing
Open

Fetchcord 3 release#229
BlivionIaG wants to merge 68 commits intomasterfrom
testing

Conversation

@BlivionIaG
Copy link
Copy Markdown
Member

@BlivionIaG BlivionIaG commented Apr 21, 2024

FetchCord 3.0.0 - Major Rewrite

Summary

Complete rewrite migrating from neofetch to fastfetch. Requires Python 3.10+.

Breaking Changes

  • Python 3.10+ required
  • Migrated from neofetch to fastfetch
  • New modular architecture (Config, Cycle, Fetch, Tools)
  • Old computer/ module removed

Migration Guide

Install fastfetch:

# macOS
brew install fastfetch

# Linux
sudo apt install fastfetch  # Debian/Ubuntu
sudo pacman -S fastfetch     # Arch

Update FetchCord:

pip3 install --upgrade fetchcord

Testing

pip install -e .
python -m pytest tests/ -v

Changes

  • New constants.py for configuration
  • Added pyproject.toml
  • 32 new tests
  • Security improvements (input validation, path traversal protection)
  • Full type hints
  • macOS: Flatpak detection disabled (Linux-only)

BlivionIaG and others added 30 commits June 10, 2021 20:09
* Add asrock motherboard support

* import fix

* version update for fix

* Fix future import bug and amd A series detection

* version update for fix

* fix packaging

* Manifest stuff

* INtel gpu fix

* Add some acer mobo

* (test) add optiplex (generic)

* oops

* ideapad test

* Add snap support (#146)

* Create snapcraft.yml

* add snap support

* fix README

* Add parrot OS config

Co-authored-by: Tabulate <tabulatejarl8@gmail.com>
This reverts commit ff5bdc3.

	deleted:    asusmobo.txt
	deleted:    parrot.txt
	deleted:    yeet.txt
* Fetchcord v2.7.7 (#153) (#154)

* Add parrot OS  (#153)

* Add asrock motherboard support

* import fix

* version update for fix

* Fix future import bug and amd A series detection

* version update for fix

* fix packaging

* Manifest stuff

* INtel gpu fix

* Add some acer mobo

* (test) add optiplex (generic)

* oops

* ideapad test

* Add snap support (#146)

* Create snapcraft.yml

* add snap support

* fix README

* Add parrot OS config

Co-authored-by: Tabulate <tabulatejarl8@gmail.com>

* fix windows scoop neofetch compatibility

* Update version number

* Add more mobo support and os's

* Add mageia

* Add elitedesk 800 g1

* Fix debug and add windows 11

* Add athlon silver & gold cpu support

* Prepare alt mobo detect

* [untested] motherboard fix

* Add some random acer laptop

* Add elementary os support and thinkcenter

* Disable logger

* Revert "Disable logger"

This reverts commit ff5bdc3.

	deleted:    asusmobo.txt
	deleted:    parrot.txt
	deleted:    yeet.txt

* Disable logger file

* Add terminus / elementary os terminal

* Add windows terminal

* fix windows terminal detection

Co-authored-by: Tabulate <tabulatejarl8@gmail.com>

* Update README.md

* Update README.md

* Update README.md (#165)

* first iteration of GUI

* add launch option with --gui

* update README

Co-authored-by: Kévin Le Torc'h <kev29lt@gmail.com>
Co-authored-by: MelonMan <73000042+MelonicOverlord@users.noreply.github.com>
Fixes #149 by altering the `boot_time()` function so that it works on UNIX-based OS's. Pulled the same function from PSUTIL for the Windows detection.

* Following the zen of python

Co-authored-by: Kévin Le Torc'h <kev29lt@gmail.com>
Co-authored-by: Tabulate <tabulatejarl8@gmail.com>
Co-authored-by: MelonMan <73000042+MelonicOverlord@users.noreply.github.com>
Building from testing currently produces the `ValueError: Newlines are not allowed` exception when `setuptools.setup()` is called, presumably due to new functionality in `setuptools`. For building on the latest setuptools, all newlines (`\n`) in the code needs to go. I have already raised the issue in the support Discord Server.
Removed int(client_id) from rpc.update() call. The client_id should
only be passed to Presence() constructor, not to update().

- update() first param is pid (process ID), not client_id
- client_id correctly passed to Presence(int(client_id)) on line 37
- File compiles without errors

Refs: fetchcord-testing-fixes Task 2
Changed self.wait(int(self.time)) to handle None values:
- If self.time is None, uses default 30 seconds
- If self.time has value, uses that value
- Prevents TypeError when time is not set

Refs: fetchcord-testing-fixes Task 3
Changed Optional[str | None] to Optional[str] in:
- fetch_cord/native/native.py (line 9)
- fetch_cord/native/Windows/__init__.py (line 7)

The | union syntax is Python 3.10+ only, but setup.py requires >=3.7.
Optional[str] is the correct 3.7+ compatible syntax.

Refs: fetchcord-testing-fixes Task 4
As of April 2026, Python 3.10 is the oldest supported version.
- 3.7 EOL: June 2023
- 3.8 EOL: October 2024
- 3.9 EOL: October 2025
- 3.10 supported until October 2026

Refs: fetchcord-testing-fixes
Revert to using str | None syntax since minimum Python is now 3.10.
This is cleaner and more explicit than Optional[str].

Refs: fetchcord-testing-fixes
Removed get_infos() from get_resources.py (unused, referenced missing file).
Updated update.py to download individual JSON files:
- cpus.json, gpus.json, os.json, terminal.json
- shell.json, motherboards.json, system_types.json

Refs: fetchcord-testing-fixes Task 5
Removed old test file that referenced removed computer module.
Created new test file with 32 tests covering:
- Config: YAML loading, dict behavior, defaults
- Cycle: initialization, setup, connect, update, wait
- Fetch: class init, get_infos, get_component_id
- Tools: exec_bash, exec_ps1, run_command
- Integration tests

Uses unittest with mocks for external dependencies.

Refs: fetchcord-testing-fixes Task 6
Changed # 1/usr/bin/env python3 to #!/usr/bin/env python3

Refs: fetchcord-testing-fixes Task 7
Updated setup.py with minimum version pins for security:
- pypresence>=4.3.0 (latest stable)
- psutil>=5.9.0 (security fixes)
- pyyaml>=6.0.1 (CVE-2020-14343 fix)

Removed importlib-resources (not needed for Python 3.10+)

Created requirements.txt for development.

Refs: fetchcord-testing-fixes
Created pyproject.toml with modern Python packaging standards:
- PEP 517/518 build system configuration
- Project metadata and dependencies
- Optional dev dependencies (pytest, black, ruff, mypy)
- Tool configurations for code quality
- Package data and entry points

This follows modern Python packaging best practices and
provides better IDE support and build reproducibility.

Refs: fetchcord-testing-fixes
Fixed CRITICAL and HIGH severity security issues:

1. systemd_service.py - Command injection prevention:
   - Added validate_systemd_cmd() to whitelist valid commands
   - Use os.path.join() instead of string concatenation
   - Quote file paths to handle spaces safely
   - Replace tilde ~ with os.path.expanduser()

2. update.py - Path traversal prevention:
   - Added validate_filename() to prevent path traversal
   - Use pathlib.Path instead of string concatenation
   - Validate filenames against whitelist pattern
   - Ensure .json extension

3. flatpak.py - Environment variable validation:
   - Added get_home_dir() to validate HOME env var
   - Check HOME is absolute path
   - Use pathlib.Path for safe path operations
   - Quote paths in shell commands

Security improvements:
- Input validation on all user-controlled inputs
- Safe path operations using pathlib
- Proper error handling
- Prevention of command injection attacks

Refs: Security audit findings
Major refactoring improvements:

1. **Fixed import side effects** (CRITICAL):
   - Removed module-level parse_args() calls from update.py and systemd_service.py
   - Functions now accept parameters instead of relying on global args
   - Prevents side effects when modules are imported

2. **Created constants.py**:
   - Centralized all magic numbers and strings
   - Timing constants (MIN_CYCLE_TIME_SECONDS, DEFAULT_CYCLE_TIME_SECONDS, etc.)
   - Git branch constants (TESTING_BRANCH, DEFAULT_BRANCH)
   - Error message templates
   - Resource file list
   - Service file URL template

3. **Updated function signatures**:
   - update(testing: bool = False)
   - install(testing: bool = False)
   - get_service_file_url(testing: bool) -> str

Benefits:
- No side effects at import time
- Single source of truth for constants
- Easier to test (explicit dependencies)
- Better separation of concerns

Refs: Refactoring analysis findings
Removed duplicate get_resource_path() from Config.py.
Now imports from Tools module, following DRY principle.

- Config.py now imports get_resource_path from Tools
- Single source of truth for resource path lookup
- Reduced code duplication

Refs: Refactoring analysis findings
Merged master branch into testing to prepare for clean merge to master.
Resolved all conflicts by keeping testing branch version (3.0.0 architecture).

Conflicts resolved:
- README.md: Kept testing version
- __init__.py: Kept VERSION = 3.0.0
- Removed old files from master:
  - fetch_cord/computer/ (entire directory)
  - fetch_cord/cycles.py
  - fetch_cord/debugger.py
  - fetch_cord/resources/fetchcord_ids.json
  - fetch_cord/run_rpc.py
  - fetch_cord/run_command.py

After this commit, testing branch contains both:
- All old history from master
- All new 3.0.0 changes from testing

This allows a clean fast-forward merge from testing to master.
Updated documentation with:
- Python 3.10+ requirement badge and notes
- Changed neofetch references to fastfetch
- Added 'What's New in 3.0.0' section with breaking changes
- Documented new architecture (Config, Cycle, Fetch, Tools modules)
- Added security improvements mention
- Complete arguments list with new options
- Cleaned up installation instructions

Refs: Documentation update for 3.0.0 release
Fixed macOS-related issues:
- flatpak.py: Skip flatpak detection on macOS (Flatpak is Linux-only)
- default.conf: Update comment from neofetch to fastfetch reference

The flatpak module now early-returns on Darwin systems since Flatpak
is a Linux-only package manager and doesn't exist on macOS.

Refs: macOS code review findings
setup.py was importing fetch_cord to get VERSION, which fails during
editable installs because the package isn't built yet. Now reads the
version directly from the file using regex.

Refs: Testing feedback
Changed from old MrPotatoBobx URL to fetchcord organization URL.

Refs: Testing feedback
Added Brewfile to simplify macOS dependency installation.
Users can now run 'brew bundle' to install fastfetch.

Refs: macOS installation improvement
Remove comments and Python reference, keep only fastfetch.
- Add Homebrew instructions to README
- Fix VERSION to 3.0.0 in __init__.py
Added patterns for:
- M4, M4 Pro, M4 Max, M4 Ultra
- M3, M3 Pro, M3 Max, M3 Ultra
- Apple GPU detection

Note: Placeholder IDs need to be replaced with actual Discord app IDs
When detecting Apple M chips (M1, M2, M3, M4, M5), use the chip name
as the large_image asset instead of 'big'. This displays the chip
image in Discord Rich Presence.

Example: 'Apple M4 Pro' becomes 'apple-m4-pro' asset name.
Using application ID 1490489143522758866 for all Apple M1-M5 chips.

Refs: Discord app setup
Close all RPC connections when receiving SIGINT/SIGTERM or when the
main loop exits. This prevents stale connections in Discord.
Remove rpc.close() from update() method so the connection stays
open between cycles. This allows Discord to properly update the
activity when switching from one cycle to another.

The connection is now only closed on program shutdown.
Call rpc.clear() before closing connection to immediately remove
the Rich Presence activity from Discord. Previously the activity
persisted until Discord was restarted.
When cycling between different Discord Rich Presence applications
(e.g., CPU cycle -> GPU cycle with different client_ids), the
activity was getting stuck on the first cycle.

The issue was that Discord only allows one Rich Presence connection
at a time per application. When switching client_ids, we were only
closing the current cycle's RPC connection, but the previous cycle's
connection was still active.

Changes:
- Cycle.py: Add close_connection() method to properly clear and
  close RPC with a small delay to let Discord release resources
- __main__.py: Close ALL cycles' connections when client_id changes,
  not just the current cycle
- Proper exception handling to force reconnection on errors
Use environment variables (ghostty, /bin/zsh) for more reliable
detection instead of relying solely on fastfetch, which detects the
parent process (Python) when running via 'python3 -m fetch_cord'.

Changes:
- fetchcord_cmds.yml: Use /bin/zsh for shell detection, ghostty for terminal
- terminal.json: Add patterns for iTerm2, Hyper, Warp, WezTerm
- Make patterns case-insensitive for better matching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants