Skip to content

Commit

Permalink
Merge branch 'main' into machine-template
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Aug 21, 2023
2 parents fa2ff26 + 81ce65f commit 10b7683
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 66 deletions.
16 changes: 15 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@
"urllib3<2.0",
]

lint_requires = [
"black==23.7.0",
"codespell[tomli]==2.2.5",
"ruff==0.0.280",
"yamllint==1.32.0",
]

type_requires = [
"mypy[reports]==1.4.1",
"pyright==1.1.316",
]

dev_requires = [
"black",
"coverage",
"flake8",
"pydocstyle",
Expand All @@ -58,9 +69,12 @@
"responses",
"tox",
]
dev_requires += lint_requires + type_requires

extras_require = {
"dev": dev_requires,
"lint": lint_requires,
"type": type_requires,
}


Expand Down
102 changes: 37 additions & 65 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[tox]
# Differences in tox configuration from starbase:
# 1. Docs not included
# 2. Charmcraft currently doesn't distinguish unit from integration tests
env_list = # Environments to run when called with no parameters.
lint-{black,ruff,shellcheck,codespell}
test-py38
minversion = 4.3.5
format-{black,ruff,codespell}
pre-commit
lint-{black,ruff,mypy,pyright,shellcheck,codespell,yaml}
test-py3.8
# Tests take a while, so we're only running them on Python
# 3.8, which is included in core20.
minversion = 4.6
# Tox will use these requirements to bootstrap a venv if necessary.
# tox-igore-env-name-mismatch allows us to have one virtualenv for all linting.
# By setting requirements here, we make this INI file compatible with older
Expand All @@ -11,9 +18,9 @@ minversion = 4.3.5
# install tox from apt. Older than that, the user gets an upgrade warning.
requires =
# renovate: datasource=pypi
tox>=4.6.4
tox-ignore-env-name-mismatch>=0.2.0.post2
# renovate: datasource=pypi
tox-ignore-env-name-mismatch==0.2.0.post2
tox-gh==1.3.1
# Allow tox to access the user's $TMPDIR environment variable if set.
# This workaround is required to avoid circular dependencies for TMPDIR,
# since tox will otherwise attempt to use the environment's TMPDIR variable.
Expand All @@ -25,45 +32,32 @@ user_tmp_dir = {env:TMPDIR}
# which will speed up those tests since they'll run on a ramdisk.
env_tmp_dir = {user_tmp_dir:{env:XDG_RUNTIME_DIR:{work_dir}}}/tox_tmp/{env_name}
set_env =
RUNNING_TOX=1
TMPDIR={env_tmp_dir}
COVERAGE_FILE={env_tmp_dir}/.coverage_{env_name}
pass_env =
CI
CRAFT_*
PYTEST_ADDOPTS

[test] # Base configuration for unit and integration tests
package = editable
extras = dev
allowlist_externals = mkdir
commands_pre = mkdir -p results
commands_pre = mkdir -p {tox_root}/results

[testenv:test-{py38,py39,py310,py311,py312}] # Configuration for all tests using pytest
[testenv:{test}-py3.{8,9,10,11,12}] # Configuration for all tests using pytest
base = testenv, test
description = Run unit tests with pytest
deps =
-rrequirements-dev.txt
-rrequirements-jammy.txt
labels = tests, unit-tests
# Once unit and integration tests are separated:
# commands = pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml tests/unit {posargs}
commands = pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs:tests}

# Commented out until we have separation of unit tests from integration tests.
# [testenv:integration-{py38,py39,py310,py311,py312}]
# base = testenv, test
# description = Run integration tests with pytest
# labels = tests, integration-tests
# commands = pytest {tty:--color=yes} --junit-xml=results/test-results-{env_name}.xml tests/integration {posargs}
description = Run tests with pytest
labels =
py3.{8,10,11}: tests
commands = pytest {tty:--color=yes} --cov={tox_root}/charmcraft --cov-config={tox_root}/pyproject.toml --cov-report=xml:{tox_root}/results/coverage-{env_name}.xml --junit-xml={tox_root}/results/test-results-{env_name}.xml {posargs}

[lint] # Standard linting configuration
skip_install = true
deps =
# renovate: datasource=pypi
black==23.7.0
# renovate: datasource=pypi
codespell[tomli]==2.2.5
# renovate: datasource=pypi
ruff==0.0.280
# renovate: datasource=pypi
yamllint==1.32.0
package = editable
extras = lint
env_dir = {work_dir}/linting
runner = ignore_env_name_mismatch

Expand All @@ -81,30 +75,24 @@ commands_pre =
shellcheck: bash -c '{[shellcheck]find} | {[shellcheck]filter} > {env_tmp_dir}/shellcheck_files'
commands =
black: black --check --diff {tty:--color} {posargs} .
ruff: ruff --diff --respect-gitignore {posargs} .
ruff: ruff check --respect-gitignore {posargs} .
shellcheck: xargs -ra {env_tmp_dir}/shellcheck_files shellcheck
codespell: codespell --toml {tox_root}/pyproject.toml {posargs}
yaml: yamllint {posargs} .

[testenv:lint-{mypy,pyright}]
description = Static type checking
base = testenv
deps =
# renovate: datasource=pypi
mypy[reports]==1.4.1
base = testenv, lint
env_dir = {work_dir}/typing
runner = ignore_env_name_mismatch
package = editable
extras = [dev, types]
extras = dev, types
labels = lint, type
allowlist_externals =
pyright: pyright
mypy: mkdir
commands_pre =
mypy: mkdir -p .mypy_cache
mypy: mkdir -p {tox_root}/.mypy_cache
commands =
pyright: pyright --lib {posargs}
mypy: mypy --install-types --non-interactive .
pyright: pyright {posargs}
mypy: mypy --install-types --non-interactive {posargs:.}

[testenv:format-{black,ruff,codespell}]
description = Automatically format source code
Expand All @@ -115,28 +103,12 @@ commands =
ruff: ruff --fix --respect-gitignore {posargs} .
codespell: codespell --toml {tox_root}/pyproject.toml --write-changes {posargs}

[docs] # Sphinx documentation configuration
extras = docs
package = editable
[testenv:pre-commit]
base =
deps = pre-commit
package = skip
no_package = true
env_dir = {work_dir}/docs
env_dir = {work_dir}/pre-commit
runner = ignore_env_name_mismatch

[testenv:build-docs]
description = Build sphinx documentation
base = docs
allowlist_externals = bash
commands_pre = bash -c 'if [[ ! -e docs ]];then echo "No docs directory. Run `tox run -e sphinx-quickstart` to create one.;";return 1;fi'
# "-W" is to treat warnings as errors
commands = sphinx-build {posargs:-b html} -W {tox_root}/docs {tox_root}/docs/_build

[testenv:autobuild-docs]
description = Build documentation with an autoupdating server
base = docs
commands = sphinx-autobuild {posargs:-b html --open-browser --port 8080} -W --watch {tox_root}/starcraft {tox_root}/docs {tox_root}/docs/_build

[testenv:lint-docs]
description = Lint the documentation with sphinx-lint
base = docs
commands = sphinx-lint --ignore docs/_build --max-line-length 80 -e all {posargs} docs/
labels = lint
description = Run pre-commit on staged files or arbitrary pre-commit commands (tox run -e pre-commit -- [args])
commands = pre-commit {posargs:run}

0 comments on commit 10b7683

Please sign in to comment.