~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Benjamin Drung
  • Date: 2023-02-13 11:33:22 UTC
  • Revision ID: benjamin.drung@canonical.com-20230213113322-j0jtzd1ph9h3z5lq
Capitalize Python in package description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python3
2
2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
3
3
 
 
4
import glob
4
5
import os
5
 
import glob
6
 
 
 
6
import pathlib
 
7
import re
7
8
from distutils.core import setup
8
9
from subprocess import check_output
9
10
 
10
 
from DistUtilsExtra.command import (
11
 
    build_extra, build_i18n, build_help)
12
 
 
 
11
from DistUtilsExtra.command import build_extra, build_help, build_i18n
13
12
 
14
13
disabled = []
15
14
 
16
15
 
 
16
def make_pep440_compliant(version: str) -> str:
 
17
    """Convert the version into a PEP440 compliant version."""
 
18
    if ":" in version:
 
19
        # Strip epoch
 
20
        version = version.split(":", 1)[1]
 
21
    public_version_re = re.compile(
 
22
        r"^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?"
 
23
    )
 
24
    _, public, local = public_version_re.split(version, maxsplit=1)
 
25
    if not local:
 
26
        return version
 
27
    sanitized_local = re.sub("[+~]+", ".", local).strip(".")
 
28
    pep440_version = f"{public}+{sanitized_local}"
 
29
    assert re.match(
 
30
        "^[a-zA-Z0-9.]+$", sanitized_local
 
31
    ), f"'{pep440_version}' not PEP440 compliant"
 
32
    return pep440_version
 
33
 
 
34
 
17
35
def plugins():
18
36
    return []
19
37
    return [os.path.join('janitor/plugincore/plugins', name)
25
43
                         universal_newlines=True).splitlines():
26
44
    header, colon, value = line.lower().partition(':')
27
45
    if header == 'version':
28
 
        version = value.strip()
 
46
        VERSION = make_pep440_compliant(value.strip())
29
47
        break
30
48
else:
31
49
    raise RuntimeError('No version found in debian/changelog')
33
51
 
34
52
class CustomBuild(build_extra.build_extra):
35
53
    def run(self):
36
 
        with open("UpdateManager/UpdateManagerVersion.py", "w") as f:
37
 
            f.write("VERSION = '%s'\n" % version)
 
54
        version_py = pathlib.Path("UpdateManager/UpdateManagerVersion.py")
 
55
        version_py.write_text(f"VERSION = '{VERSION}'\n", encoding="utf-8")
38
56
        build_extra.build_extra.run(self)
39
57
 
40
58
 
41
59
setup(name='update-manager',
42
 
      version=version,
 
60
      version=VERSION,
43
61
      packages=['UpdateManager',
44
62
                'UpdateManager.backend',
45
63
                'UpdateManager.Core',