forked from florianfesti/boxes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·90 lines (79 loc) · 3.9 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
#!/usr/bin/env python3
import glob
import os
import sys
from subprocess import check_output, CalledProcessError
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
class CustomBuildExtCommand(build_py):
"""Customized setuptools install command - prints a friendly greeting."""
def buildInkscapeExt(self):
os.system("{} {} {}".format(sys.executable, os.path.join("scripts", "boxes2inkscape"), "inkex"))
def updatePOT(self):
os.system("{} {} {}".format(sys.executable, os.path.join("scripts", "boxes2pot"), "po/boxes.py.pot"))
os.system("{} {}".format("xgettext -L Python -j --from-code=utf-8 -o po/boxes.py.pot", "boxes/*.py scripts/boxesserver scripts/boxes"))
def generate_mo_files(self):
pos = glob.glob("po/*.po")
for po in pos:
lang = po.split(os.sep)[1][:-3].replace("-", "_")
try:
os.makedirs(os.path.join("locale", lang, "LC_MESSAGES"))
except FileExistsError:
pass
os.system(f"msgfmt {po} -o locale/{lang}/LC_MESSAGES/boxes.py.mo")
self.distribution.data_files.append(
(os.path.join("share", "locale", lang, "LC_MESSAGES"),
[os.path.join("locale", lang, "LC_MESSAGES", "boxes.py.mo")]))
def run(self):
if self.distribution.data_files is None:
self.distribution.data_files = []
self.execute(self.updatePOT, ())
self.execute(self.generate_mo_files, ())
self.execute(self.buildInkscapeExt, ())
if 'CURRENTLY_PACKAGING' in os.environ:
# we are most probably building a Debian package
# let us define a simple path!
path="/usr/share/inkscape/extensions"
self.distribution.data_files.append((path, [i for i in glob.glob(os.path.join("inkex", "*.inx"))]))
self.distribution.data_files.append((path, ['scripts/boxes']))
self.distribution.data_files.append((path, ['scripts/boxes_proxy.py']))
else:
# we are surely not building a Debian package
# then here is the default behavior:
try:
path = check_output(["inkscape", "--system-data-directory"]).decode().strip()
path = os.path.join(path, "extensions")
if not os.access(path, os.W_OK): # Can we install globally
# Not tested on Windows and Mac
path = os.path.expanduser("~/.config/inkscape/extensions")
self.distribution.data_files.append((path, [i for i in glob.glob(os.path.join("inkex", "*.inx"))]))
self.distribution.data_files.append((path, ['scripts/boxes']))
self.distribution.data_files.append((path, ['scripts/boxes_proxy.py']))
except CalledProcessError:
pass # Inkscape is not installed
build_py.run(self)
setup(
name='boxes',
version='0.9',
description='Boxes generator for laser cutters',
author='Florian Festi',
author_email='[email protected]',
url='https://github.com/florianfesti/boxes',
packages=find_packages(),
python_requires='>=3.8',
install_requires=['affine>=2.0', 'markdown', 'shapely>=1.8.2', 'qrcode==7.3.1'],
scripts=['scripts/boxes', 'scripts/boxesserver'],
cmdclass={
'build_py': CustomBuildExtCommand,
},
classifiers=[ # https://pypi.python.org/pypi?%3Aaction=list_classifiers
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: Manufacturing",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Graphics :: Editors :: Vector-Based",
"Topic :: Scientific/Engineering",
],
keywords=["boxes", "box", "generator", "svg", "laser cutter"], )