Skip to content

Commit

Permalink
chore!: migrate to poetry
Browse files Browse the repository at this point in the history
* chore!: migrate to poetry

* chore: reformat project using ruff only

* chore: set up git blame ignore revs

* chore: update actions to use poetry

* chore: remove requirements.*.txt files
  • Loading branch information
marcelblijleven authored Dec 3, 2024
1 parent e6e7339 commit 3393270
Show file tree
Hide file tree
Showing 83 changed files with 1,398 additions and 349 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Migrate to ruff
73c58b02ea964d62b44b3ded3a33828aaa505910
23 changes: 11 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.11', '3.12']
python-version: ['3.11', '3.12', '3.13']
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install hatch
- name: Set up poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Run linters
run: hatch run lint:all
run: poetry run ruff check src tests
- name: Run tests
run: hatch run test-cov
run: poetry run pytest --cov
- name: "Upload coverage to Codecov"
if: matrix.python-version == 3.12 # Only upload coverage once per run
if: matrix.python-version == 3.13 # Only upload coverage once per run
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/update_readme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Set up poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Generate new README
run: generate-readme
- name: Commit new README
Expand Down
838 changes: 838 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

195 changes: 25 additions & 170 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,195 +1,50 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
[tool.poetry]
name = "adventofcode"
dynamic = ["version"]
version = "1.10.0"
description = "A collection of Advent of Code solutions"
readme = "README.md"
requires-python = ">=3.11"
authors = ["Marcel Blijleven <[email protected]>"]
license = "MIT"
keywords = []
authors = [
{ name = "Marcel Blijleven", email = "[email protected]" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"rich>=10",

]

[project.urls]
Documentation = "https://github.com/unknown/adventofcode#readme"
Issues = "https://github.com/unknown/adventofcode/issues"
Source = "https://github.com/unknown/adventofcode"

[project.scripts]
add-day = "adventofcode.scripts.add_day:add_day"
clean-repo = "adventofcode.scripts.clean_repo:clean_repo"
generate-benchmarks = "adventofcode.scripts.benchmarks:generate_benchmarks"
generate-readme = "adventofcode.scripts.generate_readme:generate_readme"
run-all = "adventofcode.scripts.runner:run_all"


[tool.hatch.version]
path = "src/adventofcode/__about__.py"

[tool.hatch.envs.default]
dependencies = [
"httpx",
"coverage[toml]>=6.5",
"pytest",
"pytest-cov",
"pytest-mock>=3.10",
]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest --cov {args:tests} "
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[[tool.hatch.envs.all.matrix]]
python = ["3.11", "3.12"]

[tool.hatch.envs.lint]
detached = true
dependencies = [
"black>=23.1.0",
"mypy>=1.0.0",
"ruff>=0.0.243",
]
[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:src/adventofcode}"
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"style",
]
all = [
"style",
"typing",
]
readme = "README.md"

[tool.black]
target-version = ["py311"]
line-length = 120
skip-string-normalization = true
[tool.poetry.dependencies]
python = ">=3.11"
rich = "^13.9.4"

[tool.ruff]
target-version = "py311"
line-length = 120
select = [
"A",
"ARG",
"B",
"C",
"DTZ",
"E",
"EM",
"F",
"FBT",
"I",
"ICN",
"ISC",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"Q",
"RUF",
"S",
"T",
"TID",
"UP",
"W",
"YTT",
]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
# Use of magic values
"PLR2004",
# Use of boolean default values in function definition
"FBT001", "FBT002",
# Exceptions with string literals
"EM101", "EM102",
# Concatenated string literals on one line
"ISC001",

]
unfixable = [
# Don't touch unused imports
"F401",
]
[tool.poetry.group.dev.dependencies]
httpx = "^0.28.0"
coverage = { extras = ["toml"], version = "^7.6.8" }
pytest = "^8.3.4"
pytest-cov = "^6.0.0"
pytest-mock = "^3.14.0"
ruff = "^0.8.1"
mypy = "^1.13.0"
commitizen = "^4.0.0"

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["adventofcode"]

[tool.ruff.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]

[tool.coverage.run]
source_pkgs = ["adventofcode", "tests"]
branch = true
parallel = true
omit = [
"src/adventofcode/__about__.py",
]
omit = ["src/adventofcode/__about__.py"]

[tool.coverage.paths]
adventofcode = ["src/adventofcode", "*/adventofcode/src/adventofcode"]
adventofcode = ["src/adventofcode", "*/adventofcode/arc/adventofcode"]
tests = ["tests", "*/adventofcode/tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
exclude_lines = ["no cov", "if __name__ == __main__:", "if TYPE_CHECKING:"]

[tool.commitizen]
tag_format = "v$version"
version = "1.10.0"
version_files = [
"src/adventofcode/__about__.py",
]
version_files = ["src/adventofcode/__about__.py"]

[[tool.mypy.overrides]]
module = [
"rich.console",
"rich.table",
"httpx",
"utils",
"config",
]
disable_error_code = ["name-defined"]
ignore_missing_imports = true
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

12 changes: 0 additions & 12 deletions requirements_dev.txt

This file was deleted.

30 changes: 23 additions & 7 deletions src/adventofcode/scripts/add_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def add_day():
write_solution_template(solution_file, year, day)

# Test file
test_module_path = os.path.abspath(os.path.join(ROOT_DIR, "../../tests/adventofcode", f"year_{year}"))
test_module_path = os.path.abspath(
os.path.join(ROOT_DIR, "../../tests/adventofcode", f"year_{year}")
)
test_file = os.path.join(test_module_path, f"test_day_{day:02}_{year}.py")
create_module_dir(test_module_path)
write_test_template(test_file, year, day)
Expand All @@ -42,7 +44,10 @@ def write_solution_template(path: str, year: int, day: int) -> None:
write_template(path, read_solution_template(year, day))
console.print(f"[green]Wrote template to {path}")
else:
console.print(f"[yellow]Did not write template for year {year} day {day}" ", the file already exists.")
console.print(
f"[yellow]Did not write template for year {year} day {day}"
", the file already exists."
)


def write_test_template(path: str, year: int, day: int) -> None:
Expand All @@ -51,7 +56,10 @@ def write_test_template(path: str, year: int, day: int) -> None:
write_template(path, read_test_template(year, day))
console.print(f"[green]Wrote test template to {path}")
else:
console.print(f"[yellow]Did not write test template for year {year} day {day}" ", the file already exists.")
console.print(
f"[yellow]Did not write test template for year {year} day {day}"
", the file already exists."
)


def create_module_dir(path: str) -> None:
Expand All @@ -73,19 +81,27 @@ def verify_input_exists(year: int, day: int) -> None:
"""Verifies if user input exists, and downloads it if not"""
try:
_ = get_input_for_day(year, day)
console.print(f"Input data already exists for year {year} day {day}, skipping download")
console.print(
f"Input data already exists for year {year} day {day}, skipping download"
)
return
except FileNotFoundError:
try:
get_input(year, day)
console.print(f"Automatically downloaded input data for year {year} day {day}")
console.print(
f"Automatically downloaded input data for year {year} day {day}"
)
return
except HTTPError as e:
console.print("[red]Could not retrieve input data for " f"year {year} day {day} automatically: {e}")
console.print(
"[red]Could not retrieve input data for "
f"year {year} day {day} automatically: {e}"
)
return
except FileNotFoundError:
console.print(
"[red]Could not retrieve input data for " f"year {year} day {day}: .session not set correctly"
"[red]Could not retrieve input data for "
f"year {year} day {day}: .session not set correctly"
)
return

Expand Down
Loading

0 comments on commit 3393270

Please sign in to comment.