-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
178 lines (148 loc) · 5.51 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.command.sdist import sdist as _sdist
from os import path
import os
from os.path import dirname, abspath
from setuptools import find_packages, setup, Command
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
from shutil import copyfile
from shutil import rmtree
from subprocess import check_call, check_output
import sys
TOP_DIR = dirname(abspath(__file__))
JS_FILES = [
"node_modules/d3/dist/d3.js",
"node_modules/elkjs/lib/elk.bundled.js",
"node_modules/d3-hwschematic/dist/d3-hwschematic.js",
"node_modules/d3-hwschematic/dist/d3-hwschematic.css",
]
def npm_installation_check():
try:
v = check_output(["npm", "--version"])
except Exception:
return False
v = v.decode().split(".")
needs_update = int(v[0]) < 6
if needs_update:
print("Minimal npm version (6) not meet trying update")
check_call(["npm", "install", "npm"])
return True
def run_npm_install():
my_env = os.environ.copy()
# PYTHONPATH has to be removed because webworker-threads (d3-hwschematic -> elk -> )
# has install time dependency on python2 and PYTHONPATH
# overrideds python2 import paths
if "PYTHONPATH" in my_env:
del my_env["PYTHONPATH"]
origCwd = os.getcwd()
try:
print("installing npm packages in ", TOP_DIR)
os.chdir(TOP_DIR)
check_call(["npm", "install"], env=my_env)
finally:
os.chdir(origCwd)
# from setuptools.command.install import install
def read(filename):
with open(filename) as fp:
return fp.read().strip()
class bdist_egg(_bdist_egg):
def run(self):
self.run_command('build_npm')
_bdist_egg.run(self)
class sdist_with_npm(_sdist):
def run(self):
self.run_command('build_npm')
_sdist.run(self)
class build_npm(Command):
description = 'build javascript and CSS from NPM packages'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
has_npm = npm_installation_check()
if has_npm:
run_npm_install()
else:
print("Warning: npm not installed using pre-builded js files!",
file=sys.stderr)
"""
Download npm packages required by package.json and extract required
files from them
"""
for js in JS_FILES:
downloaded_js_name = os.path.join(TOP_DIR, js)
installed_js_name = os.path.join(TOP_DIR, "sphinx_hwt", "html", js)
if has_npm:
assert os.path.exists(downloaded_js_name), downloaded_js_name
os.makedirs(os.path.dirname(installed_js_name), exist_ok=True)
copyfile(downloaded_js_name, installed_js_name)
print("copy generated from NPM packages", installed_js_name)
else:
if os.path.exists(installed_js_name):
print("using pre-builded", installed_js_name)
else:
raise Exception("Can not find npm,"
" which is required for the installation "
"and this is package has not js pre-builded")
class build(_build):
sub_commands = [('build_npm', None)] + _build.sub_commands
class clean(_clean):
def run(self):
root = dirname(__file__)
for d in ["node_modules", "sphinx_hwt/html/node_modules",
"sphinx_hwt.egg-info", "dist", "build"]:
rmtree(path.join(root, d), ignore_errors=True)
_clean.run(self)
setup(
name='sphinx-hwt',
version='2.7',
author="Michal Orsak",
author_email="Nic30original@gmail.com",
description="Sphinx extension to produce interactive schematic for hardware written in HWT",
license='BSD-3-Clause',
keywords='sphinx documentation HWT FPGA hardware VHDL System Verilog schematic wave',
url='https://github.com/Nic30/sphinx-hwt',
packages=find_packages(exclude=['tests*']),
long_description=read('README.md'),
long_description_content_type="text/markdown",
install_requires=[
'sphinx>=4.0.2', # base sphinx doc generator
'hwtGraph>=2.1', # converts HWT HwModules to schematics
],
classifiers=[
"Development Status :: 4 - Beta",
'Environment :: Plugins',
'Framework :: Sphinx :: Extension',
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
'Natural Language :: English',
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
"Topic :: System :: Hardware",
"Topic :: Utilities",
'Topic :: Scientific/Engineering :: Visualization',
],
cmdclass={
'build': build, # clean generated files
'bdist_egg': bdist_egg,
'build_npm': build_npm, # generate js files from npm packages
'sdist': sdist_with_npm,
'clean': clean,
},
package_data={
'sphinx_hwt': ['*.html', '*.css', "*.js"]
},
include_package_data=True,
zip_safe=False,
)