~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 13:07:34 UTC
  • Revision ID: benjamin.drung@canonical.com-20230213130734-w3qjkzl851rmv1am
Sort imports in UpdateManager/Core/utils.py with isort

```
isort -l 79 --profile=black UpdateManager/Core/utils.py
```

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
 
    return [os.path.join('janitor/plugincore/plugins', name)
20
 
            for name in os.listdir('janitor/plugincore/plugins')
21
 
            if name.endswith('_plugin.py') and name not in disabled]
22
 
 
23
 
 
24
 
for line in check_output('dpkg-parsechangelog --format rfc822'.split(),
25
 
                         universal_newlines=True).splitlines():
26
 
    header, colon, value = line.lower().partition(':')
27
 
    if header == 'version':
28
 
        version = value.strip()
 
37
    return [
 
38
        os.path.join("janitor/plugincore/plugins", name)
 
39
        for name in os.listdir("janitor/plugincore/plugins")
 
40
        if name.endswith("_plugin.py") and name not in disabled
 
41
    ]
 
42
 
 
43
 
 
44
for line in check_output(
 
45
    "dpkg-parsechangelog --format rfc822".split(), universal_newlines=True
 
46
).splitlines():
 
47
    header, colon, value = line.lower().partition(":")
 
48
    if header == "version":
 
49
        VERSION = make_pep440_compliant(value.strip())
29
50
        break
30
51
else:
31
 
    raise RuntimeError('No version found in debian/changelog')
 
52
    raise RuntimeError("No version found in debian/changelog")
32
53
 
33
54
 
34
55
class CustomBuild(build_extra.build_extra):
35
56
    def run(self):
36
 
        with open("UpdateManager/UpdateManagerVersion.py", "w") as f:
37
 
            f.write("VERSION = '%s'\n" % version)
 
57
        version_py = pathlib.Path("UpdateManager/UpdateManagerVersion.py")
 
58
        version_py.write_text(f"VERSION = '{VERSION}'\n", encoding="utf-8")
38
59
        build_extra.build_extra.run(self)
39
60
 
40
61
 
41
 
setup(name='update-manager',
42
 
      version=version,
43
 
      packages=['UpdateManager',
44
 
                'UpdateManager.backend',
45
 
                'UpdateManager.Core',
46
 
                'HweSupportStatus',
47
 
                'janitor',
48
 
                'janitor.plugincore',
49
 
                ],
50
 
      scripts=['update-manager',
51
 
               'ubuntu-security-status',
52
 
               'hwe-support-status'
53
 
               ],
54
 
      data_files=[('share/update-manager/gtkbuilder',
55
 
                   glob.glob("data/gtkbuilder/*.ui")
56
 
                   ),
57
 
                  ('share/man/man8',
58
 
                   glob.glob('data/*.8')
59
 
                   ),
60
 
                  ('share/GConf/gsettings/',
61
 
                   ['data/update-manager.convert']),
62
 
                  ],
63
 
      cmdclass={"build": CustomBuild,
64
 
                "build_i18n": build_i18n.build_i18n,
65
 
                "build_help": build_help.build_help}
66
 
      )
 
62
setup(
 
63
    name="update-manager",
 
64
    version=VERSION,
 
65
    packages=[
 
66
        "UpdateManager",
 
67
        "UpdateManager.backend",
 
68
        "UpdateManager.Core",
 
69
        "HweSupportStatus",
 
70
        "janitor",
 
71
        "janitor.plugincore",
 
72
    ],
 
73
    scripts=["update-manager", "ubuntu-security-status", "hwe-support-status"],
 
74
    data_files=[
 
75
        ("share/update-manager/gtkbuilder", glob.glob("data/gtkbuilder/*.ui")),
 
76
        ("share/man/man8", glob.glob("data/*.8")),
 
77
        ("share/GConf/gsettings/", ["data/update-manager.convert"]),
 
78
    ],
 
79
    cmdclass={
 
80
        "build": CustomBuild,
 
81
        "build_i18n": build_i18n.build_i18n,
 
82
        "build_help": build_help.build_help,
 
83
    },
 
84
)