Skip to content

Commit

Permalink
Add import-linter (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjmcdougall authored Oct 24, 2024
1 parent 8cdfbf1 commit 501f579
Show file tree
Hide file tree
Showing 48 changed files with 234 additions and 86 deletions.
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dev-dependencies = [
"pytest-cov>=5.0.0",
"gitpython>=3.1.43",
"pre-commit>=4.0.1",
"import-linter>=2.1",
]

[tool.ruff]
Expand All @@ -52,3 +53,19 @@ addopts = [
[tool.coverage.run]
source = ["src"]
omit = ["*/pytest-of-*/*"]

[tool.importlinter]
root_packages = ["usethis"]

[[tool.importlinter.contracts]]
name = "Modular Design"
type = "layers"
layers = [
"__main__",
"_interface",
"_tool",
"_integrations",
"_utils"
]
containers=["usethis"]
exhaustive=true
6 changes: 0 additions & 6 deletions src/usethis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
import typer
from rich.console import Console

console = Console()

offline_opt = typer.Option(False, "--offline", help="Disable network access")
14 changes: 8 additions & 6 deletions src/usethis/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import typer

import usethis.browse
import usethis.ci
import usethis.tool
import usethis._interface.browse
import usethis._interface.ci
import usethis._interface.tool

app = typer.Typer(
help=(
"🤖 Automate Python package and project setup tasks that are otherwise "
"performed manually."
)
)
app.add_typer(usethis.tool.app, name="tool")
app.add_typer(usethis.browse.app, name="browse")
app.add_typer(usethis.ci.app, name="ci")
app.add_typer(usethis._interface.tool.app, name="tool")
app.add_typer(usethis._interface.browse.app, name="browse")
app.add_typer(usethis._interface.ci.app, name="ci")
app(prog_name="usethis")

__all__ = ["app"]
6 changes: 6 additions & 0 deletions src/usethis/_console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import typer
from rich.console import Console

console = Console()

offline_opt = typer.Option(False, "--offline", help="Disable network access")
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from usethis._yaml import edit_yaml, load_yaml
from usethis._utils._yaml import edit_yaml, load_yaml


class Cache(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from usethis import console
from usethis._console import console

_YAML_CONTENTS = """\
image: atlassian/default-image:3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pydantic import BaseModel

from usethis._bitbucket.cache import Cache, add_cache
from usethis._yaml import edit_yaml
from usethis._integrations.bitbucket.cache import Cache, add_cache
from usethis._utils._yaml import edit_yaml


class StepRef(BaseModel):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import subprocess
from pathlib import Path

from usethis import console
from usethis._github.tags import GitHubTagError, get_github_latest_tag
from usethis._console import console
from usethis._integrations.github.tags import GitHubTagError, get_github_latest_tag

_YAML_CONTENTS_TEMPLATE = """\
repos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import ruamel.yaml

from usethis._pre_commit.config import PreCommitRepoConfig
from usethis._yaml import edit_yaml
from usethis._integrations.pre_commit.config import PreCommitRepoConfig
from usethis._utils._yaml import edit_yaml

_HOOK_ORDER = [
"validate-pyproject",
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import mergedeep

from usethis._pyproject.io import read_pyproject_toml, write_pyproject_toml
from usethis._integrations.pyproject.io import (
read_pyproject_toml,
write_pyproject_toml,
)


class ConfigValueAlreadySetError(ValueError):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from packaging.specifiers import SpecifierSet

from usethis._pyproject.io import read_pyproject_toml
from usethis._integrations.pyproject.io import read_pyproject_toml

MIN_MAJOR_PY3 = 7 # Any earlier and uv won't support the executable.
MAX_MAJOR_PY3 = 13
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil
from pathlib import Path

from usethis import console
from usethis._console import console


def add_pytest_dir() -> None:
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from usethis import console
from usethis._pyproject.core import (
from usethis._console import console
from usethis._integrations.pyproject.core import (
append_config_list,
get_config_value,
remove_from_config_list,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from packaging.requirements import Requirement
from pydantic import TypeAdapter

from usethis import console
from usethis._pyproject.io import read_pyproject_toml
from usethis._console import console
from usethis._integrations.pyproject.io import read_pyproject_toml


def get_dev_deps() -> list[str]:
Expand Down
3 changes: 3 additions & 0 deletions src/usethis/_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import typer

offline_opt = typer.Option(False, "--offline", help="Disable network access")
2 changes: 1 addition & 1 deletion src/usethis/browse.py → src/usethis/_interface/browse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typer

from usethis import console
from usethis._console import console

app = typer.Typer(help="Visit important project-related web pages.")

Expand Down
11 changes: 7 additions & 4 deletions src/usethis/ci.py → src/usethis/_interface/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import typer

from usethis import console, offline_opt
from usethis._bitbucket.config import (
from usethis._console import console
from usethis._integrations.bitbucket.config import (
add_bitbucket_pipeline_config,
remove_bitbucket_pipeline_config,
)
from usethis._bitbucket.steps import Step, StepRef, add_steps
from usethis._pyproject.requires_python import get_supported_major_python_versions
from usethis._integrations.bitbucket.steps import Step, StepRef, add_steps
from usethis._integrations.pyproject.requires_python import (
get_supported_major_python_versions,
)
from usethis._interface import offline_opt
from usethis._tool import PreCommitTool, PytestTool

app = typer.Typer(help="Add config for Continuous Integration (CI) pipelines.")
Expand Down
11 changes: 6 additions & 5 deletions src/usethis/tool.py → src/usethis/_interface/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import typer

from usethis import console, offline_opt
from usethis._pre_commit.core import (
from usethis._console import console
from usethis._integrations.pre_commit.core import (
add_pre_commit_config,
install_pre_commit,
remove_pre_commit_config,
uninstall_pre_commit,
)
from usethis._pytest.core import add_pytest_dir, remove_pytest_dir
from usethis._ruff.rules import deselect_ruff_rules, select_ruff_rules
from usethis._integrations.pytest.core import add_pytest_dir, remove_pytest_dir
from usethis._integrations.ruff.rules import deselect_ruff_rules, select_ruff_rules
from usethis._integrations.uv.deps import add_dev_deps, remove_dev_deps
from usethis._interface import offline_opt
from usethis._tool import ALL_TOOLS, DeptryTool, PreCommitTool, PytestTool, RuffTool
from usethis._uv.deps import add_dev_deps, remove_dev_deps

app = typer.Typer(help="Add and configure development tools, e.g. linters.")

Expand Down
16 changes: 8 additions & 8 deletions src/usethis/_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
from pathlib import Path
from typing import Protocol

from usethis import console
from usethis._pre_commit.config import HookConfig, PreCommitRepoConfig
from usethis._pre_commit.core import add_pre_commit_config
from usethis._pre_commit.hooks import (
from usethis._console import console
from usethis._integrations.pre_commit.config import HookConfig, PreCommitRepoConfig
from usethis._integrations.pre_commit.core import add_pre_commit_config
from usethis._integrations.pre_commit.hooks import (
add_hook,
get_hook_names,
remove_hook,
)
from usethis._pyproject.config import PyProjectConfig
from usethis._pyproject.core import (
from usethis._integrations.pyproject.config import PyProjectConfig
from usethis._integrations.pyproject.core import (
ConfigValueAlreadySetError,
ConfigValueMissingError,
remove_config_value,
set_config_value,
)
from usethis._pyproject.io import read_pyproject_toml
from usethis._uv.deps import is_dep_used
from usethis._integrations.pyproject.io import read_pyproject_toml
from usethis._integrations.uv.deps import is_dep_used


class Tool(Protocol):
Expand Down
Empty file added src/usethis/_utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from usethis._bitbucket.cache import Cache, add_cache, get_caches
from usethis._test import change_cwd
from usethis._integrations.bitbucket.cache import Cache, add_cache, get_caches
from usethis._utils._test import change_cwd


class TestAddCache:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from usethis._bitbucket.steps import Step, add_steps
from usethis._test import change_cwd
from usethis._integrations.bitbucket.steps import Step, add_steps
from usethis._utils._test import change_cwd


class TestAddStep:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import requests

from usethis._github.tags import (
from usethis._integrations.github.tags import (
GitHubTagError,
NoGitHubTagsFoundError,
get_github_latest_tag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import pytest
import requests

from usethis._pre_commit.core import (
from usethis._integrations.pre_commit.core import (
_VALIDATEPYPROJECT_VERSION,
add_pre_commit_config,
remove_pre_commit_config,
)
from usethis._test import change_cwd
from usethis._utils._test import change_cwd


class TestAddPreCommitConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import pytest

from usethis._pre_commit.config import HookConfig, PreCommitRepoConfig
from usethis._pre_commit.hooks import (
from usethis._integrations.pre_commit.config import HookConfig, PreCommitRepoConfig
from usethis._integrations.pre_commit.hooks import (
DuplicatedHookNameError,
add_hook,
get_hook_names,
remove_hook,
)
from usethis._test import change_cwd
from usethis._utils._test import change_cwd


class TestAddHook:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import pytest

from usethis._pyproject.core import (
from usethis._integrations.pyproject.core import (
ConfigValueAlreadySetError,
ConfigValueMissingError,
append_config_list,
get_config_value,
remove_config_value,
set_config_value,
)
from usethis._pyproject.io import PyProjectTOMLNotFoundError
from usethis._test import change_cwd
from usethis._integrations.pyproject.io import PyProjectTOMLNotFoundError
from usethis._utils._test import change_cwd


class TestGetConfigValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import requests
from packaging.specifiers import SpecifierSet

from usethis._pyproject.io import PyProjectTOMLNotFoundError
from usethis._pyproject.requires_python import (
from usethis._integrations.pyproject.io import PyProjectTOMLNotFoundError
from usethis._integrations.pyproject.requires_python import (
MAX_MAJOR_PY3,
MissingRequiresPythonError,
get_requires_python,
get_supported_major_python_versions,
)
from usethis._test import change_cwd
from usethis._utils._test import change_cwd


class TestMaxMajorPy3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from usethis._pytest.core import add_pytest_dir, remove_pytest_dir
from usethis._test import change_cwd
from usethis._integrations.pytest.core import add_pytest_dir, remove_pytest_dir
from usethis._utils._test import change_cwd


class TestAddPytestDir:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import pytest

from usethis._pyproject.io import PyProjectTOMLNotFoundError
from usethis._ruff.rules import deselect_ruff_rules, get_ruff_rules, select_ruff_rules
from usethis._test import change_cwd
from usethis._integrations.pyproject.io import PyProjectTOMLNotFoundError
from usethis._integrations.ruff.rules import (
deselect_ruff_rules,
get_ruff_rules,
select_ruff_rules,
)
from usethis._utils._test import change_cwd


class TestSelectRuffRules:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from usethis._test import change_cwd
from usethis._uv.deps import get_dev_deps
from usethis._integrations.uv.deps import get_dev_deps
from usethis._utils._test import change_cwd


class TestGetDevDeps:
Expand Down
Loading

0 comments on commit 501f579

Please sign in to comment.