Skip to content

Commit

Permalink
Add pyproject.toml
Browse files Browse the repository at this point in the history
This adds a pyproject.toml file to store configuration metadata for
pytest, coverage, Ruff, mypy and tox.
  • Loading branch information
replaceafill authored Aug 16, 2024
1 parent be6e57b commit 366109d
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 173 deletions.
20 changes: 0 additions & 20 deletions .coveragerc

This file was deleted.

3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

# Include
!/src/**
!/pytest.ini
!/pyproject.toml
!/requirements*
!/tox.ini
!/LICENSE
!/COPYRIGHT
!/TRADEMARK
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
make -C hack/ test-${{ matrix.rule }}
env:
TOXARGS: -vv
PYTEST_ADDOPTS: -vv --cov /src/src/ --cov-config=/src/.coveragerc --cov-report xml:/src/coverage.xml
PYTEST_ADDOPTS: -vv --cov --cov-config=/src/pyproject.toml --cov-report xml:/src/coverage.xml
PYTHON_VERSION: ${{ matrix.python-version }}
- name: "Upload coverage report"
if: matrix.rule != 'storage-service' && matrix.rule != 'migrations' && github.repository == 'artefactual/archivematica'
Expand Down
7 changes: 3 additions & 4 deletions hack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,9 @@ test-storage-service Run Storage Service tests.
```

`tox` sets up separate virtual environments for each target and calls
`pytest` to run the tests. Their configurations live in the `tox.ini`
and `pytest.ini` files but you can set the [`TOXARGS`][tox-cli] and
[`PYTEST_ADDOPTS`][pytest-cli] environment variables to pass command
line options to each.
`pytest` to run the tests. Their configurations live in the `pyproject.toml`
file but you can set the [`TOXARGS`][tox-cli] and [`PYTEST_ADDOPTS`][pytest-cli]
environment variables to pass command line options to each.

[tox-cli]: https://tox.readthedocs.io/en/latest/config.html#cli
[pytest-cli]: https://docs.pytest.org/en/stable/example/simple.html#how-to-change-command-line-options-defaults
Expand Down
37 changes: 0 additions & 37 deletions mypy.ini

This file was deleted.

163 changes: 163 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
[tool.pytest.ini_options]
addopts = "--reuse-db -p no:cacheprovider"
DJANGO_SETTINGS_MODULE="settings.test"
norecursedirs = ".svn _build tmp* node_modules bower_components share .tox"

[tool.coverage.run]
omit = [
"**/src/archivematicaCommon/lib/externals/*",
"**/migrations/*",
"**/south_migrations/*",
"**/management/commands/*",
"**/settings/*",
"**/tests/*",
"**/wsgi.py",
"**/manage.py",
]
include = [
"**/src/archivematicaCommon/lib/*",
"**/src/dashboard/src/*",
"**/src/MCPClient/lib/*",
"**/src/MCPClient/lib/clientScripts/*",
"**/src/MCPServer/lib/*",
]
branch = true

[tool.ruff.lint]
# Rule reference: https://docs.astral.sh/ruff/rules/
select = [
"B",
"C4",
"E",
"F",
"I",
"UP",
"W",
]
ignore = [
"B018",
"B904",
"E402",
"E501",
"UP031",
]

[tool.ruff.lint.per-file-ignores]
"src/*/settings/*" = ["F403"]
"src/dashboard/src/settings/*" = ["F405"]

[tool.ruff.lint.isort]
force-single-line = true

[tool.mypy]
explicit_package_bases = true
warn_redundant_casts = true
warn_unused_configs = true

[[tool.mypy.overrides]]
module = [
"src.MCPClient.lib.client.*",
"src.MCPClient.lib.clientScripts.identify_file_format",
"src.MCPClient.lib.clientScripts.normalize",
"src.MCPClient.lib.clientScripts.policy_check",
"src.MCPClient.lib.clientScripts.validate_file",
"tests.MCPClient.conftest",
"tests.MCPClient.test_identify_file_format",
"tests.MCPClient.test_normalize",
"tests.MCPClient.test_policy_check",
"tests.MCPClient.test_validate_file",
]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_reexport = true
strict_equality = true
warn_return_any = true
warn_unused_ignores = true

