forked from pdfarranger/pdfarranger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·128 lines (106 loc) · 4.01 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
#!/usr/bin/env python3
#
# pdfarranger - GTK+ based utility for splitting, rearrangement and
# modification of PDF documents.
# Copyright (C) 2008-2017 Konstantinos Poulios
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from setuptools import Command
from setuptools import setup
from setuptools import __version__ as setuptools_version
# support distros that ship old setuptools
setuptools_version = tuple(int(n) for n in setuptools_version.split('.')[:2])
if setuptools_version < (65, 2):
from distutils.command.build import build
else:
from setuptools.command.build import build
from os.path import join
import glob
import os
import subprocess
data_files = [
('share/applications', ['data/com.github.jeromerobert.pdfarranger.desktop']),
('share/pdfarranger', ['data/pdfarranger.ui', 'data/menu.ui']),
('share/man/man1', ['doc/pdfarranger.1']),
('share/metainfo', ['data/com.github.jeromerobert.pdfarranger.metainfo.xml']),
]
def _dir_to_data_files(src_dir, target_dir):
data_files = []
for root, _, files in os.walk(src_dir):
tgt = join(target_dir, os.path.relpath(root, src_dir))
if files:
data_files.append((tgt, [join(root, f) for f in files]))
return data_files
def _data_files(command):
"""Return the data_files of a command"""
data_files = command.distribution.data_files
if data_files is None:
data_files = []
command.distribution.data_files = data_files
return data_files
class build_i18n(Command):
description = "Build gettext .mo files"
def initialize_options(self):
self.build_base = None
def finalize_options(self):
self.set_undefined_options("build", ("build_base", "build_base"))
def run(self):
mo_dir = join(self.build_base, "mo")
for filename in glob.glob(join("po", "*.po")):
lang = os.path.basename(filename)[:-3]
lang_dir = join(self.build_base, "mo", lang, "LC_MESSAGES")
os.makedirs(lang_dir, exist_ok=True)
subprocess.check_call(
["msgfmt", filename, "-o", join(lang_dir, "pdfarranger.mo")]
)
data_files = _data_files(self)
data_files += _dir_to_data_files(mo_dir, join("share", "locale"))
class build_icons(Command):
description = "Ensure icons get installed"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
src_icons = join("data", "icons")
tgt_icons = join("share", "icons")
data_files = _data_files(self)
data_files += _dir_to_data_files(src_icons, tgt_icons)
build.sub_commands += [(x, lambda _: True) for x in ["build_i18n", "build_icons"]]
setup(
name='pdfarranger',
version='1.11.1',
author='Jerome Robert',
author_email='[email protected]',
description='A simple application for PDF Merging, Rearranging, and Splitting',
url='https://github.com/pdfarranger/pdfarranger',
license='GNU GPL-3',
packages=['pdfarranger'],
data_files=data_files,
zip_safe=False,
cmdclass={
"build": build,
"build_i18n": build_i18n,
"build_icons": build_icons,
},
entry_points={
'console_scripts': ['pdfarranger=pdfarranger.pdfarranger:main']
},
install_requires=['pikepdf>=6','python-dateutil>=2.4.0', 'packaging'],
extras_require={
'image': ['img2pdf>=0.3.4'],
},
)