Skip to content

Commit

Permalink
Ensure we test coverage uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Dec 12, 2024
1 parent 0e78cd6 commit 0d4dbca
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 9 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions .config/requirements-test.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage>=7.6.9
# pytest-cov
pytest-instafail
pytest-plus
pytest>=8
Empty file added .config/requirements.in
Empty file.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: ./.github/workflows/tox.yml
with:
default_python: "3.10"
jobs_producing_coverage: 0
jobs_producing_coverage: 6
max_python: "3.13"
min_python: "3.10"
run_post: echo 'Running post'
Expand Down
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
comment: false
coverage:
status:
patch: true
project:
default:
threshold: 0.5%
85 changes: 85 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 65.3.0", # required by pyproject+setuptools_scm integration and editable installs
"setuptools_scm[toml] >= 7.0.5" # required for "no-local-version" scheme
]

[project]
description = "..."
dynamic = ["version", "dependencies", "optional-dependencies"]
name = "team-devtools"
readme = "README.md"
# https://peps.python.org/pep-0621/#readme
requires-python = ">=3.10"
# Keep this default because xml/report do not know to use load it from config file:
# data_file = ".coverage"
[tool.coverage.paths]
source = ["src", "test", ".tox/*/site-packages"]

[tool.coverage.report]
exclude_also = ["pragma: no cover", "if TYPE_CHECKING:"]
# Increase it just so it would pass on any single-python run
fail_under = 100
omit = ["test/*"]
show_missing = true
skip_covered = true
skip_empty = true

[tool.coverage.run]
concurrency = ["multiprocessing", "thread"]
# Do not use branch until bug is fixes:
# https://github.com/nedbat/coveragepy/issues/605
# branch = true
parallel = true
source = ["src"]
[tool.pytest.ini_options]
addopts = "-p no:pytest_cov --durations=10 --failed-first"
norecursedirs = [
"*.egg",
".cache",
".config",
".eggs",
".git",
".github",
".mypy_cache",
".projects",
".eggs",
".tox",
"__pycache__",
"build",
"collections",
"dist",
"docs",
"site",
"src/*.egg-info"
]

[tool.setuptools.dynamic]
dependencies = {file = [".config/requirements.in"]}
optional-dependencies.docs = {file = [".config/requirements-docs.in"]}
optional-dependencies.test = {file = [".config/requirements-test.in"]}
[tool.setuptools_scm]
# To prevent accidental pick of mobile version tags such 'v6'
git_describe_command = [
"git",
"describe",
"--dirty",
"--long",
"--tags",
"--match",
"v*.*"
]
local_scheme = "no-local-version"
tag_regex = "^(?P<prefix>v)?(?P<version>[0-9.]+)(?P<suffix>.*)?$"
write_to = "src/team_devtools/_version.py"

[tool.tomlsort]
in_place = true
sort_inline_tables = true
sort_table_keys = true

[tool.uv.pip]
annotation-style = "line"
custom-compile-command = "tox run deps"
no-emit-package = ["ansible-core", "pip", "resolvelib", "typing_extensions", "uv"]
6 changes: 6 additions & 0 deletions src/team_devtools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try:
from ._version import __version__
except ImportError: # pragma: no cover
__version__ = "unknown"

__all__ = ("__version__",)
16 changes: 16 additions & 0 deletions src/team_devtools/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object

version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '22.5.1.dev19'
__version_tuple__ = version_tuple = (22, 5, 1, 'dev19')
1 change: 1 addition & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Use ansiblelint.testing instead for reusable tests."""
6 changes: 6 additions & 0 deletions test/test_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Test module for the package."""


def test_placeholder():
"""Placeholder test."""
from team_devtools import __version__
81 changes: 73 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,32 +1,72 @@
[tox]
minversion = 4.0
minversion = 4.6.3
envlist =
lint
pkg
py
docs
ubi8
ubi9
isolated_build = True
requires =
tox>=4.21.2
tox-uv>=1.15.0
tox>=4.21.2
tox-extra >= 2.0.1
tox-uv >= 1.16.0
setuptools >= 65.3.0 # editable installs

[testenv]
extras =
test
commands_pre =
sh -c "rm -f {envdir}/.coverage.* 2>/dev/null || true"
# safety measure to assure we do not accidentally run tests with broken dependencies
{envpython} -m pip check
commands =
skip_install = true
coverage run -m pytest {posargs:\
-ra \
--showlocals \
--doctest-modules \
--durations=10 \
}
{py,py310,py311,py312,py313}: sh -xc "coverage combine -a -q --data-file={envdir}/.coverage {toxworkdir}/*/.coverage.* && coverage report --data-file={envdir}/.coverage && coverage xml --data-file={envdir}/.coverage -o {envdir}/coverage.xml"
editable = true
pass_env =
CURL_CA_BUNDLE # https proxies, https://github.com/tox-dev/tox/issues/1437
FORCE_COLOR
HOME
LANG
LC_*
NO_COLOR
PYTEST_* # allows developer to define their own preferences
PYTEST_REQPASS # needed for CI
PYTHON* # PYTHONPYCACHEPREFIX, PYTHONIOENCODING, PYTHONBREAKPOINT,...
PY_COLORS
RTD_TOKEN
REQUESTS_CA_BUNDLE # https proxies
SETUPTOOLS_SCM_DEBUG
SSL_CERT_FILE # https proxies
SSH_AUTH_SOCK # may be needed by git
UV_*
# recreate = True
setenv =
COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}}
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
skip_install = false
usedevelop = false
changedir = {toxinidir}
allowlist_externals =
sh
uv_seed = true

[testenv:docs]
description = Build docs
deps =
-r requirements.in
ansible-core
extras = docs
passenv =
*
commands =
; ansible-playbook -i localhost, playbooks/sync.yml
{envpython} -m mkdocs {posargs:build --strict --site-dir=_readthedocs/html/}
skip_install = true
skip_install = false
usedevelop = false

[testenv:lint]
Expand All @@ -50,3 +90,28 @@ commands =
podman run -it adt-{envname} adt --version
allowlist_externals =
podman
[testenv:pkg]
description =
Build package, verify metadata, install package and assert behavior when ansible is missing.
deps =
build >= 0.9.0
twine >= 4.0.1
pip
pipx
skip_install = true
# Ref: https://twitter.com/di_codes/status/1044358639081975813
commands_pre =
commands =
# build wheel and sdist using PEP-517
{envpython} -c 'import os.path, shutil, sys; \
dist_dir = os.path.join("{toxinidir}", "dist"); \
os.path.isdir(dist_dir) or sys.exit(0); \
print("Removing \{!s\} contents...".format(dist_dir), file=sys.stderr); \
shutil.rmtree(dist_dir)'
{envpython} -m build --outdir {toxinidir}/dist/ {toxinidir}
# Validate metadata using twine
python3 -m twine check --strict {toxinidir}/dist/*
# Install the wheel
sh -c 'python3 -m pip install "team-devtools @ file://$(echo {toxinidir}/dist/*.whl)"'
# Uninstall it
python3 -m pip uninstall -y team-devtools

0 comments on commit 0d4dbca

Please sign in to comment.