printrun-src/setup.py

changeset 45
c82943fb205f
parent 15
0bbb006204fc
equal deleted inserted replaced
44:310be640a303 45:c82943fb205f
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 2
3 # This file is part of the Printrun suite. 3 # This file is part of the Printrun suite.
4 # 4 #
5 # Printrun is free software: you can redistribute it and/or modify 5 # Printrun is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by 6 # it under the terms of the GNU General Public License as published by
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Printrun. If not, see <http://www.gnu.org/licenses/>. 16 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import sys 18 import ast
19 import os 19 import glob
20 from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH 20 from setuptools import setup
21 from distutils.core import setup 21 from setuptools import find_packages
22 from distutils.command.install import install as _install 22
23 from distutils.command.install_data import install_data as _install_data
24 try: 23 try:
25 from Cython.Build import cythonize 24 from Cython.Build import cythonize
26 extensions = cythonize("printrun/gcoder_line.pyx") 25 extensions = cythonize("printrun/gcoder_line.pyx")
27 from Cython.Distutils import build_ext 26 from Cython.Distutils import build_ext
28 except ImportError, e: 27 except ImportError as e:
29 print "WARNING: Failed to cythonize: %s" % e 28 print("WARNING: Failed to cythonize: %s" % e)
30 # Debug helper: uncomment these: 29 # Debug helper: uncomment these:
31 # import traceback 30 # import traceback
32 # traceback.print_exc() 31 # traceback.print_exc()
33 extensions = None 32 extensions = None
34 build_ext = None 33 build_ext = None
35 34
36 from printrun.printcore import __version__ as printcore_version
37 35
38 INSTALLED_FILES = "installed_files" 36 with open('README.md') as f:
37 long_description = f.read()
39 38
40 class install (_install): 39 with open('requirements.txt') as f:
40 install_requires = f.readlines()
41 41
42 def run(self): 42 with open('printrun/printcore.py') as f:
43 _install.run(self) 43 for line in f.readlines():
44 outputs = self.get_outputs() 44 if line.startswith("__version__"):
45 length = 0 45 __version__ = ast.literal_eval(line.split("=")[1].strip())
46 if self.root:
47 length += len(self.root)
48 if self.prefix:
49 length += len(self.prefix)
50 if length:
51 for counter in xrange(len(outputs)):
52 outputs[counter] = outputs[counter][length:]
53 data = "\n".join(outputs)
54 try:
55 file = open(INSTALLED_FILES, "w")
56 except:
57 self.warn("Could not write installed files list %s" %
58 INSTALLED_FILES)
59 return
60 file.write(data)
61 file.close()
62 46
63 class install_data(_install_data):
64 47
65 def run(self): 48 def multiglob(*globs):
66 def chmod_data_file(file): 49 paths = []
67 try: 50 for g in globs:
68 os.chmod(file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) 51 paths.extend(glob.glob(g))
69 except: 52 return paths
70 self.warn("Could not chmod data file %s" % file)
71 _install_data.run(self)
72 map(chmod_data_file, self.get_outputs())
73 53
74 class uninstall(_install):
75 54
76 def run(self): 55 data_files = [
77 try: 56 ('share/pixmaps', multiglob('*.png')),
78 file = open(INSTALLED_FILES, "r") 57 ('share/applications', multiglob('*.desktop')),
79 except: 58 ('share/metainfo', multiglob('*.appdata.xml')),
80 self.warn("Could not read installed files list %s" % 59 ('share/pronterface/images', multiglob('images/*.png',
81 INSTALLED_FILES) 60 'images/*.svg')),
82 return 61 ]
83 files = file.readlines()
84 file.close()
85 prepend = ""
86 if self.root:
87 prepend += self.root
88 if self.prefix:
89 prepend += self.prefix
90 if len(prepend):
91 for counter in xrange(len(files)):
92 files[counter] = prepend + files[counter].rstrip()
93 for file in files:
94 print "Uninstalling", file
95 try:
96 os.unlink(file)
97 except:
98 self.warn("Could not remove file %s" % file)
99 62
100 ops = ("install", "build", "sdist", "uninstall", "clean", "build_ext") 63 for locale in glob.glob('locale/*/LC_MESSAGES/'):
64 data_files.append((f'share/{locale}', glob.glob(f'{locale}/*.mo')))
101 65
102 if len(sys.argv) < 2 or sys.argv[1] not in ops:
103 print "Please specify operation : %s" % " | ".join(ops)
104 raise SystemExit
105 66
106 prefix = None 67 setup(
107 if len(sys.argv) > 2: 68 name="Printrun",
108 i = 0 69 version=__version__,
109 for o in sys.argv: 70 description="Host software for 3D printers",
110 if o.startswith("--prefix"): 71 author="Kliment Yanev, Guillaume Seguin and others",
111 if o == "--prefix": 72 long_description=long_description,
112 if len(sys.argv) >= i: 73 long_description_content_type="text/markdown",
113 prefix = sys.argv[i + 1] 74 url="http://github.com/kliment/Printrun/",
114 sys.argv.remove(prefix) 75 license="GPLv3+",
115 elif o.startswith("--prefix=") and len(o[9:]): 76 data_files=data_files,
116 prefix = o[9:] 77 packages=find_packages(),
117 sys.argv.remove(o) 78 scripts=["pronsole.py", "pronterface.py", "plater.py", "printcore.py"],
118 i += 1 79 ext_modules=extensions,
119 if not prefix and "PREFIX" in os.environ: 80 python_requires=">=3.6",
120 prefix = os.environ["PREFIX"] 81 install_requires=install_requires,
121 if not prefix or not len(prefix): 82 setup_requires=["Cython"],
122 prefix = sys.prefix 83 classifiers=[
123 84 "Environment :: X11 Applications :: GTK",
124 if sys.argv[1] in("install", "uninstall") and len(prefix): 85 "Intended Audience :: End Users/Desktop",
125 sys.argv += ["--prefix", prefix] 86 "Intended Audience :: Manufacturing",
126 87 "Intended Audience :: Science/Research",
127 target_images_path = "share/pronterface/images/" 88 "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
128 data_files = [('share/pixmaps', ['pronterface.png', 'plater.png', 'pronsole.png']), 89 "Operating System :: MacOS :: MacOS X",
129 ('share/applications', ['pronterface.desktop', 'pronsole.desktop', 'plater.desktop']), 90 "Operating System :: Microsoft :: Windows",
130 ('share/appdata', ['pronterface.appdata.xml', 'pronsole.appdata.xml', 'plater.appdata.xml'])] 91 "Operating System :: POSIX :: Linux",
131 92 "Programming Language :: Python :: 3 :: Only",
132 for basedir, subdirs, files in os.walk("images"): 93 "Programming Language :: Python :: 3.6",
133 images = [] 94 "Programming Language :: Python :: 3.7",
134 for filename in files: 95 "Programming Language :: Python :: 3.8",
135 if filename.find(".svg") or filename.find(".png"): 96 "Topic :: Printing",
136 file_path = os.path.join(basedir, filename) 97 ],
137 images.append(file_path) 98 zip_safe=False,
138 data_files.append((target_images_path + basedir[len("images/"):], images)) 99 )
139
140 for basedir, subdirs, files in os.walk("locale"):
141 if not basedir.endswith("LC_MESSAGES"):
142 continue
143 destpath = os.path.join("share", "pronterface", basedir)
144 files = filter(lambda x: x.endswith(".mo"), files)
145 files = map(lambda x: os.path.join(basedir, x), files)
146 data_files.append((destpath, files))
147
148 extra_data_dirs = ["css"]
149 for extra_data_dir in extra_data_dirs:
150 for basedir, subdirs, files in os.walk(extra_data_dir):
151 files = map(lambda x: os.path.join(basedir, x), files)
152 destpath = os.path.join("share", "pronterface", basedir)
153 data_files.append((destpath, files))
154
155 cmdclass = {"uninstall": uninstall,
156 "install": install,
157 "install_data": install_data}
158 if build_ext:
159 cmdclass['build_ext'] = build_ext
160
161 setup(name = "Printrun",
162 version = printcore_version,
163 description = "Host software for 3D printers",
164 author = "Kliment Yanev",
165 url = "http://github.com/kliment/Printrun/",
166 license = "GPLv3",
167 data_files = data_files,
168 packages = ["printrun", "printrun.gl", "printrun.gl.libtatlin", "printrun.gui", "printrun.power"],
169 scripts = ["pronsole.py", "pronterface.py", "plater.py", "printcore.py"],
170 cmdclass = cmdclass,
171 ext_modules = extensions,
172 )

mercurial