Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version handling #1878

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 12 additions & 66 deletions nbconvert/_version.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
__version__ = "7.2.0"
version_info = (7, 2, 0)
pre_info = ""
dev_info = "dev0"


def create_valid_version(release_info, epoch=None, pre_input="", dev_input=""):
"""
Creates a pep440 valid version of version number given a tuple integers
and optional epoch, prerelease and developmental info.

Parameters
----------
release_info : Tuple(Int)
epoch : Int, default None
pre_input : Str, default ''
dev_input : Str, default ''
"""

pep440_err = "The version number is not a pep 440 compliant version number"

if epoch is not None:
epoch_seg = str(epoch) + "!"
else:
epoch_seg = ""

release_seg = ".".join(map(str, release_info))

_magic_pre = ["a", "b", "rc"]
if pre_input != "" and not any([pre_input.startswith(prefix) for prefix in _magic_pre]):
raise ValueError(pep440_err + "\n please fix your prerelease segment.")
else:
pre_seg = pre_input

if dev_input == "":
dev_seg = dev_input
elif not dev_input.startswith(".") and dev_input.startswith("dev"):
dev_seg = "".join([".", dev_input])
elif dev_input.startswith(".dev"):
dev_seg = dev_input
elif dev_input != "":
raise ValueError(pep440_err + "\n please fix your development segment.")

if dev_input != "" and not any([dev_seg.endswith(str(n)) for n in range(10)]):
dev_seg = "".join([dev_seg, "0"])

out_version = "".join([epoch_seg, release_seg, pre_seg, dev_seg])

import re

def is_canonical(version):
return (
re.match(
r"^([1-9]\d*!)?(0|[1-9]\d*)"
r"(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*))?"
r"(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?$",
version,
)
is not None
)

if is_canonical(out_version):
return out_version
else:
raise ValueError(pep440_err)
import re
from typing import List

# Version string must appear intact for versioning
__version__ = "7.2.0"

assert __version__ == create_valid_version(version_info, pre_input=pre_info, dev_input=dev_info)
# Build up version_info tuple for backwards compatibility
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
match = re.match(pattern, __version__)
assert match is not None
parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
if match["rest"]:
parts.append(match["rest"])
version_info = tuple(parts)