mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-15 02:41:28 +00:00
refactor(setup.py): Introduce get_debian_version
Move getting the Debian package version into a separate function and fail in case it cannot find it or fails parsing it. Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
This commit is contained in:
parent
a685368ae9
commit
8692bc2b1c
23
setup.py
23
setup.py
@ -1,12 +1,23 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import pathlib
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
def get_debian_version() -> str:
|
||||||
|
"""Look what Debian version we have."""
|
||||||
|
changelog = pathlib.Path(__file__).parent / "debian" / "changelog"
|
||||||
|
with changelog.open("r", encoding="utf-8") as changelog_f:
|
||||||
|
head = changelog_f.readline()
|
||||||
|
match = re.compile(r".*\((.*)\).*").match(head)
|
||||||
|
if not match:
|
||||||
|
raise ValueError(f"Failed to extract Debian version from '{head}'.")
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
|
||||||
def make_pep440_compliant(version: str) -> str:
|
def make_pep440_compliant(version: str) -> str:
|
||||||
"""Convert the version into a PEP440 compliant version."""
|
"""Convert the version into a PEP440 compliant version."""
|
||||||
public_version_re = re.compile(r"^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?")
|
public_version_re = re.compile(r"^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?")
|
||||||
@ -19,14 +30,6 @@ def make_pep440_compliant(version: str) -> str:
|
|||||||
return pep440_version
|
return pep440_version
|
||||||
|
|
||||||
|
|
||||||
# look/set what version we have
|
|
||||||
changelog = "debian/changelog"
|
|
||||||
if os.path.exists(changelog):
|
|
||||||
head = open(changelog, "r", encoding="utf-8").readline()
|
|
||||||
match = re.compile(r".*\((.*)\).*").match(head)
|
|
||||||
if match:
|
|
||||||
version = match.group(1)
|
|
||||||
|
|
||||||
scripts = [
|
scripts = [
|
||||||
"backportpackage",
|
"backportpackage",
|
||||||
"bitesize",
|
"bitesize",
|
||||||
@ -81,7 +84,7 @@ data_files = [
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
setup(
|
setup(
|
||||||
name="ubuntu-dev-tools",
|
name="ubuntu-dev-tools",
|
||||||
version=make_pep440_compliant(version),
|
version=make_pep440_compliant(get_debian_version()),
|
||||||
scripts=scripts,
|
scripts=scripts,
|
||||||
packages=[
|
packages=[
|
||||||
"ubuntutools",
|
"ubuntutools",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user