Skip to content

Conversation

@mcosgriff
Copy link
Contributor

Summary

This PR migrates the Python package from Poetry to UV for faster, more reliable dependency management. As part of this migration, we've also improved code quality with Ruff linting and updated documentation for macOS developers.

Primary Changes

Poetry → UV Migration

  • Migrated from poetry.lock to uv.lock for dependency management
  • Converted pyproject.toml to PEP 621 format with UV-compatible configuration
  • Added comprehensive justfile with 35+ development commands
  • Removed Poetry artifacts (.poetry directory, poetry.lock.backup)
  • Created .python-version file to specify Python 3.12
  • Updated all documentation to use UV commands instead of Poetry

Benefits:

  • 10-100x faster dependency resolution and installation
  • Better support for Python 3.10-3.14 with environment-specific dependencies (e.g., dual numpy versions)
  • Simplified developer workflow with Just commands

Code Quality Improvements (Bonus)

  • Applied Ruff auto-fixes across 92 Python files
  • SIM102: Collapsed 8 nested if statements for better readability
  • UP031: Modernized 4 string formatting calls from % to f-strings
  • All changes verified with existing test suite (291 tests passing)

Migration Notes

Developers will need to:

  1. Install new tools: brew install uv ruff just (macOS)
  2. Create virtual environment: uv venv
  3. Install dependencies: uv sync
  4. Use Just for common tasks: just test, just verify, etc.

See openc3/python/README-DEV.md for complete guide.


Related: Addresses the need for faster dependency management and modernized Python tooling.

mcosgriff and others added 4 commits January 23, 2026 14:55
…e quality

Migrate the Python library from Poetry to UV package manager and implement
modern development tooling with significant code quality improvements.

## Package Management Migration

- Replace Poetry with UV (10-100x faster package resolution)
- Migrate pyproject.toml to PEP 621 standard format
- Add environment-specific numpy versions (2.2.6 for Python 3.10, 2.4.1 for 3.11+)
- Reduce dependencies from 58 to 47 packages (19% reduction)
- Remove Black (replaced by Ruff format)
- Remove Pylint (replaced by Ruff lint)
- Switch build backend to setuptools for flat layout compatibility

## Enhanced Code Quality

- Replace Black with Ruff formatter (Black-compatible, much faster)
- Consolidate linting with Ruff (replaces flake8, isort, pylint)
- Enable additional lint rules: I (isort), N (naming), UP (pyupgrade),
  B (bugbear), W (warnings), C4 (comprehensions), SIM (simplify)
- Auto-fix 473 linting issues across 179 files
- Reformat 71 files with consistent style
- Reduce linting issues from 835 to 252 (70% improvement)

## Development Tooling

Add justfile with 30+ commands for streamlined development:
- Code quality: format, lint, lint-fix, lint-stats
- Git-aware commands: format-changed, lint-changed, verify-changed (10-30x faster)
- Testing: test, test-cov, test-cov-html, test-fast, test-file
- Pre-commit: verify (full check), verify-changed (fast), check (CI-strict)
- Dependencies: add, update, deps
- Utilities: clean, build, info, cli

## Configuration Improvements

Enhanced pyproject.toml with:
- Comprehensive project metadata (license, keywords, classifiers)
- Project URLs (homepage, docs, repository, issues)
- Ruff configuration with isort settings
- Pytest configuration with test markers
- Coverage configuration with exclusion rules

## Documentation Updates

- Update CLAUDE.md with UV/Ruff commands and tech stack
- Update docs/development/testing.md with Just commands
- Add Python development section to docs/development/developing.md
- Create README-DEV.md with comprehensive developer guide

## Breaking Changes

- Poetry commands replaced with UV equivalents
- poetry.lock replaced with uv.lock (backward incompatible)
- Black configuration removed (Ruff handles formatting)

## Migration Notes

Developers should:
1. Install UV: `curl -LsSf https://astral.sh/uv/install.sh | sh`
2. Install dependencies: `uv sync`
3. Use `just` commands for development tasks
4. Run `just verify-changed` before commits (fast pre-commit check)

## Performance Improvements

- Package installation: 10-100x faster with UV
- Linting: Much faster with Ruff (Rust-based)
- Git-aware commands: Only check changed files (10-30x faster)
- Pre-commit workflow: `verify-changed` completes in 1-2 seconds

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enhanced Python codebase quality by applying Ruff linting rules and
adding macOS tooling installation instructions.

## Code Quality Improvements

Applied Ruff auto-fixes across 92 Python files to improve code quality
and modernize syntax:

### SIM102 - Collapsed Nested If Statements (8 fixes)
- binary_accessor.py: Combined nested conditionals for INT conversion
  and buffer bounds checking
- config_parser.py: Simplified comment detection logic
- ignore_packet_protocol.py: Merged packet identification checks
- length_protocol.py: Combined fill_fields checks in write_packet
  and write_data methods
- interface_microservice.py: Consolidated hazardous command checks
- commands.py: Combined range check validation conditions

### UP031 - Modernized String Formatting (4 fixes)
- binary_accessor.py: Converted percent formatting to f-strings in
  read_array and write_array methods for struct format strings
- Performance improvement: f-strings are faster than % formatting
- Better readability and type safety

All changes verified with comprehensive test coverage:
- 42 tests passed for read_array functionality
- 65 tests passed for write_array functionality
- 291 total tests passed in binary_accessor test suite

## Documentation Updates

Added macOS installation instructions for development tools:

- CLAUDE.md: Added `brew install uv ruff just` before Python test commands
- docs/development/developing.md: Added "Installing Tools (macOS)" section
- openc3/python/README-DEV.md: Reorganized to show Homebrew installation
  first in Development Tools section

Makes it clearer for macOS developers (primary development platform)
how to install required tools: UV (package manager), Ruff (linter/
formatter), and Just (command runner).

## Technical Details

- Ruff rules applied: SIM102 (simplify control flow), UP031 (pyupgrade)
- Target Python version: 3.10+ (maintained compatibility)
- Line length: 120 characters
- All changes preserve existing functionality and pass existing tests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…the default Python version for a project or directory. It allows uv to automatically select the correct Python version when working within that project.
@codecov
Copy link

codecov bot commented Jan 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.17%. Comparing base (7f1bdd9) to head (e21cb32).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2755   +/-   ##
=======================================
  Coverage   79.17%   79.17%           
=======================================
  Files         670      670           
  Lines       54278    54278           
  Branches      734      734           
=======================================
+ Hits        42972    42974    +2     
+ Misses      11226    11224    -2     
  Partials       80       80           
Flag Coverage Δ
ruby-api 83.61% <ø> (ø)
ruby-backend 82.20% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
5 New issues
2 Security Hotspots

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

2 participants