-
Notifications
You must be signed in to change notification settings - Fork 3
Implement usethis arch command
#1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
de382c2
Initial plan
Copilot 5df8128
Implement usethis arch command for architecture tools (Import Linter)
Copilot 452e928
Add arch module to .importlinter ui_interface contract
Copilot d18a92f
Replace "architecture tools" with "architecture analysis tools" every…
Copilot 326b5f2
Add usethis arch entry to docs/cli/overview.md to match README
Copilot 77a37ae
Add test for usethis init --arch
Copilot a1e25e9
Merge branch 'main' into copilot/implement-usethis-arch
nathanjmcdougall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from usethis._core.tool import use_import_linter | ||
|
|
||
|
|
||
| def use_arch_tools(remove: bool = False, how: bool = False): | ||
| use_import_linter(remove=remove, how=how) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import typer | ||
|
|
||
| from usethis._config import usethis_config | ||
| from usethis._types.backend import BackendEnum | ||
| from usethis._ui.options import ( | ||
| backend_opt, | ||
| frozen_opt, | ||
| how_opt, | ||
| offline_opt, | ||
| quiet_opt, | ||
| remove_opt, | ||
| ) | ||
|
|
||
|
|
||
| def arch( | ||
| remove: bool = remove_opt, | ||
| how: bool = how_opt, | ||
| offline: bool = offline_opt, | ||
| quiet: bool = quiet_opt, | ||
| frozen: bool = frozen_opt, | ||
| backend: BackendEnum = backend_opt, | ||
| ) -> None: | ||
| """Add recommended architecture analysis tools to the project.""" | ||
| from usethis._config_file import files_manager | ||
| from usethis._console import err_print | ||
| from usethis._toolset.arch import use_arch_tools | ||
| from usethis.errors import UsethisError | ||
|
|
||
| assert isinstance(backend, BackendEnum) | ||
|
|
||
| with ( | ||
| usethis_config.set( | ||
| offline=offline, quiet=quiet, frozen=frozen, backend=backend | ||
| ), | ||
| files_manager(), | ||
| ): | ||
| try: | ||
| use_arch_tools(remove=remove, how=how) | ||
| except UsethisError as err: | ||
| err_print(err) | ||
| raise typer.Exit(code=1) from None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from pathlib import Path | ||
|
|
||
| from usethis._test import CliRunner, change_cwd | ||
| from usethis._ui.app import app | ||
|
|
||
|
|
||
| class TestArch: | ||
| def test_how_option(self, tmp_path: Path): | ||
| # Act | ||
| runner = CliRunner() | ||
| with change_cwd(tmp_path): | ||
| result = runner.invoke_safe(app, ["arch", "--how"]) | ||
|
|
||
| # Assert | ||
| assert result.exit_code == 0, result.output | ||
| assert "lint-imports" in result.output | ||
|
|
||
| def test_none_backend_pyproject_toml(self, tmp_path: Path): | ||
| # Arrange | ||
| (tmp_path / "pyproject.toml").write_text( | ||
| '[project]\nname = "myproject"\n\n[tool.usethis]\n' | ||
| ) | ||
| (tmp_path / "src" / "myproject").mkdir(parents=True) | ||
| (tmp_path / "src" / "myproject" / "__init__.py").touch() | ||
| (tmp_path / "src" / "myproject" / "a.py").touch() | ||
| (tmp_path / "src" / "myproject" / "b.py").touch() | ||
| (tmp_path / "src" / "myproject" / "c.py").touch() | ||
|
|
||
| # Act | ||
| runner = CliRunner() | ||
| with change_cwd(tmp_path): | ||
| result = runner.invoke_safe(app, ["arch", "--backend", "none"]) | ||
|
|
||
| # Assert | ||
| assert result.exit_code == 0, result.output | ||
| assert "☐ Add the dev dependency 'import-linter'." in result.output | ||
| assert "Adding Import Linter config to 'pyproject.toml'." in result.output | ||
| assert "lint-imports" in result.output | ||
|
|
||
| def test_add_then_remove(self, tmp_path: Path): | ||
| # Arrange | ||
| (tmp_path / "pyproject.toml").write_text( | ||
| '[project]\nname = "myproject"\n\n[tool.usethis]\n' | ||
| ) | ||
| (tmp_path / "src" / "myproject").mkdir(parents=True) | ||
| (tmp_path / "src" / "myproject" / "__init__.py").touch() | ||
| (tmp_path / "src" / "myproject" / "a.py").touch() | ||
| (tmp_path / "src" / "myproject" / "b.py").touch() | ||
| (tmp_path / "src" / "myproject" / "c.py").touch() | ||
|
|
||
| runner = CliRunner() | ||
|
|
||
| with change_cwd(tmp_path): | ||
| # Act: Add arch | ||
| result = runner.invoke_safe(app, ["arch", "--backend", "none"]) | ||
| assert result.exit_code == 0, result.output | ||
|
|
||
| # Act: Remove arch | ||
| result = runner.invoke_safe(app, ["arch", "--remove", "--backend", "none"]) | ||
|
|
||
| # Assert | ||
| assert result.exit_code == 0, result.output | ||
| assert "Removing" in result.output | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.