|
1 | 1 | #! /usr/bin/env python3 |
2 | 2 |
|
3 | | -from pybind11.setup_helpers import Pybind11Extension, build_ext |
4 | | -from setuptools import setup, find_packages |
5 | | -import sys |
6 | | -import subprocess |
7 | 3 | import os |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | + |
| 7 | +from pybind11.setup_helpers import Pybind11Extension, build_ext |
| 8 | +from setuptools import find_packages, setup |
8 | 9 |
|
9 | | -mapnik_config = 'mapnik-config' |
10 | 10 |
|
11 | 11 | def check_output(args): |
12 | | - output = subprocess.check_output(args).decode() |
13 | | - return output.rstrip('\n') |
| 12 | + output = subprocess.check_output(args).decode() |
| 13 | + return output.rstrip("\n") |
| 14 | + |
14 | 15 |
|
15 | 16 | linkflags = [] |
16 | | -bin_path = os.path.join(check_output([mapnik_config, '--prefix']),'bin') |
17 | | -lib_path = os.path.join(check_output([mapnik_config, '--prefix']),'lib') |
18 | | -linkflags.extend(check_output([mapnik_config, '--libs']).split(' ')) |
19 | | -linkflags.extend(check_output([mapnik_config, '--ldflags']).split(' ')) |
20 | | -linkflags.extend(check_output([mapnik_config, '--dep-libs']).split(' ')) |
21 | | -linkflags.extend([ |
22 | | - '-lmapnik-wkt', |
23 | | - '-lmapnik-json', |
24 | | -]) |
| 17 | +lib_path = os.path.join( |
| 18 | + check_output(["pkg-config", "--variable=prefix", "libmapnik"]), "lib" |
| 19 | +) |
| 20 | +linkflags.extend(check_output(["pkg-config", "--libs", "libmapnik"]).split(" ")) |
25 | 21 |
|
26 | | -# Remove symlinks |
27 | | -if os.path.islink('packaging/mapnik/bin') : |
28 | | - os.unlink('packaging/mapnik/bin') |
29 | | -if os.path.islink('packaging/mapnik/lib') : |
30 | | - os.unlink('packaging/mapnik/lib') |
31 | 22 | # Dynamically make the mapnik/paths.py file |
32 | | -f_paths = open('packaging/mapnik/paths.py', 'w') |
33 | | -f_paths.write('import os\n') |
34 | | -f_paths.write('\n') |
| 23 | +f_paths = open("packaging/mapnik/paths.py", "w") |
| 24 | +f_paths.write("import os\n") |
| 25 | +f_paths.write("\n") |
35 | 26 |
|
36 | | -if os.environ.get('SYSTEM_MAPNIK'): |
37 | | - input_plugin_path = check_output([mapnik_config, '--input-plugins']) |
38 | | - font_path = check_output([mapnik_config, '--fonts']) |
39 | | - f_paths.write("mapniklibpath = '{path}'\n".format(path=lib_path)) |
40 | | - f_paths.write("inputpluginspath = '{path}'\n".format(path=input_plugin_path)) |
41 | | - f_paths.write("fontscollectionpath = '{path}'\n".format(path=font_path)) |
42 | | -else: |
43 | | - os.symlink(bin_path, 'packaging/mapnik/bin') |
44 | | - os.symlink(lib_path, 'packaging/mapnik/lib') |
45 | | - f_paths.write("mapniklibpath = os.path.join(os.path.dirname(__file__), 'lib')\n") |
46 | | - f_paths.write("inputpluginspath = os.path.join(os.path.dirname(__file__), 'lib/mapnik/input')\n") |
47 | | - f_paths.write("fontscollectionpath = os.path.join(os.path.dirname(__file__), 'lib/mapnik/fonts')\n") |
| 27 | +input_plugin_path = check_output(["pkg-config", "--variable=plugins_dir", "libmapnik"]) |
| 28 | +font_path = check_output(["pkg-config", "--variable=fonts_dir", "libmapnik"]) |
48 | 29 |
|
49 | | -f_paths.write("__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n") |
50 | | -f_paths.close() |
| 30 | +if os.environ.get("LIB_DIR_NAME"): |
| 31 | + mapnik_lib_path = lib_path + os.environ.get("LIB_DIR_NAME") |
| 32 | +else: |
| 33 | + mapnik_lib_path = lib_path + "/mapnik" |
| 34 | + f_paths.write("mapniklibpath = '{path}'\n".format(path=mapnik_lib_path)) |
| 35 | + f_paths.write("inputpluginspath = '{path}'\n".format(path=input_plugin_path)) |
| 36 | + f_paths.write("fontscollectionpath = '{path}'\n".format(path=font_path)) |
| 37 | + f_paths.write("__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n") |
| 38 | + f_paths.close() |
51 | 39 |
|
52 | | -extra_comp_args = check_output([mapnik_config, '--cflags']).split(' ') |
53 | | -extra_comp_args = list(filter(lambda arg: arg != "-fvisibility=hidden", extra_comp_args)) |
| 40 | +extra_comp_args = check_output(["pkg-config", "--cflags", "libmapnik"]).split(" ") |
| 41 | +extra_comp_args = list( |
| 42 | + filter(lambda arg: arg != "-fvisibility=hidden", extra_comp_args) |
| 43 | +) |
54 | 44 |
|
55 | | -if sys.platform == 'darwin': |
56 | | - pass |
| 45 | +if sys.platform == "darwin": |
| 46 | + pass |
57 | 47 | else: |
58 | | - linkflags.append('-lrt') |
59 | | - linkflags.append('-Wl,-z,origin') |
60 | | - linkflags.append('-Wl,-rpath=$ORIGIN/lib') |
| 48 | + linkflags.append("-lrt") |
| 49 | + linkflags.append("-Wl,-z,origin") |
| 50 | + linkflags.append("-Wl,-rpath=$ORIGIN/lib") |
61 | 51 |
|
| 52 | +extra_comp_args = list(filter(lambda arg: arg != "", extra_comp_args)) |
| 53 | +linkflags = list(filter(lambda arg: arg != "", linkflags)) |
62 | 54 |
|
63 | 55 | ext_modules = [ |
64 | | - Pybind11Extension( |
65 | | - "mapnik._mapnik", |
66 | | - [ |
67 | | - "src/mapnik_python.cpp", |
68 | | - "src/mapnik_layer.cpp", |
69 | | - "src/mapnik_query.cpp", |
70 | | - "src/mapnik_map.cpp", |
71 | | - "src/mapnik_color.cpp", |
72 | | - "src/mapnik_composite_modes.cpp", |
73 | | - "src/mapnik_coord.cpp", |
74 | | - "src/mapnik_envelope.cpp", |
75 | | - "src/mapnik_expression.cpp", |
76 | | - "src/mapnik_datasource.cpp", |
77 | | - "src/mapnik_datasource_cache.cpp", |
78 | | - "src/mapnik_gamma_method.cpp", |
79 | | - "src/mapnik_geometry.cpp", |
80 | | - "src/mapnik_feature.cpp", |
81 | | - "src/mapnik_featureset.cpp", |
82 | | - "src/mapnik_font_engine.cpp", |
83 | | - "src/mapnik_fontset.cpp", |
84 | | - "src/mapnik_grid.cpp", |
85 | | - "src/mapnik_grid_view.cpp", |
86 | | - "src/mapnik_image.cpp", |
87 | | - "src/mapnik_image_view.cpp", |
88 | | - "src/mapnik_projection.cpp", |
89 | | - "src/mapnik_proj_transform.cpp", |
90 | | - "src/mapnik_rule.cpp", |
91 | | - "src/mapnik_symbolizer.cpp", |
92 | | - "src/mapnik_debug_symbolizer.cpp", |
93 | | - "src/mapnik_markers_symbolizer.cpp", |
94 | | - "src/mapnik_polygon_symbolizer.cpp", |
95 | | - "src/mapnik_polygon_pattern_symbolizer.cpp", |
96 | | - "src/mapnik_line_symbolizer.cpp", |
97 | | - "src/mapnik_line_pattern_symbolizer.cpp", |
98 | | - "src/mapnik_point_symbolizer.cpp", |
99 | | - "src/mapnik_raster_symbolizer.cpp", |
100 | | - "src/mapnik_scaling_method.cpp", |
101 | | - "src/mapnik_style.cpp", |
102 | | - "src/mapnik_logger.cpp", |
103 | | - "src/mapnik_placement_finder.cpp", |
104 | | - "src/mapnik_text_symbolizer.cpp", |
105 | | - "src/mapnik_palette.cpp", |
106 | | - "src/mapnik_parameters.cpp", |
107 | | - "src/python_grid_utils.cpp", |
108 | | - "src/mapnik_raster_colorizer.cpp", |
109 | | - "src/mapnik_label_collision_detector.cpp", |
110 | | - "src/mapnik_dot_symbolizer.cpp", |
111 | | - "src/mapnik_building_symbolizer.cpp", |
112 | | - "src/mapnik_shield_symbolizer.cpp", |
113 | | - "src/mapnik_group_symbolizer.cpp" |
114 | | - ], |
115 | | - extra_compile_args=extra_comp_args, |
116 | | - extra_link_args=linkflags, |
117 | | - ) |
| 56 | + Pybind11Extension( |
| 57 | + "mapnik._mapnik", |
| 58 | + [ |
| 59 | + "src/mapnik_python.cpp", |
| 60 | + "src/mapnik_layer.cpp", |
| 61 | + "src/mapnik_query.cpp", |
| 62 | + "src/mapnik_map.cpp", |
| 63 | + "src/mapnik_color.cpp", |
| 64 | + "src/mapnik_composite_modes.cpp", |
| 65 | + "src/mapnik_coord.cpp", |
| 66 | + "src/mapnik_envelope.cpp", |
| 67 | + "src/mapnik_expression.cpp", |
| 68 | + "src/mapnik_datasource.cpp", |
| 69 | + "src/mapnik_datasource_cache.cpp", |
| 70 | + "src/mapnik_gamma_method.cpp", |
| 71 | + "src/mapnik_geometry.cpp", |
| 72 | + "src/mapnik_feature.cpp", |
| 73 | + "src/mapnik_featureset.cpp", |
| 74 | + "src/mapnik_font_engine.cpp", |
| 75 | + "src/mapnik_fontset.cpp", |
| 76 | + "src/mapnik_grid.cpp", |
| 77 | + "src/mapnik_grid_view.cpp", |
| 78 | + "src/mapnik_image.cpp", |
| 79 | + "src/mapnik_image_view.cpp", |
| 80 | + "src/mapnik_projection.cpp", |
| 81 | + "src/mapnik_proj_transform.cpp", |
| 82 | + "src/mapnik_rule.cpp", |
| 83 | + "src/mapnik_symbolizer.cpp", |
| 84 | + "src/mapnik_debug_symbolizer.cpp", |
| 85 | + "src/mapnik_markers_symbolizer.cpp", |
| 86 | + "src/mapnik_polygon_symbolizer.cpp", |
| 87 | + "src/mapnik_polygon_pattern_symbolizer.cpp", |
| 88 | + "src/mapnik_line_symbolizer.cpp", |
| 89 | + "src/mapnik_line_pattern_symbolizer.cpp", |
| 90 | + "src/mapnik_point_symbolizer.cpp", |
| 91 | + "src/mapnik_raster_symbolizer.cpp", |
| 92 | + "src/mapnik_scaling_method.cpp", |
| 93 | + "src/mapnik_style.cpp", |
| 94 | + "src/mapnik_logger.cpp", |
| 95 | + "src/mapnik_placement_finder.cpp", |
| 96 | + "src/mapnik_text_symbolizer.cpp", |
| 97 | + "src/mapnik_palette.cpp", |
| 98 | + "src/mapnik_parameters.cpp", |
| 99 | + "src/python_grid_utils.cpp", |
| 100 | + "src/mapnik_raster_colorizer.cpp", |
| 101 | + "src/mapnik_label_collision_detector.cpp", |
| 102 | + "src/mapnik_dot_symbolizer.cpp", |
| 103 | + "src/mapnik_building_symbolizer.cpp", |
| 104 | + "src/mapnik_shield_symbolizer.cpp", |
| 105 | + "src/mapnik_group_symbolizer.cpp", |
| 106 | + ], |
| 107 | + extra_compile_args=extra_comp_args, |
| 108 | + extra_link_args=linkflags, |
| 109 | + ) |
118 | 110 | ] |
119 | 111 |
|
120 | 112 | if os.environ.get("CC", False) == False: |
121 | | - os.environ["CC"] = check_output([mapnik_config, '--cxx']) |
| 113 | + os.environ["CC"] = "c++" |
122 | 114 | if os.environ.get("CXX", False) == False: |
123 | | - os.environ["CXX"] = check_output([mapnik_config, '--cxx']) |
| 115 | + os.environ["CXX"] = "c++" |
124 | 116 |
|
125 | 117 | setup( |
126 | | - name="mapnik", |
127 | | - package_dir={"": "packaging"}, |
128 | | - packages=["mapnik", |
129 | | - "mapnik/printing", |
130 | | - "mapnik/bin", |
131 | | - "mapnik/lib", |
132 | | - "mapnik/lib.mapnik.fonts", |
133 | | - "mapnik/lib.mapnik.input"], |
134 | | - include_package_data=True, |
135 | | - ext_modules=ext_modules, |
136 | | - cmdclass={"build_ext": build_ext}, |
137 | | - python_requires=">=3.9", |
| 118 | + name="mapnik", |
| 119 | + version="4.0.0.dev", |
| 120 | + packages=find_packages(where="packaging"), |
| 121 | + package_dir={"": "packaging"}, |
| 122 | + package_data={ |
| 123 | + "mapnik": ["lib/*.*", "lib/*/*/*", "share/*/*"], |
| 124 | + }, |
| 125 | + ext_modules=ext_modules, |
| 126 | + cmdclass={"build_ext": build_ext}, |
| 127 | + python_requires=">=3.7", |
138 | 128 | ) |
0 commit comments