[tool.tox]
legacy_tox_ini = """
[tox]
skipsdist = True
envlist =
archivematica-common
dashboard
mcp-server
mcp-client
storage-service
migrations-dashboard
migrations-storage-service
linting
[testenv]
skip_install = True
deps = -r{toxinidir}/requirements-dev.txt
commands = py.test {posargs}
allowlist_externals =
bash
find
setenv =
# General
LOGNAME = user
DJANGO_SETTINGS_MODULE = {env:DJANGO_SETTINGS_MODULE:settings.test}
PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:}
SRC_DIR = {toxinidir}/src
HACK_DIR = {toxinidir}/hack
# Archivematica Common
ARCHIVEMATICA_COMMON_ROOT = {env:SRC_DIR}/archivematicaCommon
ARCHIVEMATICA_COMMON_DIR = {env:ARCHIVEMATICA_COMMON_ROOT}/lib
# Dashboard
DASHBOARD_ROOT = {env:SRC_DIR}/dashboard
DASHBOARD_DIR = {env:DASHBOARD_ROOT}/src
DASHBOARD_PYTHONPATH = {env:DASHBOARD_DIR}:{env:ARCHIVEMATICA_COMMON_DIR}
# MCP Server
MCPSERVER_ROOT = {env:SRC_DIR}/MCPServer
MCPSERVER_DIR = {env:MCPSERVER_ROOT}/lib
MCPSERVER_PYTHONPATH = {env:MCPSERVER_DIR}:{env:ARCHIVEMATICA_COMMON_DIR}:{env:DASHBOARD_DIR}
# MCP Client
MCPCLIENT_ROOT = {env:SRC_DIR}/MCPClient
MCPCLIENT_DIR = {env:MCPCLIENT_ROOT}/lib
MCPCLIENT_PYTHONPATH = {env:MCPCLIENT_DIR}:{env:MCPCLIENT_DIR}/clientScripts:{env:ARCHIVEMATICA_COMMON_DIR}:{env:DASHBOARD_DIR}
# Storage Service
STORAGE_SERVICE_ROOT = {env:HACK_DIR}/submodules/archivematica-storage-service
STORAGE_SERVICE_DIR = {env:STORAGE_SERVICE_ROOT}/storage_service
STORAGE_SERVICE_PYTHONPATH = {env:STORAGE_SERVICE_DIR}:{env:STORAGE_SERVICE_DIR}/storage_service
# TOXENV-specific
archivematica-common: PYTHONPATH = {env:DASHBOARD_PYTHONPATH}
dashboard: PYTHONPATH = {env:DASHBOARD_PYTHONPATH}
mcp-server: PYTHONPATH = {env:MCPSERVER_PYTHONPATH}
mcp-client: PYTHONPATH = {env:MCPCLIENT_PYTHONPATH}
storage-service: PYTHONPATH = {env:STORAGE_SERVICE_PYTHONPATH}
migrations-dashboard: PYTHONPATH = {env:DASHBOARD_PYTHONPATH}
migrations-storage-service: PYTHONPATH = {env:STORAGE_SERVICE_PYTHONPATH}
# Setting HOME prevents Python's pwd module to ask for a real uid inside
# the container, and using {temp_dir} allows caching the pre-commit
# dependencies in the tox host
linting: HOME = {temp_dir}/user
changedir =
archivematica-common: {toxinidir}/tests/archivematicaCommon
dashboard: {toxinidir}/tests/dashboard
mcp-server: {toxinidir}/tests/MCPServer
mcp-client: {toxinidir}/tests/MCPClient
storage-service: {env:STORAGE_SERVICE_ROOT}
[testenv:storage-service]
deps =
-r{env:STORAGE_SERVICE_ROOT}/requirements-dev.txt
[testenv:migrations-dashboard]
commands = django-admin makemigrations --check --dry-run
[testenv:migrations-storage-service]
deps = {[testenv:storage-service]deps}
commands = {[testenv:migrations-dashboard]commands}
[testenv:linting]
basepython = python3
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure
"""
4 changes: 0 additions & 4 deletions pytest.ini

This file was deleted.

2 changes: 1 addition & 1 deletion requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt

coverage
coverage[toml]
git+https://github.com/artefactual-labs/[email protected]#egg=mockldap
pip-tools
pytest
Expand Down
25 changes: 0 additions & 25 deletions ruff.toml

This file was deleted.

79 changes: 0 additions & 79 deletions tox.ini

This file was deleted.

0 comments on commit 366109d

Please sign in to comment.