Diff of /setup.py [000000] .. [030aeb]

Switch to unified view

a b/setup.py
1
#!/usr/bin/env python
2
3
import os
4
import sys
5
from shutil import rmtree
6
from setuptools import Command, find_packages, setup
7
8
here = os.path.abspath(os.path.dirname(__file__))
9
10
11
def get_version():
12
    init_py_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "dosma", "__init__.py")
13
    init_py = open(init_py_path, "r").readlines()
14
    version_line = [l.strip() for l in init_py if l.startswith("__version__")][0]  # noqa: E741
15
    version = version_line.split("=")[-1].strip().strip("'\"")
16
17
    # The following is used to build release packages.
18
    # Users should never use it.
19
    suffix = os.getenv("DOSMA_VERSION_SUFFIX", "")
20
    version = version + suffix
21
    if os.getenv("BUILD_NIGHTLY", "0") == "1":
22
        from datetime import datetime
23
24
        date_str = datetime.today().strftime("%y%m%d")
25
        version = version + ".dev" + date_str
26
27
        new_init_py = [l for l in init_py if not l.startswith("__version__")]  # noqa: E741
28
        new_init_py.append('__version__ = "{}"\n'.format(version))
29
        with open(init_py_path, "w") as f:
30
            f.write("".join(new_init_py))
31
    return version
32
33
34
def get_resources():
35
    """Get the resources files for dosma. To be used with `package_data`.
36
37
    All files under 'dosma/resources/{elastix,templates}'.
38
    """
39
    import pathlib
40
41
    files = []
42
    # Elastix files
43
    for path in pathlib.Path("dosma/resources/elastix/params").rglob("*.*"):
44
        files.append(str(path))
45
    for path in pathlib.Path("dosma/resources/templates").rglob("*.*"):
46
        files.append(str(path))
47
    return [x.split("/", 1)[1] for x in files]
48
49
50
class UploadCommand(Command):
51
    """Support setup.py upload.
52
53
    Adapted from https://github.com/robustness-gym/meerkat.
54
    """
55
56
    description = "Build and publish the package."
57
    user_options = []
58
59
    @staticmethod
60
    def status(s):
61
        """Prints things in bold."""
62
        print("\033[1m{0}\033[0m".format(s))
63
64
    def initialize_options(self):
65
        pass
66
67
    def finalize_options(self):
68
        pass
69
70
    def run(self):
71
        try:
72
            self.status("Removing previous builds…")
73
            rmtree(os.path.join(here, "dist"))
74
        except OSError:
75
            pass
76
77
        self.status("Building Source and Wheel (universal) distribution…")
78
        os.system("{0} setup.py sdist bdist_wheel --universal".format(sys.executable))
79
80
        self.status("Uploading the package to PyPI via Twine…")
81
        os.system("twine upload dist/*")
82
83
        self.status("Pushing git tags…")
84
        os.system("git tag v{0}".format(get_version()))
85
        os.system("git push --tags")
86
87
        sys.exit()
88
89
90
# ---------------------------------------------------
91
# Setup Information
92
# ---------------------------------------------------
93
94
# Required pacakges.
95
REQUIRED = [
96
    "matplotlib",
97
    "numpy",
98
    "h5py",
99
    "natsort",
100
    "nested-lookup",
101
    "nibabel",
102
    "nipype",
103
    "packaging",
104
    "pandas",
105
    # TODO Issue #57: Remove pydicom upper bound (https://github.com/ad12/DOSMA/issues/57)
106
    "pydicom>=1.6.0",
107
    "scikit-image",
108
    "scipy",
109
    "seaborn",
110
    "openpyxl",
111
    "Pmw",
112
    "PyYAML",
113
    "tabulate",
114
    "termcolor",
115
    "tqdm>=4.42.0",
116
]
117
118
# Optional packages.
119
# TODO Issue #106: Fix to only import tensorflow version with fixed version
120
# once keras import statements are properly handled.
121
EXTRAS = {
122
    "dev": [
123
        "coverage",
124
        "flake8",
125
        "flake8-bugbear",
126
        "flake8-comprehensions",
127
        "isort",
128
        "black==21.4b2",
129
        "click==8.0.2",
130
        "simpleitk",
131
        "sphinx",
132
        "sphinxcontrib.bibtex",
133
        "m2r2",
134
        "tensorflow<=2.4.1",
135
        "keras<=2.4.3",
136
        "sigpy",
137
    ],
138
    "ai": ["tensorflow<=2.4.1", "keras<=2.4.3"],
139
    "docs": ["mistune>=0.8.1,<2.0.0", "sphinx", "sphinxcontrib.bibtex", "m2r2"],
140
}
141
142
with open("README.md", "r", encoding="utf-8") as fh:
143
    long_description = fh.read()
144
145
146
setup(
147
    name="dosma",
148
    version=get_version(),
149
    author="Arjun Desai",
150
    url="https://github.com/ad12/DOSMA",
151
    project_urls={"Documentation": "https://dosma.readthedocs.io/"},
152
    description="An AI-powered open-source medical image analysis toolbox",
153
    long_description=long_description,
154
    long_description_content_type="text/markdown",
155
    packages=find_packages(exclude=("configs", "tests", "tests.*")),
156
    package_data={"dosma": get_resources()},
157
    python_requires=">=3.6",
158
    install_requires=REQUIRED,
159
    license="GNU",
160
    classifiers=[
161
        "Programming Language :: Python :: 3",
162
        "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
163
        "Operating System :: OS Independent",
164
    ],
165
    extras_require=EXTRAS,
166
    # $ setup.py publish support.
167
    cmdclass={
168
        "upload": UploadCommand,
169
    },
170
)