mygpoclient 1.10
[gpodder.git] / setup.py
bloba875e3ccf70c6ea01edeed30235b37fbc6bba869
1 #!/usr/bin/env python3
4 # gPodder - A media aggregator and podcast client
5 # Copyright (c) 2005-2018 The gPodder Team
7 # gPodder is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # gPodder is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import os
22 import re
23 import sys
25 from setuptools import setup
27 installing = ('install' in sys.argv and '--help' not in sys.argv)
29 # setuptools depends on setup.py being executed from the same dir.
30 # Most of our custom commands work either way, but this makes
31 # it work in all cases.
32 os.chdir(os.path.dirname(os.path.realpath(__file__)))
35 class MissingFile(BaseException):
36 pass
39 def info(message, item=None):
40 print('=>', message, item if item is not None else '')
43 def find_data_files(uis, scripts):
44 # Support for installing only a subset of translations
45 linguas = os.environ.get('LINGUAS', None)
46 if linguas is not None:
47 linguas = linguas.split()
48 info('Selected languages (from $LINGUAS):', linguas)
50 for dirpath, dirnames, filenames in os.walk('share'):
51 if not filenames:
52 continue
54 # Skip data folders if we don't want the corresponding UI
55 share_gpodder_ui = os.path.join('share', 'gpodder', 'ui')
56 if uis is not None and dirpath.startswith(share_gpodder_ui):
57 dirparts = dirpath.split(os.sep)
58 if not any(part in uis for part in dirparts):
59 info('Skipping folder:', dirpath)
60 continue
62 # Skip translations if $LINGUAS is set
63 share_locale = os.path.join('share', 'locale')
64 if linguas is not None and dirpath.startswith(share_locale):
65 _, _, language, _ = dirpath.split(os.sep, 3)
66 if language not in linguas:
67 info('Skipping translation:', language)
68 continue
70 # Skip desktop stuff if we don't have any UIs requiring it
71 skip_folder = False
72 uis_requiring_freedesktop = ('gtk',)
73 freedesktop_folders = ('applications', 'dbus-1', 'icons', 'metainfo')
74 for folder in freedesktop_folders:
75 share_folder = os.path.join('share', folder)
76 if dirpath.startswith(share_folder) and uis is not None:
77 if not any(ui in uis_requiring_freedesktop for ui in uis):
78 info('Skipping freedesktop.org folder:', dirpath)
79 skip_folder = True
80 break
82 if skip_folder:
83 continue
85 # Skip manpages if their scripts are not going to be installed
86 share_man = os.path.join('share', 'man')
87 if dirpath.startswith(share_man):
88 def have_script(filename):
89 if not filename.endswith('.1'):
90 return True
92 basename, _ = os.path.splitext(filename)
93 result = any(os.path.basename(s) == basename for s in scripts)
94 if not result:
95 info('Skipping manpage without script:', filename)
96 return result
97 filenames = list(filter(have_script, filenames))
99 def convert_filename(filename):
100 filename = os.path.join(dirpath, filename)
102 # Skip header files generated by "make messages"
103 if filename.endswith('.h'):
104 return None
106 # Skip .in files, but check if their target exist
107 if filename.endswith('.in'):
108 filename = filename[:-3]
109 if installing and not os.path.exists(filename):
110 raise MissingFile(filename)
111 return None
113 return filename
115 filenames = [_f for _f in map(convert_filename, filenames) if _f]
116 if filenames:
117 # Some distros/ports install manpages into $PREFIX/man instead
118 # of $PREFIX/share/man (e.g. FreeBSD). To allow this, we strip
119 # the "share/" part if the variable GPODDER_MANPATH_NO_SHARE is
120 # set to any value in the environment.
121 if dirpath.startswith(share_man):
122 if 'GPODDER_MANPATH_NO_SHARE' in os.environ:
123 dirpath = dirpath.replace(share_man, 'man')
125 yield (dirpath, filenames)
128 def find_packages(uis):
129 src_gpodder = os.path.join('src', 'gpodder')
130 for dirpath, dirnames, filenames in os.walk(src_gpodder):
131 if '__init__.py' not in filenames:
132 continue
134 skip = False
135 dirparts = dirpath.split(os.sep)
136 dirparts.pop(0)
137 package = '.'.join(dirparts)
139 # Extract all parts of the package name ending in "ui"
140 ui_parts = [p for p in dirparts if p.endswith('ui')]
141 if uis is not None and ui_parts:
142 # Strip the trailing "ui", e.g. "gtkui" -> "gtk"
143 folder_uis = [p[:-2] for p in ui_parts]
144 for folder_ui in folder_uis:
145 if folder_ui not in uis:
146 info('Skipping package:', package)
147 skip = True
148 break
150 if not skip:
151 yield package
154 def find_scripts(uis):
155 # Functions for scripts to check if they should be installed
156 file_checks = {
157 'gpo': lambda uis: 'cli' in uis,
158 'gpodder': lambda uis: any(ui in uis for ui in ('gtk',)),
161 for dirpath, dirnames, filenames in os.walk('bin'):
162 for filename in filenames:
163 # If we have a set of uis, check if we can skip this file
164 if uis is not None and filename in file_checks:
165 if not file_checks[filename](uis):
166 info('Skipping script:', filename)
167 continue
169 yield os.path.join(dirpath, filename)
172 # Recognized UIs: cli, gtk (default: install all UIs)
173 uis = os.environ.get('GPODDER_INSTALL_UIS', None)
174 if uis is not None:
175 uis = uis.split()
177 info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis)
180 try:
181 packages = sorted(find_packages(uis))
182 scripts = sorted(find_scripts(uis))
183 data_files = sorted(find_data_files(uis, scripts))
184 except MissingFile as mf:
185 print("""
186 Missing file: %s
188 If you want to install, use "make install" instead of using
189 setup.py directly. See the README file for more information.
190 """ % mf, file=sys.stderr)
191 sys.exit(1)
194 setup(
195 package_dir={'': 'src'},
196 packages=packages,
197 scripts=scripts,
198 data_files=data_files,