Skip to content

Commit

Permalink
Lock command. Upgrades dependencies (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomperez98 authored Dec 21, 2023
1 parent 05ac19e commit abfd5e1
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 124 deletions.
1 change: 0 additions & 1 deletion .whitelist.vulture
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
NAME # unused variable (pyrgo/cli/cmds/check.py:102)
28 changes: 13 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "pyrgo"
version = "2.0.0"
version = "2.1.0"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
Expand All @@ -16,32 +16,32 @@ authors = [
{ name = "Tomas Perez Alvarez", email = "[email protected]" },
]
dependencies = [
"click",
"ruff>=0.1.2",
"mypy",
"pip-tools>=7.0.0",
"pytest",
"result",
"build",
"loguru",
"pip-audit>=2.5.5",
"click < 9",
"ruff < 1",
"mypy < 2",
"pip-tools < 8",
"pytest < 8",
"result < 1",
"build < 2",
"pip-audit < 3",
"vulture < 3",
"tomli",
"tomli < 3",
"pdoc < 15",
]

[project.optional-dependencies]
dev = ["pytest-cov"]
dev = ["pytest-cov < 5"]

[project.scripts]
pyrgo = "pyrgo.cli._main:cli"
pyrgo = "pyrgo.cli.__main__:cli"

[project.urls]
Documentation = "https://github.com/Tomperez98/pyrgo#readme"
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",
Expand Down Expand Up @@ -121,14 +121,12 @@ precision = 1
exclude_lines = ["if TYPE_CHECKING:", "raise NotImplementedError"]

[tool.mypy]
show_error_codes = true
follow_imports = "normal"
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
disallow_any_generics = true
check_untyped_defs = true
no_implicit_reexport = true
warn_unused_configs = true
disallow_subclassing_any = true
disallow_incomplete_defs = true
Expand Down
File renamed without changes.
17 changes: 15 additions & 2 deletions pyrgo/cli/cmds/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import subprocess


def _initial_args(env: str, core_deps_alias: str) -> list[str]:
def _initial_args(env: str, core_deps_alias: str, *, upgrade: bool) -> list[str]:
base_args = ["compile"]
if upgrade:
base_args.append("-U")

if env == core_deps_alias:
return base_args

Expand Down Expand Up @@ -56,6 +59,14 @@ def _complete_cmd(
show_default=True,
type=click.BOOL,
)
@click.option(
"--upgrade",
"upgrade",
is_flag=True,
default=False,
show_default=True,
type=click.BOOL,
)
@click.option(
"-e",
"--env",
Expand All @@ -64,7 +75,7 @@ def _complete_cmd(
type=click.STRING,
required=False,
)
def lock(*, generate_hashes: bool, envs: tuple[str, ...]) -> None:
def lock(*, generate_hashes: bool, envs: tuple[str, ...], upgrade: bool) -> None:
"""Lock project dependencies with `piptools`."""
configuration = PyrgoConf.new()

Expand All @@ -85,6 +96,7 @@ def lock(*, generate_hashes: bool, envs: tuple[str, ...]) -> None:
args=_initial_args(
env=env,
core_deps_alias=configuration.core_deps_alias,
upgrade=upgrade,
),
),
generate_hashes=generate_hashes,
Expand All @@ -107,6 +119,7 @@ def lock(*, generate_hashes: bool, envs: tuple[str, ...]) -> None:
args=_initial_args(
env=env,
core_deps_alias=configuration.core_deps_alias,
upgrade=upgrade,
),
),
generate_hashes=generate_hashes,
Expand Down
17 changes: 3 additions & 14 deletions pyrgo/core/_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
from __future__ import annotations

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

import loguru
import tomli


Expand All @@ -17,20 +15,12 @@ def __init__(self, path: pathlib.Path) -> None:
super().__init__(f"`pyproject.toml` not found at {path.as_posix()}")


def _configure_logger(logger: loguru.Logger) -> loguru.Logger:
logger.remove()
fmt = "<lvl>[{level}]</lvl> {message} <green>{name}:{function}:{line}</green> @ {time:HH:mm:ss}"
logger.add(sys.stderr, format=fmt)
return logger


@dataclass(frozen=True)
class PyrgoConf:
"""Pyrgo configuration."""

cwd: pathlib.Path
requirements: pathlib.Path
logger: loguru.Logger
relevant_paths: list[str]
artifacts: list[pathlib.Path]
caches: list[pathlib.Path]
Expand All @@ -41,7 +31,6 @@ class PyrgoConf:
@classmethod
def new(cls: type[PyrgoConf]) -> PyrgoConf:
"""Create new configuration instance."""
logger = _configure_logger(logger=loguru.logger)
cwd = pathlib.Path().cwd()
pyproject_path = cwd.joinpath("pyproject.toml")
if not (pyproject_path.exists() and pyproject_path.is_file()):
Expand All @@ -52,10 +41,11 @@ def new(cls: type[PyrgoConf]) -> PyrgoConf:
relevant_paths: list[str] = [
project_name,
]
pyproject_tooling: dict[str, Any] = pyproject_data["tool"]
relevant_paths.extend(
pyproject_data["tool"]["pytest"]["ini_options"]["testpaths"],
pyproject_tooling["pytest"]["ini_options"]["testpaths"],
)
pyrgo_config = pyproject_data["tool"].get("pyrgo", None)
pyrgo_config: dict[str, Any] | None = pyproject_tooling.get("pyrgo", None)
caches = [
cwd.joinpath(".pytest_cache"),
cwd.joinpath(".ruff_cache"),
Expand All @@ -81,7 +71,6 @@ def new(cls: type[PyrgoConf]) -> PyrgoConf:
return cls(
cwd=cwd,
requirements=cwd.joinpath("requirements"),
logger=logger,
relevant_paths=relevant_paths,
artifacts=[cwd.joinpath("dist")],
caches=caches,
Expand Down
1 change: 1 addition & 0 deletions pyrgo/core/resources/new-project/new_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Project code."""
36 changes: 1 addition & 35 deletions pyrgo/core/resources/new-project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authors = [{ name = "Author name", email = "[email protected]" }]
dependencies = []

[project.optional-dependencies]
dev = ["pyrgo"]
dev = ["pyrgo < 3"]

[tool.ruff]
line-length = 88
Expand Down Expand Up @@ -59,55 +59,21 @@ exclude = [
]

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

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

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

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

[tool.black]
line-length = 88
include = '\.pyi?$'

[tool.pytest.ini_options]
testpaths = ["tests"]
xfail_strict = true
addopts = ["--import-mode=importlib", "--strict-markers"]
markers = ["integration: mark integration tests.", "unit: mark unittest."]

[tool.coverage.run]
branch = true
parallel = true
relative_files = true

[tool.coverage.report]
precision = 1
exclude_lines = [
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"@overload",
"raise NotImplementedError",
]

[tool.mypy]
show_error_codes = true
follow_imports = "normal"
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
disallow_any_generics = true
check_untyped_defs = true
no_implicit_reexport = true
warn_unused_configs = true
disallow_subclassing_any = true
disallow_incomplete_defs = true
Expand Down
Loading

0 comments on commit abfd5e1

Please sign in to comment.