-
Notifications
You must be signed in to change notification settings - Fork 20
/
setup.py
141 lines (118 loc) · 3.86 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright 2020 InterDigital Communications, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import find_packages, setup
cwd = Path(__file__).resolve().parent
package_name = "compressai"
version = "1.1.6dev0"
git_hash = "unknown"
try:
git_hash = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd).decode().strip()
)
except (FileNotFoundError, subprocess.CalledProcessError):
pass
def write_version_file():
path = cwd / package_name / "version.py"
with path.open("w") as f:
f.write(f'__version__ = "{version}"\n')
f.write(f'git_version = "{git_hash}"\n')
write_version_file()
def get_extensions():
ext_dirs = cwd / package_name / "cpp_exts"
ext_modules = []
# Add rANS module
rans_lib_dir = cwd / "third_party/ryg_rans"
rans_ext_dir = ext_dirs / "rans"
extra_compile_args = ["-std=c++17"]
if os.getenv("DEBUG_BUILD", None):
extra_compile_args += ["-O0", "-g", "-UNDEBUG"]
else:
extra_compile_args += ["-O3"]
ext_modules.append(
Pybind11Extension(
name=f"{package_name}.ans",
sources=[str(s) for s in rans_ext_dir.glob("*.cpp")],
language="c++",
include_dirs=[rans_lib_dir, rans_ext_dir],
extra_compile_args=extra_compile_args,
)
)
# Add ops
ops_ext_dir = ext_dirs / "ops"
ext_modules.append(
Pybind11Extension(
name=f"{package_name}._CXX",
sources=[str(s) for s in ops_ext_dir.glob("*.cpp")],
language="c++",
extra_compile_args=extra_compile_args,
)
)
return ext_modules
TEST_REQUIRES = ["pytest", "pytest-cov"]
DEV_REQUIRES = TEST_REQUIRES + [
"black",
"flake8",
"flake8-bugbear",
"flake8-comprehensions",
"isort",
"mypy",
]
def get_extra_requirements():
extras_require = {
"test": TEST_REQUIRES,
"dev": DEV_REQUIRES,
"doc": ["sphinx", "furo"],
"tutorials": ["jupyter", "ipywidgets"],
}
extras_require["all"] = set(req for reqs in extras_require.values() for req in reqs)
return extras_require
setup(
name=package_name,
version=version,
description="A PyTorch library and evaluation platform for end-to-end compression research",
url="https://github.com/InterDigitalInc/CompressAI",
author="InterDigital AI Lab",
author_email="[email protected]",
packages=find_packages(exclude=("tests",)),
zip_safe=False,
python_requires=">=3.6",
install_requires=[
"numpy",
"scipy",
"matplotlib",
"torch",
"torchvision",
"pytorch-msssim",
"timm",
"einops",
],
extras_require=get_extra_requirements(),
license="Apache-2",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
ext_modules=get_extensions(),
cmdclass={"build_ext": build_ext},
)