-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revisit versioning and streamline maintenance adding "bump" and "tag_…
…release" nox sessions (#13) * feat: simplify versioning by hard-coding value in pyproject.toml This major version associated with the package is now consistent with the IDC table version hard-coded in `scripts/sql/idc_index.sql`. Co-authored-by: Henry Schreiner <[email protected]> * chore: Add "bump" nox session to streamline IDC index version update Co-authored-by: Henry Schreiner <[email protected]> * chore: Add nox session and instructions for tagging a release Co-authored-by: Henry Schreiner <[email protected]> --------- Co-authored-by: Henry Schreiner <[email protected]>
- Loading branch information
Showing
6 changed files
with
215 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ build-backend = "scikit_build_core.build" | |
|
||
[project] | ||
name = "idc-index-data" | ||
version = "17.0.0" | ||
authors = [ | ||
{ name = "Andrey Fedorov", email = "[email protected]" }, | ||
{ name = "Vamsi Thiriveedhi", email = "[email protected]" }, | ||
|
@@ -39,7 +40,6 @@ classifiers = [ | |
"Topic :: Scientific/Engineering", | ||
"Typing :: Typed", | ||
] | ||
dynamic = ["version"] | ||
dependencies = [] | ||
|
||
[project.optional-dependencies] | ||
|
@@ -69,15 +69,15 @@ Changelog = "https://github.com/ImagingDataCommons/idc-index-data/releases" | |
[tool.scikit-build] | ||
minimum-version = "0.8.2" | ||
build-dir = "build/{wheel_tag}" | ||
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" | ||
sdist.include = ["src/idc_index_data/_version.py"] | ||
wheel.platlib = false | ||
wheel.py-api = "py3" | ||
|
||
|
||
[tool.setuptools_scm] | ||
write_to = "src/idc_index_data/_version.py" | ||
version_scheme = "no-guess-dev" | ||
[[tool.scikit-build.generate]] | ||
path = "idc_index_data/_version.py" | ||
template = ''' | ||
version = "${version}" | ||
''' | ||
|
||
|
||
[tool.pytest.ini_options] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Command line executable allowing to update source files given a IDC index version. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import contextlib | ||
import os | ||
import re | ||
import textwrap | ||
from pathlib import Path | ||
|
||
ROOT_DIR = Path(__file__).parent / "../.." | ||
|
||
|
||
@contextlib.contextmanager | ||
def _log(txt, verbose=True): | ||
if verbose: | ||
print(txt) # noqa: T201 | ||
yield | ||
if verbose: | ||
print(f"{txt} - done") # noqa: T201 | ||
|
||
|
||
def _update_file(filepath, regex, replacement): | ||
msg = "Updating %s" % os.path.relpath(str(filepath), ROOT_DIR) | ||
with _log(msg): | ||
pattern = re.compile(regex) | ||
with filepath.open() as doc_file: | ||
lines = doc_file.readlines() | ||
updated_content = [] | ||
for line in lines: | ||
updated_content.append(re.sub(pattern, replacement, line)) | ||
with filepath.open("w") as doc_file: | ||
doc_file.writelines(updated_content) | ||
|
||
|
||
def update_pyproject_toml(idc_index_version): | ||
pattern = re.compile(r'^version = "[\w\.]+"$') | ||
replacement = f'version = "{idc_index_version}.0.0"' | ||
_update_file(ROOT_DIR / "pyproject.toml", pattern, replacement) | ||
|
||
|
||
def update_sql_scripts(idc_index_version): | ||
pattern = re.compile(r"idc_v\d+") | ||
replacement = f"idc_v{idc_index_version}" | ||
_update_file(ROOT_DIR / "scripts/sql/idc_index.sql", pattern, replacement) | ||
|
||
|
||
def update_tests(idc_index_version): | ||
pattern = re.compile(r"EXPECTED_IDC_INDEX_VERSION = \d+") | ||
replacement = f"EXPECTED_IDC_INDEX_VERSION = {idc_index_version}" | ||
_update_file(ROOT_DIR / "tests/test_package.py", pattern, replacement) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument( | ||
"idc_index_version", | ||
metavar="IDC_INDEX_VERSION", | ||
type=int, | ||
help="IDC index version of the form NN", | ||
) | ||
parser.add_argument( | ||
"--quiet", | ||
action="store_true", | ||
help="Hide the output", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
update_pyproject_toml(args.idc_index_version) | ||
update_sql_scripts(args.idc_index_version) | ||
update_tests(args.idc_index_version) | ||
|
||
if not args.quiet: | ||
msg = """\ | ||
Complete! Now run: | ||
git switch -c update-to-idc-index-{release} | ||
git add -u pyproject.toml scripts/sql/idc_index.sql tests/test_package.py | ||
git commit -m "Update to IDC index {release}" | ||
gh pr create --fill --body "Created by update_idc_index_version.py" | ||
""" | ||
print(textwrap.dedent(msg.format(release=args.idc_index_version))) # noqa: T201 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from __future__ import annotations | ||
|
||
version: str | ||
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters