Skip to content

Major architecture changes to improve CI vs. pre-commit selection logic#1286

Merged
nathanjmcdougall merged 23 commits intomainfrom
980-reconsider-internal-placement-of-logic-to-choose-between-ci-and-pre-commit
Feb 10, 2026
Merged

Major architecture changes to improve CI vs. pre-commit selection logic#1286
nathanjmcdougall merged 23 commits intomainfrom
980-reconsider-internal-placement-of-logic-to-choose-between-ci-and-pre-commit

Conversation

@nathanjmcdougall
Copy link
Collaborator

No description provided.

@nathanjmcdougall nathanjmcdougall changed the title 980 reconsider internal placement of logic to choose between ci and pre commit Major architecture changes to improve CI vs. pre-commit selection logic Jan 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a major architecture refactoring that reorganizes internal module structure to improve separation of concerns. The changes primarily move code from usethis._integrations to more appropriately named top-level modules and introduces new detection logic for CI and pre-commit usage.

Changes:

  • Moved file manipulation modules from _integrations.file to _file for cleaner architecture
  • Moved backend-specific code from _integrations.backend to _backend
  • Moved Python version handling from _integrations.python to _python
  • Created new _detect module with detection functions for CI, pre-commit, and README usage
  • Improved CI vs pre-commit selection logic in tool base classes
  • Updated Ruff version from v0.14.10 to v0.14.11
  • Updated UV fallback version from 0.9.21 to 0.9.24

Reviewed changes

Copilot reviewed 115 out of 133 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/usethis/*.py Updated import paths to reflect new module structure
tests/usethis/_ui/interface/*.py Updated import paths for backend, file, and python modules
tests/usethis/_tool/**/*.py Updated import paths for file and python version modules
tests/usethis/_integrations/**/*.py Updated import paths for file, backend, and detection modules
tests/usethis/_file/**/*.py Updated import paths for newly relocated file modules
tests/usethis/_backend/**/*.py Updated import paths for backend-specific modules
tests/usethis/_core/*.py Updated import paths and detection logic usage
tests/*.py Updated import paths for backend and file modules
src/usethis/_ui/ruff.toml Added banned imports for new _backend and _detect modules
src/usethis/_ui/interface/readme.py Updated import paths and moved detection logic
src/usethis/_tool/impl/*.py Updated imports and improved pre-commit vs CI detection logic
src/usethis/_tool/base.py Added detection imports and refined CI/pre-commit logic
src/usethis/_integrations/**/*.py Updated import paths to use new module structure
src/usethis/_integrations/readme/path.py New file with README path detection logic moved from _core/readme.py
src/usethis/_integrations/ci/bitbucket/used.py Deleted file, functionality moved to _detect/ci/bitbucket.py
src/usethis/_init.py Updated imports to use new module structure
src/usethis/_file/**/*.py Updated internal imports after relocation
src/usethis/_detect/**/*.py New detection module with CI, pre-commit, and README detection
src/usethis/_deps.py Updated imports for backend modules
src/usethis/_core/*.py Updated imports and refactored to use new detection module
src/usethis/_config_file.py Updated imports for file and backend modules
src/usethis/_backend/**/*.py Updated internal imports after relocation and version bumps
pyproject.toml Updated type checker configuration for new module structure
.importlinter Updated architecture constraints for new module organization

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 99.17355% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_backend/uv/call.py 89.47% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing 980-reconsider-internal-placement-of-logic-to-choose-between-ci-and-pre-commit (9dedc7c) with main (5d9732d)

Summary

✅ 2 untouched benchmarks

@nathanjmcdougall nathanjmcdougall merged commit 937a94b into main Feb 10, 2026
19 checks passed
@nathanjmcdougall nathanjmcdougall deleted the 980-reconsider-internal-placement-of-logic-to-choose-between-ci-and-pre-commit branch February 10, 2026 07:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 117 out of 135 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (17)

