Skip to content

Commit 192541d

Browse files
committed
#426: Allowed configuring the python version used for coverage
1 parent 097f0be commit 192541d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

doc/changes/unreleased.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ which is specified in the `noxconfig.py`
1010

1111
## ✨ Features
1212

13-
* [#441](https://github.com/exasol/python-toolbox/issues/441): Switched nox task for `version:check` to use the config value of `version_file` to specify the location of the `version.py`
13+
* [#441](https://github.com/exasol/python-toolbox/issues/441): Switched nox task for `version:check` to use the config value of `version_file` to specify the location of the `version.py`
14+
## Features
15+
16+
* #426: Allowed configuring the python version used for coverage

exasol/toolbox/nox/_artifacts.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import shutil
12
import json
23
import pathlib
34
import re
@@ -118,3 +119,51 @@ def _validate_coverage(path: Path) -> str:
118119
f"Invalid database, the database is missing the following tables {missing}"
119120
)
120121
return ""
122+
123+
124+
@nox.session(name="artifacts:copy", python=False)
125+
def copy_artifacts(session: Session) -> None:
126+
"""
127+
Copy artifacts to the current directory
128+
"""
129+
130+
def get_suffix() -> str:
131+
versions = getattr(PROJECT_CONFIG, "python_versions", None)
132+
pivot = versions[0] if versions else "3.9"
133+
return f"-python{pivot}"
134+
135+
dir = Path(session.posargs[0])
136+
suffix = _python_version_suffix()
137+
_combine_coverage(session, dir, f"coverage{suffix}*/.coverage")
138+
_copy_artifacts(
139+
dir,
140+
f"lint{suffix}/.lint.txt",
141+
f"lint{suffix}/.lint.json",
142+
f"security{suffix}/.security.json",
143+
)
144+
145+
146+
def _python_version_suffix() -> str:
147+
versions = getattr(PROJECT_CONFIG, "python_versions", None)
148+
pivot = versions[0] if versions else "3.9"
149+
return f"-python{pivot}"
150+
151+
152+
def _combine_coverage(session: Session, dir: Path, pattern: str):
153+
"""
154+
pattern: glob pattern, e.g. "*.coverage"
155+
"""
156+
if args := [f for f in dir.glob(pattern) if f.exists()]:
157+
session.run("coverage", "combine", "--keep", *args)
158+
else:
159+
print(f"Could not find any file {dir}/{pattern}")
160+
161+
162+
def _copy_artifacts(dir: Path, *files: str):
163+
for file in files:
164+
path = dir / file
165+
if path.exists():
166+
print(f"Copying file {path}")
167+
shutil.copy(path, ".")
168+
else:
169+
print(f"File not found {path}")

0 commit comments

Comments
 (0)