Skip to content

Commit 09a247d

Browse files
committed
Don't require dependencies to be installed when clean target is executed.
1 parent 5ab32f0 commit 09a247d

File tree

1 file changed

+133
-130
lines changed

1 file changed

+133
-130
lines changed

setup.py

Lines changed: 133 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -114,143 +114,146 @@ def run(self):
114114
mason_build = False
115115

116116

117+
extra_comp_args = []
117118
linkflags = []
118-
lib_path = os.path.join(check_output([mapnik_config, '--prefix']),'lib')
119-
linkflags.extend(check_output([mapnik_config, '--libs']).split(' '))
120-
linkflags.extend(check_output([mapnik_config, '--ldflags']).split(' '))
121-
linkflags.extend(check_output([mapnik_config, '--dep-libs']).split(' '))
122-
linkflags.extend([
123-
'-lmapnik-wkt',
124-
'-lmapnik-json',
125-
] + ['-l%s' % i for i in get_boost_library_names()])
126-
127-
# Dynamically make the mapnik/paths.py file
128-
f_paths = open('mapnik/paths.py', 'w')
129-
f_paths.write('import os\n')
130-
f_paths.write('\n')
131-
132-
input_plugin_path = check_output([mapnik_config, '--input-plugins'])
133-
font_path = check_output([mapnik_config, '--fonts'])
134-
135-
if mason_build:
136-
try:
137-
if sys.platform == 'darwin':
138-
base_f = 'libmapnik.dylib'
139-
else:
140-
base_f = 'libmapnik.so'
141-
f = os.path.join(lib_path, base_f)
142-
if not os.path.exists(os.path.join('mapnik', 'lib')):
143-
os.makedirs(os.path.join('mapnik', 'lib'))
144-
shutil.copyfile(f, os.path.join('mapnik', 'lib', base_f))
145-
except shutil.Error:
146-
pass
147-
input_plugin_files = os.listdir(input_plugin_path)
148-
input_plugin_files = [os.path.join(
149-
input_plugin_path, f) for f in input_plugin_files]
150-
if not os.path.exists(os.path.join('mapnik', 'lib', 'mapnik', 'input')):
151-
os.makedirs(os.path.join('mapnik', 'lib', 'mapnik', 'input'))
152-
for f in input_plugin_files:
153-
try:
154-
shutil.copyfile(f, os.path.join(
155-
'mapnik', 'lib', 'mapnik', 'input', os.path.basename(f)))
156-
except shutil.Error:
157-
pass
158-
font_files = os.listdir(font_path)
159-
font_files = [os.path.join(font_path, f) for f in font_files]
160-
if not os.path.exists(os.path.join('mapnik', 'lib', 'mapnik', 'fonts')):
161-
os.makedirs(os.path.join('mapnik', 'lib', 'mapnik', 'fonts'))
162-
for f in font_files:
119+
120+
if 'clean' not in sys.argv:
121+
lib_path = os.path.join(check_output([mapnik_config, '--prefix']),'lib')
122+
linkflags.extend(check_output([mapnik_config, '--libs']).split(' '))
123+
linkflags.extend(check_output([mapnik_config, '--ldflags']).split(' '))
124+
linkflags.extend(check_output([mapnik_config, '--dep-libs']).split(' '))
125+
linkflags.extend([
126+
'-lmapnik-wkt',
127+
'-lmapnik-json',
128+
] + ['-l%s' % i for i in get_boost_library_names()])
129+
130+
# Dynamically make the mapnik/paths.py file
131+
f_paths = open('mapnik/paths.py', 'w')
132+
f_paths.write('import os\n')
133+
f_paths.write('\n')
134+
135+
input_plugin_path = check_output([mapnik_config, '--input-plugins'])
136+
font_path = check_output([mapnik_config, '--fonts'])
137+
138+
if mason_build:
163139
try:
164-
shutil.copyfile(f, os.path.join(
165-
'mapnik', 'lib', 'mapnik', 'fonts', os.path.basename(f)))
140+
if sys.platform == 'darwin':
141+
base_f = 'libmapnik.dylib'
142+
else:
143+
base_f = 'libmapnik.so'
144+
f = os.path.join(lib_path, base_f)
145+
if not os.path.exists(os.path.join('mapnik', 'lib')):
146+
os.makedirs(os.path.join('mapnik', 'lib'))
147+
shutil.copyfile(f, os.path.join('mapnik', 'lib', base_f))
166148
except shutil.Error:
167149
pass
168-
f_paths.write(
169-
'mapniklibpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")\n')
170-
f_paths.write("inputpluginspath = os.path.join(mapniklibpath, 'mapnik', 'input')\n")
171-
f_paths.write("fontscollectionpath = os.path.join(mapniklibpath, 'mapnik', 'fonts')\n")
172-
f_paths.write(
173-
"__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n")
174-
f_paths.close()
175-
else:
176-
if os.environ.get('LIB_DIR_NAME'):
177-
mapnik_lib_path = lib_path + os.environ.get('LIB_DIR_NAME')
150+
input_plugin_files = os.listdir(input_plugin_path)
151+
input_plugin_files = [os.path.join(
152+
input_plugin_path, f) for f in input_plugin_files]
153+
if not os.path.exists(os.path.join('mapnik', 'lib', 'mapnik', 'input')):
154+
os.makedirs(os.path.join('mapnik', 'lib', 'mapnik', 'input'))
155+
for f in input_plugin_files:
156+
try:
157+
shutil.copyfile(f, os.path.join(
158+
'mapnik', 'lib', 'mapnik', 'input', os.path.basename(f)))
159+
except shutil.Error:
160+
pass
161+
font_files = os.listdir(font_path)
162+
font_files = [os.path.join(font_path, f) for f in font_files]
163+
if not os.path.exists(os.path.join('mapnik', 'lib', 'mapnik', 'fonts')):
164+
os.makedirs(os.path.join('mapnik', 'lib', 'mapnik', 'fonts'))
165+
for f in font_files:
166+
try:
167+
shutil.copyfile(f, os.path.join(
168+
'mapnik', 'lib', 'mapnik', 'fonts', os.path.basename(f)))
169+
except shutil.Error:
170+
pass
171+
f_paths.write(
172+
'mapniklibpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")\n')
173+
f_paths.write("inputpluginspath = os.path.join(mapniklibpath, 'mapnik', 'input')\n")
174+
f_paths.write("fontscollectionpath = os.path.join(mapniklibpath, 'mapnik', 'fonts')\n")
175+
f_paths.write(
176+
"__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n")
177+
f_paths.close()
178178
else:
179-
mapnik_lib_path = lib_path + "/mapnik"
180-
f_paths.write("mapniklibpath = '{path}'\n".format(path=mapnik_lib_path))
181-
f_paths.write('mapniklibpath = os.path.normpath(mapniklibpath)\n')
182-
f_paths.write(
183-
"inputpluginspath = '{path}'\n".format(path=input_plugin_path))
184-
f_paths.write(
185-
"fontscollectionpath = '{path}'\n".format(path=font_path))
186-
f_paths.write(
187-
"__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n")
188-
f_paths.close()
189-
190-
191-
if mason_build:
192-
193-
share_dir = 'share'
194-
195-
for dep in ['icu','gdal','proj']:
196-
share_path = os.path.join('mapnik', share_dir, dep)
197-
if not os.path.exists(share_path):
198-
os.makedirs(share_path)
199-
200-
icu_path = 'mason_packages/.link/share/icu/*/*.dat'
201-
icu_files = glob.glob(icu_path)
202-
if len(icu_files) != 1:
203-
raise Exception("Failed to find icu dat file at "+ icu_path)
204-
for f in icu_files:
205-
shutil.copyfile(f, os.path.join(
206-
'mapnik', share_dir, 'icu', os.path.basename(f)))
207-
208-
gdal_path = 'mason_packages/.link/share/gdal/'
209-
gdal_files = os.listdir(gdal_path)
210-
gdal_files = [os.path.join(gdal_path, f) for f in gdal_files]
211-
for f in gdal_files:
212-
try:
179+
if os.environ.get('LIB_DIR_NAME'):
180+
mapnik_lib_path = lib_path + os.environ.get('LIB_DIR_NAME')
181+
else:
182+
mapnik_lib_path = lib_path + "/mapnik"
183+
f_paths.write("mapniklibpath = '{path}'\n".format(path=mapnik_lib_path))
184+
f_paths.write('mapniklibpath = os.path.normpath(mapniklibpath)\n')
185+
f_paths.write(
186+
"inputpluginspath = '{path}'\n".format(path=input_plugin_path))
187+
f_paths.write(
188+
"fontscollectionpath = '{path}'\n".format(path=font_path))
189+
f_paths.write(
190+
"__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n")
191+
f_paths.close()
192+
193+
194+
if mason_build:
195+
196+
share_dir = 'share'
197+
198+
for dep in ['icu','gdal','proj']:
199+
share_path = os.path.join('mapnik', share_dir, dep)
200+
if not os.path.exists(share_path):
201+
os.makedirs(share_path)
202+
203+
icu_path = 'mason_packages/.link/share/icu/*/*.dat'
204+
icu_files = glob.glob(icu_path)
205+
if len(icu_files) != 1:
206+
raise Exception("Failed to find icu dat file at "+ icu_path)
207+
for f in icu_files:
213208
shutil.copyfile(f, os.path.join(
214-
'mapnik', share_dir, 'gdal', os.path.basename(f)))
215-
except shutil.Error:
216-
pass
217-
218-
proj_path = 'mason_packages/.link/share/proj/'
219-
proj_files = os.listdir(proj_path)
220-
proj_files = [os.path.join(proj_path, f) for f in proj_files]
221-
for f in proj_files:
209+
'mapnik', share_dir, 'icu', os.path.basename(f)))
210+
211+
gdal_path = 'mason_packages/.link/share/gdal/'
212+
gdal_files = os.listdir(gdal_path)
213+
gdal_files = [os.path.join(gdal_path, f) for f in gdal_files]
214+
for f in gdal_files:
215+
try:
216+
shutil.copyfile(f, os.path.join(
217+
'mapnik', share_dir, 'gdal', os.path.basename(f)))
218+
except shutil.Error:
219+
pass
220+
221+
proj_path = 'mason_packages/.link/share/proj/'
222+
proj_files = os.listdir(proj_path)
223+
proj_files = [os.path.join(proj_path, f) for f in proj_files]
224+
for f in proj_files:
225+
try:
226+
shutil.copyfile(f, os.path.join(
227+
'mapnik', share_dir, 'proj', os.path.basename(f)))
228+
except shutil.Error:
229+
pass
230+
231+
extra_comp_args = check_output([mapnik_config, '--cflags']).split(' ')
232+
233+
extra_comp_args = list(filter(lambda arg: arg != "-fvisibility=hidden", extra_comp_args))
234+
235+
if os.environ.get("PYCAIRO", "false") == "true":
222236
try:
223-
shutil.copyfile(f, os.path.join(
224-
'mapnik', share_dir, 'proj', os.path.basename(f)))
225-
except shutil.Error:
226-
pass
227-
228-
extra_comp_args = check_output([mapnik_config, '--cflags']).split(' ')
229-
230-
extra_comp_args = list(filter(lambda arg: arg != "-fvisibility=hidden", extra_comp_args))
231-
232-
if os.environ.get("PYCAIRO", "false") == "true":
233-
try:
234-
extra_comp_args.append('-DHAVE_PYCAIRO')
235-
dist = pkg_resources.get_distribution('pycairo')
236-
print(dist.location)
237-
print("-I%s/cairo/include".format(dist.location))
238-
extra_comp_args.append("-I{0}/cairo/include".format(dist.location))
239-
#extra_comp_args.extend(check_output(["pkg-config", '--cflags', 'pycairo']).strip().split(' '))
240-
#linkflags.extend(check_output(["pkg-config", '--libs', 'pycairo']).strip().split(' '))
241-
except:
242-
raise Exception("Failed to find compiler options for pycairo")
243-
244-
if sys.platform == 'darwin':
245-
extra_comp_args.append('-mmacosx-version-min=13.0')
246-
# silence warning coming from boost python macros which
247-
# would is hard to silence via pragma
248-
extra_comp_args.append('-Wno-parentheses-equality')
249-
linkflags.append('-mmacosx-version-min=13.0')
250-
else:
251-
linkflags.append('-lrt')
252-
linkflags.append('-Wl,-z,origin')
253-
linkflags.append('-Wl,-rpath=$ORIGIN/lib')
237+
extra_comp_args.append('-DHAVE_PYCAIRO')
238+
dist = pkg_resources.get_distribution('pycairo')
239+
print(dist.location)
240+
print("-I%s/cairo/include".format(dist.location))
241+
extra_comp_args.append("-I{0}/cairo/include".format(dist.location))
242+
#extra_comp_args.extend(check_output(["pkg-config", '--cflags', 'pycairo']).strip().split(' '))
243+
#linkflags.extend(check_output(["pkg-config", '--libs', 'pycairo']).strip().split(' '))
244+
except:
245+
raise Exception("Failed to find compiler options for pycairo")
246+
247+
if sys.platform == 'darwin':
248+
extra_comp_args.append('-mmacosx-version-min=13.0')
249+
# silence warning coming from boost python macros which
250+
# would is hard to silence via pragma
251+
extra_comp_args.append('-Wno-parentheses-equality')
252+
linkflags.append('-mmacosx-version-min=13.0')
253+
else:
254+
linkflags.append('-lrt')
255+
linkflags.append('-Wl,-z,origin')
256+
linkflags.append('-Wl,-rpath=$ORIGIN/lib')
254257

255258
if os.environ.get("CC", False) == False:
256259
os.environ["CC"] = check_output([mapnik_config, '--cxx'])

0 commit comments

Comments
 (0)