Skip to content

Commit 369b98e

Browse files
committed
Use config.version_file for version:check
1 parent 5664744 commit 369b98e

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

doc/changes/unreleased.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Unreleased
22

33
## 📚 Documentation
4-
* Updated getting_started.rst for allowing tag-based releases
4+
* Updated getting_started.rst for allowing tag-based releases
5+
6+
## ✨ Features
7+
8+
* [#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`

exasol/toolbox/nox/_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _pyupgrade(session: Session, files: Iterable[str]) -> None:
3636
def fix(session: Session) -> None:
3737
"""Runs all automated fixes on the code base"""
3838
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
39-
_version(session, Mode.Fix, PROJECT_CONFIG.version_file)
39+
_version(session, Mode.Fix)
4040
_pyupgrade(session, py_files)
4141
_code_format(session, Mode.Fix, py_files)
4242

exasol/toolbox/nox/_package_version.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
from exasol.toolbox.error import ToolboxError
1313
from exasol.toolbox.util.version import Version
14+
from noxconfig import (
15+
PROJECT_CONFIG,
16+
Config,
17+
)
1418

1519
_SUCCESS = 0
1620
_FAILURE = 1
@@ -20,7 +24,7 @@
2024
# ATTENTION:
2125
# This file is generated by exasol/toolbox/nox/_package_version.py when using:
2226
# * either "poetry run -- nox -s project:fix"
23-
# * or "poetry run -- nox version:check -- <path/version.py> --fix"
27+
# * or "poetry run -- nox version:check -- --fix"
2428
# Do not edit this file manually!
2529
# If you need to change the version, do so in the pyproject.toml, e.g. by using `poetry version X.Y.Z`.
2630
MAJOR = {major}
@@ -32,8 +36,7 @@
3236
# fmt: on
3337

3438

35-
def write_version_module(version: Version, path: str, exists_ok: bool = True) -> None:
36-
version_file = Path(path)
39+
def write_version_module(version: Version, version_file: Path, exists_ok: bool = True) -> None:
3740
if version_file.exists() and not exists_ok:
3841
raise ToolboxError(f"Version file [{version_file}] already exists.")
3942
version_file.unlink(missing_ok=True)
@@ -50,8 +53,6 @@ def _create_parser() -> ArgumentParser:
5053
prog="nox -s version:check --",
5154
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
5255
)
53-
parser.add_argument("version_module", help="Path to version module")
54-
parser.add_argument("files", nargs="*")
5556
parser.add_argument(
5657
"-d",
5758
"--debug",
@@ -69,23 +70,22 @@ def _create_parser() -> ArgumentParser:
6970
return parser
7071

7172

72-
def _version_check(args: Namespace) -> int:
73-
module_version = Version.from_python_module(args.version_module)
74-
poetry_version = Version.from_poetry()
73+
def _version_check(args: Namespace, config: Config) -> int:
74+
version_file = config.version_file
7575

76+
module_version = Version.from_python_module(version_file)
77+
poetry_version = Version.from_poetry()
7678
if args.fix:
77-
write_version_module(poetry_version, args.version_module)
79+
print(
80+
f"Updating version in {version_file} from {module_version} to {poetry_version}"
81+
)
82+
write_version_module(version=poetry_version, version_file=version_file)
83+
module_version = Version.from_python_module(version_file)
7884

7985
if module_version != poetry_version:
8086
print(
81-
f"Version in pyproject.toml {poetry_version} and {args.version_module} {module_version} do not match!"
87+
f"Version in pyproject.toml ({poetry_version}) and {version_file} ({module_version}) do not match!"
8288
)
83-
if args.fix:
84-
print(
85-
f"Updating version in file ({args.version_module}) from {module_version} to {poetry_version}"
86-
)
87-
return _SUCCESS
88-
8989
return _FAILURE
9090

9191
return _SUCCESS
@@ -99,5 +99,5 @@ def version_check(session: Session) -> None:
9999
"""
100100
parser = _create_parser()
101101
args = parser.parse_args(session.posargs)
102-
if _version_check(args):
102+
if _version_check(args=args, config=PROJECT_CONFIG):
103103
session.error()

exasol/toolbox/nox/_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _is_valid_version(old: Version, new: Version) -> bool:
6767

6868
def _update_project_version(session: Session, version: Version) -> Version:
6969
session.run("poetry", "version", f"{version}")
70-
_version(session, Mode.Fix, PROJECT_CONFIG.version_file)
70+
_version(session, Mode.Fix)
7171
return version
7272

7373

exasol/toolbox/nox/_shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def python_files(project_root: Path) -> Iterable[Path]:
3636
return [path for path in files if not set(path.parts).intersection(deny_list)]
3737

3838

39-
def _version(session: Session, mode: Mode, version_file: Path) -> None:
39+
def _version(session: Session, mode: Mode) -> None:
4040
command = ["nox", "-s", "version:check", "--"]
4141
command = command if mode == Mode.Check else command + ["--fix"]
42-
session.run(*command, f"{version_file}")
42+
session.run(*command)
4343

4444

4545
def _context_parser() -> argparse.ArgumentParser:

exasol/toolbox/nox/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def check(session: Session) -> None:
3535
"""Runs all available checks on the project"""
3636
context = _context(session, coverage=True)
3737
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
38-
_version(session, Mode.Check, PROJECT_CONFIG.version_file)
38+
_version(session, Mode.Check)
3939
_code_format(session, Mode.Check, py_files)
4040
_pylint(session, py_files)
4141
_type_check(session, py_files)

exasol/toolbox/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ATTENTION:
22
# This file is generated by exasol/toolbox/nox/_package_version.py when using:
33
# * either "poetry run -- nox -s project:fix"
4-
# * or "poetry run -- nox version:check -- <path/version.py> --fix"
4+
# * or "poetry run -- nox version:check -- --fix"
55
# Do not edit this file manually!
66
# If you need to change the version, do so in the pyproject.toml, e.g. by using `poetry version X.Y.Z`.
77
MAJOR = 1

0 commit comments

Comments
 (0)