Skip to content

Commit bc5a818

Browse files
committed
chore: add ruff and mypy linting with GitHub Actions
- Add ruff and mypy as dev dependencies - Configure ruff for linting and formatting (E, W, F, I, B, UP rules) - Configure mypy for type checking with strict settings - Add GitHub Actions workflow for automated linting on push/PR - Fix all lint issues in src/ and tests/ - Apply ruff formatting to codebase
1 parent e422637 commit bc5a818

33 files changed

Lines changed: 708 additions & 283 deletions

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
ruff:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: astral-sh/ruff-action@v3
15+
- uses: astral-sh/ruff-action@v3
16+
with:
17+
args: format --check
18+
19+
mypy:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: astral-sh/setup-uv@v5
24+
- run: uv sync --dev
25+
- run: uv run mypy src/

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,25 @@ addopts = "-m 'not slow'"
6666
[dependency-groups]
6767
dev = [
6868
"pytest>=9.0.2",
69+
"ruff>=0.8.0",
70+
"mypy>=1.13.0",
6971
]
72+
73+
[tool.ruff.lint]
74+
select = [
75+
"E", # pycodestyle errors
76+
"W", # pycodestyle warnings
77+
"F", # pyflakes
78+
"I", # isort
79+
"B", # flake8-bugbear
80+
"UP", # pyupgrade
81+
]
82+
ignore = [
83+
"E501", # line too long (handled by formatter)
84+
]
85+
86+
[tool.mypy]
87+
python_version = "3.10"
88+
warn_return_any = true
89+
warn_unused_ignores = true
90+
disallow_untyped_defs = true

src/distrobox_plus/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ def _get_command_name() -> str:
1414
"""Get command name from package metadata (pyproject.toml)."""
1515
try:
1616
from importlib.metadata import metadata
17+
1718
return metadata(__package__)["Name"]
1819
except Exception:
1920
# Development mode: read from pyproject.toml directly
20-
import tomllib
2121
from pathlib import Path
2222

23+
import tomllib # type: ignore[import-not-found]
24+
2325
pyproject = Path(__file__).parent.parent.parent / "pyproject.toml"
2426
if pyproject.exists():
2527
with open(pyproject, "rb") as f:
2628
data = tomllib.load(f)
27-
return data.get("project", {}).get("name", "distrobox-plus")
29+
return str(data.get("project", {}).get("name", "distrobox-plus"))
2830
raise
2931

3032

src/distrobox_plus/cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sys
1010

1111
from .config import VERSION
12-
from .utils.console import print_msg, print_error, red
12+
from .utils.console import print_error, print_msg, red
1313
from .utils.exceptions import DistroboxError
1414

1515

@@ -38,7 +38,8 @@ def _main(argv: list[str] | None = None) -> int:
3838
description="Create and manage containerized environments",
3939
)
4040
parser.add_argument(
41-
"-V", "--version",
41+
"-V",
42+
"--version",
4243
action="version",
4344
version=f"distrobox: {VERSION}",
4445
)
@@ -82,42 +83,52 @@ def _main(argv: list[str] | None = None) -> int:
8283
match command:
8384
case "assemble":
8485
from .commands.assemble import run
86+
8587
return run(args)
8688

8789
case "create":
8890
from .commands.create import run
91+
8992
return run(args)
9093

9194
case "enter":
9295
from .commands.enter import run
96+
9397
return run(args)
9498

9599
case "ephemeral":
96100
from .commands.ephemeral import run
101+
97102
return run(args)
98103

99104
case "export":
100105
from .commands.export import run
106+
101107
return run(args)
102108

103109
case "generate-entry":
104110
from .commands.generate_entry import run
111+
105112
return run(args)
106113

107114
case "list" | "ls":
108115
from .commands.list import run
116+
109117
return run(args)
110118

111119
case "stop":
112120
from .commands.stop import run
121+
113122
return run(args)
114123

115124
case "rm":
116125
from .commands.rm import run
126+
117127
return run(args)
118128

119129
case "upgrade":
120130
from .commands.upgrade import run
131+
121132
return run(args)
122133

123134
case _:

0 commit comments

Comments
 (0)