forked from siliconcompiler/siliconcompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·151 lines (128 loc) · 5.31 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
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
import glob
import os
import shutil
import sys
from setuptools import find_packages
# Hack to get version number since it's considered bad practice to import your
# own package in setup.py. This call defines keys 'version', 'authors', and
# 'banner' in the `metadata` dict.
metadata = {}
with open('siliconcompiler/_metadata.py') as f:
exec(f.read(), metadata)
on_rtd = os.environ.get('READTHEDOCS') == 'True'
if not on_rtd:
try:
from skbuild import setup
except ImportError:
print(
"Error finding build dependencies!\n"
"If you're installing this project using pip, make sure you're using pip version 10 "
"or greater.\n"
"If you're installing this project by running setup.py, manually install all "
"dependencies listed in requirements.txt.",
file=sys.stderr
)
raise
else:
from setuptools import setup
with open("README.md", "r", encoding="utf-8") as readme:
long_desc = readme.read()
def parse_reqs():
'''Parse out each requirement category from requirements.txt'''
install_reqs = []
extras_reqs = {}
current_section = None # default to install
with open('requirements.txt', 'r') as reqs_file:
for line in reqs_file.readlines():
line = line.rstrip('\n')
if line.startswith('#:'):
# strip off '#:' prefix to read extras name
current_section = line[2:]
if current_section not in extras_reqs:
extras_reqs[current_section] = []
elif not line or line.startswith('#'):
# skip blanks and comments
continue
elif current_section is None:
install_reqs.append(line)
else:
extras_reqs[current_section].append(line)
return install_reqs, extras_reqs
# Let us pass in generic arguments to CMake via an environment variable, since
# our automated build servers need to pass in a certain argument when building
# wheels on Windows.
cmake_args = []
if 'SC_CMAKEARGS' in os.environ:
cmake_args.append(os.environ['SC_CMAKEARGS'])
# Autogenerate list of entry points based on each file in apps/
entry_points_apps = []
for app in os.listdir('siliconcompiler/apps'):
name, ext = os.path.splitext(app)
if (name.startswith('sc') or name.startswith('sup')) and ext == '.py':
cli_name = name.replace('_', '-')
entry = f'{cli_name}=siliconcompiler.apps.{name}:main'
entry_points_apps.append(entry)
if cli_name == 'sc':
entry = f'siliconcompiler=siliconcompiler.apps.{name}:main'
entry_points_apps.append(entry)
# Remove the _skbuild/ directory before running install procedure. This helps
# fix very opaque bugs we've run into where the install fails due to some bad
# state being cached in this directory. This means we won't get caching of build
# results, but since the leflib is small and compiles quickly, and a user likely
# won't have to perform many installs anyways, this seems like a worthwhile
# tradeoff.
if os.path.isdir('_skbuild'):
print("Note: removing existing _skbuild/ directory.")
shutil.rmtree('_skbuild')
if not on_rtd:
skbuild_args = {
'cmake_install_dir': 'siliconcompiler/leflib',
'cmake_args': cmake_args
}
else:
skbuild_args = {}
def get_package_data(item, package):
'''Used to compensate for poor glob support in package_data'''
package_data = []
for f in glob.glob(f'{package}/{item}/**/*', recursive=True):
if os.path.isfile(f):
# strip off directory and add to list
package_data.append(f[len(package + '/'):])
return package_data
install_reqs, extras_req = parse_reqs()
setup(
name="siliconcompiler",
description="A compiler framework that automates translation from source code to silicon.",
long_description=long_desc,
long_description_content_type="text/markdown",
license='Apache License 2.0',
author="Andreas Olofsson",
author_email="[email protected]",
url="https://siliconcompiler.com",
project_urls={
"Documentation": "https://docs.siliconcompiler.com",
"Source Code": "https://github.com/siliconcompiler/siliconcompiler",
"Bug Tracker": "https://github.com/siliconcompiler/siliconcompiler/issues",
"Forum": "https://github.com/siliconcompiler/siliconcompiler/discussions"
},
version=metadata['version'],
packages=find_packages(where='.', exclude=['tests*']),
# TODO: hack to work around weird scikit-build behavior:
# https://github.com/scikit-build/scikit-build/issues/590
# Once this issue is resolved, we should switch to setting
# include_package_data to True instead of manually specifying package_data.
# include_package_data=True,
package_data={
'siliconcompiler':
[*get_package_data('templates', 'siliconcompiler'),
*get_package_data('data', 'siliconcompiler')],
'siliconcompiler.tools': get_package_data('.', 'siliconcompiler/tools'),
'siliconcompiler.checklists': get_package_data('.', 'siliconcompiler/checklists'),
},
python_requires=">=3.6",
install_requires=install_reqs,
extras_require=extras_req,
entry_points={"console_scripts": entry_points_apps},
**skbuild_args
)