-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move developmental release version generation out of CI file
- Loading branch information
1 parent
d0adbc1
commit 3303a26
Showing
6 changed files
with
132 additions
and
31 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 |
---|---|---|
@@ -1,27 +1,25 @@ | ||
[project] | ||
name = "backports-datetime-fromisoformat" | ||
version = "2.0.1" | ||
authors = [ | ||
{ name="Michael Overmeyer", email="[email protected]" }, | ||
] | ||
authors = [{ name = "Michael Overmeyer", email = "[email protected]" }] | ||
description = "Backport of Python 3.11's datetime.fromisoformat" | ||
readme = "README.rst" | ||
requires-python = ">3" | ||
license = {file = "LICENSE"} | ||
license = { file = "LICENSE" } | ||
classifiers = [ | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
] | ||
|
||
[project.urls] | ||
|
@@ -34,3 +32,14 @@ Changelog = "https://github.com/movermeyer/backports.datetime_fromisoformat/CHAN | |
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pylint.'MESSAGES CONTROL'] | ||
max-line-length = 120 | ||
disable = "C0114, C0115, C0116, C0301" | ||
|
||
[tool.autopep8] | ||
max_line_length = 120 | ||
ignore = ["E501"] | ||
in-place = true | ||
recursive = true | ||
aggressive = 3 |
Empty file.
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,47 @@ | ||
import argparse | ||
import json | ||
import sys | ||
|
||
from packaging.version import parse, Version | ||
from typing import Iterator | ||
|
||
def _releases(contents) -> Iterator[Version]: | ||
parsed = json.loads(contents) | ||
existing_releases = [parse(x) for x in parsed["releases"].keys()] | ||
return existing_releases | ||
|
||
def non_developmental_version(version: Version): | ||
if not version.is_devrelease: | ||
return version | ||
|
||
epoch = f"{version.epoch}!" if version.epoch else "" | ||
release = ".".join([str(x) for x in version.release]) | ||
pre = f"{version.pre[0]}{version.pre[1]}" if version.pre else "" | ||
post = f".post{version.post}" if version.post else "" | ||
return parse(f"{epoch}{release}{pre}{post}") | ||
|
||
|
||
def new_developmental_release_version(new: Version, existing_releases: Iterator[Version]) -> Version: | ||
existing = max([x for x in existing_releases if x.is_devrelease and non_developmental_version(x) == new], default=parse("0.0.0")) | ||
dev_number = existing.dev + 1 if existing.is_devrelease and new.release == existing.release else 1 | ||
|
||
epoch = f"{new.epoch}!" if new.epoch else "" | ||
release = ".".join([str(x) for x in new.release]) | ||
pre = f"{new.pre[0]}{new.pre[1]}" if new.pre else "" | ||
post = f".post{new.post}" if new.post else "" | ||
dev = f".dev{dev_number}" | ||
return parse(f"{epoch}{release}{pre}{post}{dev}") | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description='Generates the next developmental release version number based on existing releases' | ||
) | ||
|
||
parser.add_argument('new_version', help='The new version number you want to use (without any `.dev` suffix)') | ||
args = parser.parse_args() | ||
|
||
contents = sys.stdin.read() | ||
existing_releases = _releases(contents) | ||
dev_version = new_developmental_release_version(parse(args.new_version), existing_releases) | ||
print(dev_version) |
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,40 @@ | ||
import itertools | ||
import unittest | ||
|
||
from packaging.version import parse, Version | ||
from typing import Iterator | ||
|
||
from developmental_release import new_developmental_release_version | ||
|
||
def generate_versions() -> Iterator[Version]: | ||
# https://peps.python.org/pep-0440/ | ||
epoch_options = ["", "1!"] | ||
release_options = ['2', '2.0', '2.0.0', '2.0.0.0', '2.0.0.0.0'] | ||
pre_release_options = ["", 'a1', 'b1', 'rc1'] | ||
post_release_options = ["", ".post1"] | ||
dev_options = ["", ".dev1"] | ||
for v in (parse(f"{epoch}{release}{pre_release}{post_release}{dev}") for (epoch, release, pre_release, post_release, dev) in itertools.product(epoch_options, release_options, pre_release_options, post_release_options, dev_options)): | ||
yield v | ||
|
||
class TestDevelopmentalVersionGeneration(unittest.TestCase): | ||
def test_no_releases(self): | ||
for version in generate_versions(): | ||
if version.is_devrelease: | ||
continue | ||
new_dev_version = new_developmental_release_version(version, []) | ||
self.assertRegex(f"{new_dev_version}", r"\.dev1$", f"Input: {version}, Output: {new_dev_version}") | ||
|
||
def test_existing_dev_release(self): | ||
for version in generate_versions(): | ||
if version.is_devrelease: | ||
continue | ||
new_dev_version = new_developmental_release_version(version, [parse(f"{version}.dev1")]) | ||
self.assertRegex(f"{new_dev_version}", r"\.dev2$", f"Input: {version}, Output: {new_dev_version}") | ||
|
||
def test_dev_release_exists_for_more_specific_version(self): | ||
version = parse("2.0.0") | ||
new_dev_version = new_developmental_release_version(version, [parse("2.0.0b1.dev1")]) | ||
self.assertRegex(f"{new_dev_version}", r"\.dev1$", f"Input: {version}, Output: {new_dev_version}") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |