Skip to content

Commit

Permalink
Started using hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
plonerma committed Nov 20, 2023
1 parent db5dfb6 commit c4dcf0f
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 264 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/python-package-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ on:
branches: [ "main" ]

jobs:
build:

run:
name: "Test & Coverage"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies and package
run: |
python -m pip install --upgrade pip
pip install -e .[tests]
- name: Test with pytest
run: |
pytest
- name: Set up pip cache
if: runner.os == 'Linux'
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
- name: Install hatch
run: pipx install hatch
- name: Lint
run: hatch run lint:all
- name: Tests
run: hatch run +py=${{ matrix.python-version }} test
2 changes: 1 addition & 1 deletion examples/nested_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Config:

def train(config: Config):
# to something
print(config)
print(config) # noqa: T201


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Config:
def train(config: Config, output_dir: Path):
"""Help text which will be shown."""

print(output_dir)
print(config)
print(output_dir) # noqa: T201
print(config) # noqa: T201


if __name__ == "__main__":
Expand Down
204 changes: 153 additions & 51 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,74 +1,176 @@
[project]
name = "cordage"
version = "0.0.3"
authors = [
{ name="Max Ploner", email="cordage@maxploner.de" },
]
description = "Small framework for computational research data management"
dynamic = ["version"]
description = 'Small framework for computational research data management'
readme = "README.md"
requires-python = ">=3.8"
license = {text = "MIT"}
license = "MIT"
keywords = []
authors = [
{ name = "Max Ploner", email = "cordage@maxploner.de" },
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies=[
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
'docstring_parser',
'colorlog',
'dacite',
]

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

[project.optional-dependencies]
tests = [
'pytest',
'pytest-mypy',
'pytest-isort',
'pytest-flake8',
'pytest-cov',
'pytest-timeout',
'pyyaml',
'toml',
'flake8<5.0.0',
'flake8-black',
'types-PyYAML',
'types-toml',
]

dev = [
'types-PyYAML',
'types-toml',
toml = [
"toml",
]
yaml = [
"pyyaml",
]

[project.urls]
"Homepage" = "https://github.com/plonerma/cordage"
"Bug Tracker" = "https://github.com/plonerma/cordage/issues"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.setuptools]
package-dir = {"" = "src"}
[tool.hatch.version]
path = "src/cordage/__about__.py"

[tool.setuptools.packages.find]
where = ["src"]
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"pytest-timeout",
]
features = ["toml", "yaml"]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[tool.pytest.ini_options]
flake8-max-line-length = 210
addopts = "--flake8 --mypy --isort --cov=src --cov-fail-under=90"
flake8-ignore = ["E203", "W503"] # See https://github.com/PyCQA/pycodestyle/issues/373
[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11"]

[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/cordage tests}"
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"style",
]
all = [
"style",
"typing",
]

[tool.black]
line_length = 120
target-version = ["py38"]
line-length = 120
skip-string-normalization = true

[tool.ruff]
target-version = "py38"
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",
# Allow asserts for now (transitioning to recommended exceptions)
"S101",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
]
unfixable = [
# Don't touch unused imports
"F401",
]

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

[tool.ruff.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 = ["cordage", "tests"]
branch = true
parallel = true
omit = [
"src/cordage/__about__.py",
]

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

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

[tool.mypy]
ignore_missing_imports = true
check_untyped_defs = true

[tool.isort]
profile = "black"
line_length = 120

[tool.ruff]
line-length = 120
1 change: 1 addition & 0 deletions src/cordage/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.4"
6 changes: 3 additions & 3 deletions src/cordage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
WrongTypeError,
)

from .context import FunctionContext
from .experiment import Experiment, Metadata, Series, Trial
from .global_config import GlobalConfig
from cordage.context import FunctionContext
from cordage.experiment import Experiment, Metadata, Series, Trial
from cordage.global_config import GlobalConfig


def run(
Expand Down
Loading

0 comments on commit c4dcf0f

Please sign in to comment.