Skip to content

Commit

Permalink
Upgrade stuff (#31)
Browse files Browse the repository at this point in the history
* Update ruff

* Use mashumaro to parse pyproject

* Default

* Pump version
  • Loading branch information
coactive-tomas authored Feb 7, 2024
1 parent 6cca8f4 commit 0f1b9b0
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 75 deletions.
43 changes: 23 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyrgo"
version = "2.2.1"
version = "2.2.2"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
Expand All @@ -25,9 +25,9 @@ dependencies = [
"build < 2",
"pip-audit < 3",
"vulture < 3",
"tomli < 3",
"tomlkit < 1",
"pdoc < 15",
"mashumaro[orjson,toml] < 4",
]

[project.optional-dependencies]
Expand All @@ -42,21 +42,7 @@ Issues = "https://github.com/Tomperez98/pyrgo/issues"
Source = "https://github.com/Tomperez98/pyrgo"

[tool.ruff]
logger-objects = ["pyrgo.logging.logger"]
line-length = 88
ignore = [
"ANN101",
"D203",
"D212",
"COM812",
"COM819",
"D206",
"E501",
"ISC001",
"Q",
"W191",
]
select = ["ALL"]
fix = false
exclude = [
".bzr",
Expand All @@ -80,20 +66,37 @@ exclude = [
"venv",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint]
logger-objects = ["pyrgo.logging.logger"]
ignore = [
"ANN101",
"D203",
"D212",
"COM812",
"COM819",
"D206",
"E501",
"ISC001",
"Q",
"W191",
"UP007",
]
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"scripts/*.py" = ["INP001"]
"__init__.py" = ["D104"]
"tests/*.py" = ["INP001", "S101", "D"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["pyrgo"]
combine-as-imports = true
required-imports = ["from __future__ import annotations"]

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

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "double"

[tool.black]
Expand Down
4 changes: 3 additions & 1 deletion pyrgo/cli/cmds/doc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Doc command."""
from __future__ import annotations

from typing import Optional

import click

from pyrgo.cli.utils import inform_and_run_program
Expand All @@ -22,7 +24,7 @@
"port",
type=click.INT,
)
def doc(output_dir: str | None, port: int | None) -> None:
def doc(output_dir: Optional[str], port: Optional[int]) -> None:
"""Build a package's documentation with `pdoc`."""
configuration = PyrgoConf.new()
pdoc_command = PythonCommandExec.new(program="pdoc").add_args(
Expand Down
3 changes: 2 additions & 1 deletion pyrgo/cli/cmds/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import sys
from typing import Optional

import click
from result import Ok
Expand All @@ -18,7 +19,7 @@
default=None,
show_default=True,
)
def test(marker: str | None) -> None:
def test(marker: Optional[str]) -> None:
"""Run tests with `pytest`."""
pytest_command = PythonCommandExec.new(
program="pytest",
Expand Down
6 changes: 3 additions & 3 deletions pyrgo/core/_command_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from result import Err, Ok, Result

Expand All @@ -22,7 +22,7 @@ class PythonCommandExec:
"""Python command executor."""

args: list[str]
output_file: pathlib.Path | None
output_file: Optional[pathlib.Path]

@classmethod
def new(
Expand All @@ -44,7 +44,7 @@ def add_args(self, args: list[str]) -> Self:

def execute(self) -> Result[None, subprocess.CalledProcessError]:
"""Execute python command."""
stdout_file: None | TextIOWrapper = None
stdout_file: Optional[TextIOWrapper] = None

if self.output_file is not None:
stdout_file = self.output_file.open(mode="w")
Expand Down
88 changes: 65 additions & 23 deletions pyrgo/core/_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,46 @@
from __future__ import annotations

import pathlib
from dataclasses import dataclass
import sys
from dataclasses import dataclass, field
from typing import Any

import toml
import click
from mashumaro import field_options
from mashumaro.mixins.toml import DataClassTOMLMixin


@dataclass(frozen=True)
class _Project:
name: str
optional_dependencies: dict[str, Any] = field(
metadata=field_options(alias="optional-dependencies"), default_factory=dict
)


@dataclass(frozen=True)
class _Pyrgo:
extra_paths: list[str] = field(
metadata=field_options(alias="extra-paths"), default_factory=list
)
extra_caches: list[str] = field(
metadata=field_options(alias="extra-caches"), default_factory=list
)
vulture_allowlist: str = field(
metadata=field_options(alias="vulture-allowlist"), default=".whitelist.vulture"
)


@dataclass(frozen=True)
class _Tooling:
pytest: dict[str, Any]
pyrgo: _Pyrgo = field(default=_Pyrgo())


@dataclass(frozen=True)
class _PyProjectToml(DataClassTOMLMixin):
project: _Project
tool: _Tooling


class PyProjectNotFoundError(Exception):
Expand Down Expand Up @@ -38,41 +74,47 @@ def new(cls: type[PyrgoConf]) -> PyrgoConf:
if not (pyproject_path.exists() and pyproject_path.is_file()):
raise PyProjectNotFoundError(path=cwd)

pyproject_data = toml.loads(pyproject_path.read_text())
project_name = pyproject_data["project"]["name"].strip().replace("-", "_")
pyproject_data = _PyProjectToml.from_toml(pyproject_path.read_text())

project_name = pyproject_data.project.name.strip().replace("-", "_")
relevant_paths: list[str] = [
project_name,
]
pyproject_tooling: dict[str, Any] = pyproject_data["tool"]
try:
test_paths = pyproject_data.tool.pytest["ini_options"]["testpaths"]

except KeyError:
click.echo(
message=click.style(
"`tool.pytest.ini_options.testpaths` is required.", fg="red"
),
color=True,
)
sys.exit(1)

relevant_paths.extend(
pyproject_tooling["pytest"]["ini_options"]["testpaths"],
test_paths,
)
pyrgo_config: dict[str, Any] | None = pyproject_tooling.get("pyrgo", None)
caches = [
cwd.joinpath(".pytest_cache"),
cwd.joinpath(".ruff_cache"),
cwd.joinpath(".mypy_cache"),
]
vulture_allowlist: str = ".whitelist.vulture"
if pyrgo_config is not None:
extra_paths = pyrgo_config.get("extra-paths", None)
extra_caches = pyrgo_config.get("extra-caches", None)
if pyproject_data.tool.pyrgo is not None:
vulture_allowlist = pyproject_data.tool.pyrgo.vulture_allowlist

relevant_paths.extend(pyproject_data.tool.pyrgo.extra_paths)

if pyrgo_config.get("vulture-allowlist", None):
vulture_allowlist = pyrgo_config["vulture-allowlist"]
if extra_paths is not None:
relevant_paths.extend(extra_paths)
if extra_caches is not None:
caches.extend(cwd.joinpath(extra) for extra in extra_caches)
caches.extend(
cwd.joinpath(extra) for extra in pyproject_data.tool.pyrgo.extra_caches
)

core_deps_alias = "core"
env_groups = [core_deps_alias]
op_deps: dict[str, Any] | None = pyproject_data["project"].get(
"optional-dependencies",
None,
)
if op_deps is not None:
env_groups.extend(op_deps.keys())
env_groups = [
core_deps_alias,
*pyproject_data.project.optional_dependencies.keys(),
]

return cls(
cwd=cwd,
Expand Down
36 changes: 19 additions & 17 deletions pyrgo/core/resources/new-project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ dev = ["pyrgo < 3"]

[tool.ruff]
line-length = 88
ignore = [
"ANN101",
"D203",
"D212",
"COM812",
"COM819",
"D206",
"E501",
"ISC001",
"Q000",
"Q001",
"Q002",
"Q003",
"W191",
]
select = ["ALL"]
fix = false
exclude = [
".bzr",
Expand All @@ -58,7 +42,25 @@ exclude = [
"venv",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint]
ignore = [
"ANN101",
"D203",
"D212",
"COM812",
"COM819",
"D206",
"E501",
"ISC001",
"Q000",
"Q001",
"Q002",
"Q003",
"W191",
]
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["INP001", "S101", "D"]

[tool.pytest.ini_options]
Expand Down
19 changes: 14 additions & 5 deletions requirements/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ build==1.0.3
# via
# pip-tools
# pyrgo (pyproject.toml)
cachecontrol[filecache]==0.13.1
cachecontrol[filecache]==0.14.0
# via
# cachecontrol
# pip-audit
certifi==2023.11.17
certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
Expand Down Expand Up @@ -44,10 +44,14 @@ license-expression==30.2.0
# via cyclonedx-python-lib
markdown-it-py==3.0.0
# via rich
markupsafe==2.1.4
markupsafe==2.1.5
# via
# jinja2
# pdoc
mashumaro[orjson,toml]==3.12
# via
# mashumaro
# pyrgo (pyproject.toml)
mdurl==0.1.2
# via markdown-it-py
msgpack==1.0.7
Expand All @@ -56,6 +60,8 @@ mypy==1.8.0
# via pyrgo (pyproject.toml)
mypy-extensions==1.0.0
# via mypy
orjson==3.9.13
# via mashumaro
packageurl-python==0.13.4
# via cyclonedx-python-lib
packaging==23.2
Expand Down Expand Up @@ -96,7 +102,7 @@ result==0.16.0
# via pyrgo (pyproject.toml)
rich==13.7.0
# via pip-audit
ruff==0.1.15
ruff==0.2.1
# via pyrgo (pyproject.toml)
six==1.16.0
# via html5lib
Expand All @@ -107,16 +113,19 @@ toml==0.10.2
tomli==2.0.1
# via
# build
# mashumaro
# mypy
# pip-tools
# pyproject-hooks
# pyrgo (pyproject.toml)
# pytest
# vulture
tomli-w==1.0.0
# via mashumaro
tomlkit==0.12.3
# via pyrgo (pyproject.toml)
typing-extensions==4.9.0
# via
# mashumaro
# mypy
# result
urllib3==2.2.0
Expand Down
Loading

0 comments on commit 0f1b9b0

Please sign in to comment.