Major architecture changes to improve CI vs. pre-commit selection logic#1286
Conversation
…t vs. bitbucket selection logic in the `use_*` functions in `src\usethis\_core\tool.py`
There was a problem hiding this comment.
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.fileto_filefor cleaner architecture - Moved backend-specific code from
_integrations.backendto_backend - Moved Python version handling from
_integrations.pythonto_python - Created new
_detectmodule 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 |
…estTool::TestAddPreCommitConfig::test_multiple_repo_configs
…st yet but is created by uv
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
There was a problem hiding this comment.
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.
| # 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) |
There was a problem hiding this comment.
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.
| def is_readme_used(): | ||
| """Check if the README.md file is used.""" | ||
| try: |
There was a problem hiding this comment.
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.
| import usethis._integrations.backend.dispatch | ||
| import usethis._integrations.python.version | ||
| import usethis._backend.dispatch | ||
| import usethis._python.version |
There was a problem hiding this comment.
Module 'usethis._python.version' is imported with both 'import' and 'import from'.
| @@ -5,9 +5,9 @@ | |||
| import usethis._tool.impl.pytest | |||
There was a problem hiding this comment.
Module 'usethis._tool.impl.pytest' is imported with both 'import' and 'import from'.
No description provided.