src/usethis/_tool/impl/mkdocs.py:64

  • This 'lambda' is just a simple wrapper around a callable object. Use that object directly.
    src/usethis/_tool/impl/deptry.py:47
  • Variable _dir is not used.
    src/usethis/file/ini/io.py:161
  • Variable section_key is not used.
    src/usethis/file/toml/io.py:399
  • Variable toml_document is not used.
    src/usethis/file/yaml/io.py:423
  • Variable content is not used.
    src/usethis/_core/badge.py:238
  • This assignment to 'path' is unnecessary as it is redefined before this value is used.
    path = usethis_config.cpd() / "README.md"

tests/usethis/_integrations/sonarqube/test_sonarqube_config.py:371

  • The result of _validate_project_key is used even though it is always None.
    src/usethis/file/pyproject_toml/io.py:72
  • This method raises PyprojectTOMLValueMissingError - should raise a LookupError (KeyError or IndexError) instead.
    src/usethis/file/setup_cfg/io.py:72
  • This method raises SetupCFGValueMissingError - should raise a LookupError (KeyError or IndexError) instead.
    src/usethis/file/ini/io.py:346
  • This method raises ININestingError - should raise a LookupError (KeyError or IndexError) instead.
    src/usethis/_deps.py:3
  • Module 'pydantic' is imported with both 'import' and 'import from'.
    Module 'usethis._integrations.pydantic' is imported with both 'import' and 'import from'.
import pydantic

tests/usethis/_backend/uv/test_available.py:3

  • Module 'usethis._backend.uv.available' is imported with both 'import' and 'import from'.
    tests/usethis/_backend/uv/test_call.py:5
  • Module 'usethis._backend.uv.call' is imported with both 'import' and 'import from'.
    tests/usethis/_core/test_core_tool.py:3
  • Module 'unittest.mock' is imported with both 'import' and 'import from'.
    tests/usethis/_backend/uv/test_lockfile.py:6
  • Module 'usethis._backend.uv.lockfile' is imported with both 'import' and 'import from'.
    src/usethis/_integrations/environ/python.py:58
  • 'except' clause does nothing but pass and there is no explanatory comment.
    src/usethis/_tool/impl/pytest.py:315
  • Unnecessary 'pass' statement.

Comment on lines +681 to +686
# If pre-commit is being used and this is not the PreCommitTool itself,
# don't add Bitbucket steps (the tool will run via pre-commit instead)
if is_pre_commit_used():
return

self._unconditional_update_bitbucket_steps(matrix_python=matrix_python)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool.update_bitbucket_steps() returns early when pre-commit is used, which prevents cleanup of any previously-added Bitbucket steps for this tool. This can leave stale per-tool CI steps in bitbucket-pipelines.yml after a project switches to running QA via pre-commit (or after use_ci_bitbucket() is re-run), causing duplicated CI work. Consider removing this tool’s managed Bitbucket steps when is_pre_commit_used() is true (or otherwise ensuring stale steps are cleaned up) before returning.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +6
def is_readme_used():
"""Check if the README.md file is used."""
try:
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_readme_used is missing a -> bool return annotation, and the docstring says it checks whether README.md is used even though get_readme_path() detects several README variants. Align the docstring with behavior and add the return type for consistency with the other detection helpers.

Copilot uses AI. Check for mistakes.
import usethis._integrations.backend.dispatch
import usethis._integrations.python.version
import usethis._backend.dispatch
import usethis._python.version
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module 'usethis._python.version' is imported with both 'import' and 'import from'.

Copilot uses AI. Check for mistakes.
@@ -5,9 +5,9 @@
import usethis._tool.impl.pytest
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module 'usethis._tool.impl.pytest' is imported with both 'import' and 'import from'.

Copilot uses AI. Check for mistakes.
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.

Reconsider internal placement of logic to choose between CI and pre-commit

2 participants