-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
187 lines (163 loc) · 5.75 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
179
180
181
182
183
184
185
186
187
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function)
from builtins import *
import os
import glob
import shutil
import tarfile
import zipfile
from setuptools import setup, Command
import io
import sys
data_files = [
(os.path.relpath(os.path.dirname(x), "res"), [x])
for x in glob.glob("res/**")
]
def determine_dir(name, filename, defaults={}):
if not os.path.exists(".paths"):
os.mkdir(".paths")
filepath = os.path.join(".paths", filename)
if os.path.exists(filepath):
with io.open(filepath, 'r', encoding="UTF-8") as f:
return f.read()
default = defaults.get(sys.platform, "")
msg = "Please specify the {} or press enter to use the default.\n[{}]"
dirname = input(msg.format(name, default))
if len(dirname) == 0:
dirname = default
msg = "Your path configuration will be saved in the file {} " \
+ "for further use."
print(msg.format(filepath))
with io.open(filepath, 'w', encoding="UTF-8") as f:
f.write(dirname)
return dirname
def determine_ext():
return determine_dir("inkscape extension directory", "ext.txt", defaults={
"win32": r'C:\Program Files\Inkscape\share\extensions',
"cygwin": r'C:\Program Files\Inkscape\share\extensions',
"linux": r'/usr/share/inkscape/extensions/',
})
def determine_user_ext(forcedefault=False):
defaults = {
"win32": os.path.expanduser(
r'~\AppData\Roaming\inkscape\extensions'
),
"cygwin": os.path.expanduser(
r'~\AppData\Roaming\inkscape\extensions'
),
"linux": os.path.expanduser(
r'~/.config/inkscape/extensions/'
)
}
if sys.platform.startswith("linux"):
# prior to python 3.3, sys.platform was "linux2", "linux3", and so on
default = defaults.get("linux")
else:
default = defaults.get(sys.platform, "")
if forcedefault:
return default
return determine_dir(
"inkscape user extension directory", "user_ext.txt", defaults=defaults
)
# NOTE: if we want to use PEP517, there is currently no way to run these
# custom commands directly via pip due to
# https://github.com/pypa/pip/issues/2677
class BdistInkscape(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
outfile = "{}-{}".format(
self.distribution.metadata.get_name(),
self.distribution.metadata.get_version()
)
files = []
files.extend([
(f, os.path.relpath(f, "src"))
for f in glob.glob("src/**")
if ".egg-info" not in f
])
files.extend([
(f, os.path.relpath(f, "res"))
for f in glob.glob("res/**")
])
with tarfile.open("dist/{}.tar.gz".format(outfile), "w:gz") as tf:
for f, aname in files:
tf.add(f, arcname=aname)
with zipfile.ZipFile("dist/{}.zip".format(outfile), "w") as zf:
for f, aname in files:
zf.write(f, arcname=aname)
class InstallToExtensionDir(Command):
user_options = [(
'defaultext', None,
'If True, default user ext directory will be used without prompt'
)]
def initialize_options(self):
self.defaultext = False
def finalize_options(self):
if self.defaultext == 1:
self.defaultext = True
def run(self):
uext = determine_user_ext(forcedefault=self.defaultext)
if not os.path.exists(uext):
os.makedirs(uext)
# copy source files to extension dir
for f in [x for x in glob.glob("src/**") if ".egg-info" not in x]:
src = f
dst = os.path.join(uext, os.path.relpath(f, "src"))
print("copying %s -> %s" % (src, dst))
shutil.copyfile(src, dst)
# copy .inx file(s) to extension dir
for f in glob.glob("res/**"):
src = f
dst = os.path.join(uext, os.path.relpath(f, "res"))
print("copying %s -> %s" % (src, dst))
shutil.copyfile(src, dst)
with io.open("README.rst", "r", encoding="utf-8") as f:
readme = f.read()
version = '0.2.1'
setup(
name='MoNK',
package_dir={'': 'src'},
py_modules=['svg2modelica'],
version=version,
platforms="any",
license="MIT",
description='Inkscape plugin to save document as Modelica annotation.',
long_description=readme,
author='Christopher Schölzel',
author_email='[email protected]',
url='https://github.com/THM-MoTE/MoNK',
download_url='https://github.com/THM-MoTE/MoNK/tarball/v' + version,
keywords=[
'Modelica', 'inkscape', 'inkscape extension', 'Modelica annotation'],
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7'
],
install_requires=[
'setuptools', # ensures that we can run `python setup.py install_ink`
# after we installed with `pip install .` using PEP517
'future',
'lxml',
'numpy==1.16.4; python_version < "3.0.0"',
'numpy; python_version >= "3.6.0"',
'pathlib; python_version < "3.3.0"' # for python < 3.3
],
cmdclass={
'install_ink': InstallToExtensionDir,
'bdist_ink': BdistInkscape
},
data_files=data_files,
include_package_data=True
)