pyvalhalla-git 3.5.1.post187__cp39-cp39-macosx_14_0_arm64.whl → 3.6.0.post0__cp39-cp39-macosx_14_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyvalhalla-git
3
- Version: 3.5.1.post187
3
+ Version: 3.6.0.post0
4
4
  Summary: High-level bindings to the Valhalla C++ library
5
5
  Home-page: https://github.com/valhalla/valhalla
6
6
  Author: Nils Nolde
@@ -26,7 +26,7 @@ Dynamic: summary
26
26
 
27
27
  ## Valhalla Python bindings
28
28
 
29
- This package contains the Python bindings to [Valhalla routing engine](https://github.com/valhalla/valhalla).
29
+ This folder contains the Python bindings to [Valhalla routing engine](https://github.com/valhalla/valhalla).
30
30
 
31
31
  > [!NOTE]
32
32
  > `pyvalhalla(-git)` packages are currently only published for:
@@ -34,9 +34,7 @@ This package contains the Python bindings to [Valhalla routing engine](https://g
34
34
  > - `win-amd64`
35
35
  > - `macos-arm64`
36
36
 
37
- ### License
38
-
39
- Due to the dependencies we package, the Python bindings are licensed under GNU Lesser General Public License v2 or later (LGPLv2+).
37
+ On top of the (very) high-level Python bindings, we package some data-building Valhalla executables to ease the process of graph creation.
40
38
 
41
39
  ### Installation
42
40
 
@@ -47,7 +45,9 @@ We distribute all currently maintained CPython versions as **binary wheels** for
47
45
 
48
46
  ### Usage
49
47
 
50
- Find a more extended notebook in `./examples`, e.g. how to [use the actor](./examples/actor_examples.ipynb).
48
+ #### Bindings
49
+
50
+ Find a more extended notebook in `./examples`, e.g. how to [use the actor](https://github.com/valhalla/valhalla/blob/master/src/bindings/python/examples/actor_examples.ipynb).
51
51
 
52
52
  Before using the Python bindings you need to have access to a routable Valhalla graph. Either install Valhalla from source and built the graph from OSM compatible data or use our [Valhalla docker image](https://github.com/gis-ops/docker-valhalla) for a painless experience, e.g. this will build the routing graph for Andorra in `./custom_files`:
53
53
 
@@ -71,6 +71,24 @@ actor = Actor(config)
71
71
  route = actor.route({"locations": [...]})
72
72
  ```
73
73
 
74
+ #### Valhalla executables (**`linux-x86_x64` only**)
75
+
76
+ To access the C++ (native) executables, there are 2 options:
77
+ - (recommended) execute the module, e.g. `python -m valhalla valhalla_build_tiles -h`
78
+ - execute the Python wrapper scripts directly, e.g. `valhalla_build_tiles -h`
79
+
80
+ > [!NOTE]
81
+ > For the latter option to work, the Python environment's `bin/` folder has to be in the `$PATH`. Inside virtual environments, that's always the case.
82
+
83
+ Executing the scripts directly might also not work properly if there's a system-wide Valhalla installation, unless the Python environment's `bin/` folder has higher priority than system folders in `$PATH`. The module execution uses an explicit Python executable which should be preferred.
84
+
85
+ There are also some additional commands we added:
86
+ - `--help`: print the help for `python -m valhalla` explicitly
87
+ - `--quiet`: redirect `stdout` of the C++ executables to `/dev/null`; can be added **once** anywhere in the command, will not be forwarded to a C++ executable
88
+ - `print_bin_path`: simply prints the absolute path to the package-internal `bin/` directory where the C++ executables are; useful if the executables should be accessed directly in some script
89
+
90
+ To find out which Valhalla executables are currently included, run `python -m valhalla --help`. We limit the number of executables to control the wheel size. However, we're open to include any other executable if there's a good reason.
91
+
74
92
  ### Building from source
75
93
 
76
94
  #### Linux
@@ -94,7 +112,7 @@ Once built, start a container to actually build Valhalla using AlmaLinux 8:
94
112
  ```shell
95
113
  cd valhalla
96
114
  docker run -dt -v $PWD:/valhalla-py --name valhalla-py --workdir /valhalla-py ghcr.io/valhalla/manylinux:2_28_valhalla_python
97
- docker exec -t valhalla-py /valhalla-py/src/bindings/python/build_linux.sh build_manylinux 3.12
115
+ docker exec -t valhalla-py /valhalla-py/src/bindings/python/build_linux.sh build_manylinux 3.13
98
116
  ```
99
117
 
100
118
  This will also build & install `libvalhalla` before building the bindings. At this point there should be a `wheelhouse` folder with the fixed python wheel, ready to be installed or distributed to arbitrary python 3.12 installations.
@@ -104,11 +122,16 @@ This will also build & install `libvalhalla` before building the bindings. At th
104
122
  On our CI, this orchestrates the packaging of all `pyvalhalla` wheels for every supported, minor Python version and every platform. It can also be run locally (obviously only being able to build wheels for _your_ platform), e.g.
105
123
 
106
124
  ```shell
107
- # specifiers from https://cibuildwheel.pypa.io/en/stable/options/#build-skip
125
+ python -m pip install cibuildwheel
126
+ cibuildwheel --print-build-identifiers
108
127
  cibuildwheel --only cp313-manylinux_x86_64
109
128
 
110
129
  # for windows you'll have to set an env var to the vcpkg win root
111
130
  VCPKG_ARCH_ROOT="build/vcpkg_installed/custom-x64-windows" cibuildwheel --only cp313-manylinux_x86_64
112
131
  ```
113
132
 
114
- On Linux, this might download the `manylinux` docker image. In the end, you'll find the wheel in `./wheelhouse`.
133
+ On Linux, this might download the [`manylinux` docker image](https://github.com/valhalla/manylinux/pkgs/container/manylinux). In the end, you'll find the wheel in `./wheelhouse`.
134
+
135
+ ### Testing (**`linux-x86_x64` only**)
136
+
137
+ We have a small [test script](https://github.com/valhalla/valhalla/blob/master/src/bindings/python/test/test_pyvalhalla_package.sh) which makes sure that all the executables are working properly. If run locally for some reason, install a `pyvalhalla` wheel first. We run this in CI in a fresh Docker container with no dependencies installed, mostly to verify dynamic linking of the vendored dependencies.
@@ -1,17 +1,20 @@
1
1
  _valhalla.cpython-39-darwin.so,sha256=EEYoZxz8FNNJvehpSCR5eHJYLqWZ8tBCXuWx45KVv2o,11479072
2
- pyvalhalla_git-3.5.1.post187.dist-info/RECORD,,
3
- pyvalhalla_git-3.5.1.post187.dist-info/WHEEL,sha256=DhkyuvaF_ECzC6tOpvYO14C_ylOEhcIxq8q81VPjNdw,134
4
- pyvalhalla_git-3.5.1.post187.dist-info/top_level.txt,sha256=mU472JpF5fOfpVQ8UxZ_dwLmecLogajAMO5RmYsU1gw,19
5
- pyvalhalla_git-3.5.1.post187.dist-info/METADATA,sha256=U5_omjLt3jjVJGrYfLlGB3sMSLKg0x5nN37ddO_rhVc,4773
6
- pyvalhalla_git-3.5.1.post187.dist-info/licenses/LICENSE.md,sha256=sZlxfQFAuJ8ba_1E8G3hYQ7eC770tBIywEWAg3rrixM,44
7
- pyvalhalla_git-3.5.1.post187.dist-info/licenses/AUTHORS,sha256=IGm6Dg1NRkmFHV2GWvlPdfiqVoc1kfoc0pMbcKiCs30,171
8
- pyvalhalla_git-3.5.1.post187.dist-info/licenses/COPYING,sha256=i9sUrrsAX_p17jiQqhCyQrMMhAyqAbmWxWM4yiefN80,1135
2
+ pyvalhalla_git-3.6.0.post0.dist-info/RECORD,,
3
+ pyvalhalla_git-3.6.0.post0.dist-info/WHEEL,sha256=DhkyuvaF_ECzC6tOpvYO14C_ylOEhcIxq8q81VPjNdw,134
4
+ pyvalhalla_git-3.6.0.post0.dist-info/top_level.txt,sha256=mU472JpF5fOfpVQ8UxZ_dwLmecLogajAMO5RmYsU1gw,19
5
+ pyvalhalla_git-3.6.0.post0.dist-info/METADATA,sha256=uzpMMvlVTOF183ebKJqt4o2qAYAGemUQg52C1UR2LNI,6790
6
+ pyvalhalla_git-3.6.0.post0.dist-info/licenses/LICENSE.md,sha256=sZlxfQFAuJ8ba_1E8G3hYQ7eC770tBIywEWAg3rrixM,44
7
+ pyvalhalla_git-3.6.0.post0.dist-info/licenses/AUTHORS,sha256=IGm6Dg1NRkmFHV2GWvlPdfiqVoc1kfoc0pMbcKiCs30,171
8
+ pyvalhalla_git-3.6.0.post0.dist-info/licenses/COPYING,sha256=i9sUrrsAX_p17jiQqhCyQrMMhAyqAbmWxWM4yiefN80,1135
9
9
  valhalla/config.py,sha256=kpYm-7RS4Mz3plcfGWNDx1s6tfXjnBGMei1uxhQ7VJM,1488
10
- valhalla/__init__.py,sha256=TQKBm2DP8mNh3OYJ-orTqk1KWGOum2U8fJo27IwQrBk,194
11
- valhalla/__version__.py,sha256=fUJPudoAYydBLozK46W_lClD7MtK4kD3D24zHiwVYDg,530
10
+ valhalla/_valhalla.cc,sha256=3OorCxyOun1-Q9olHlHw75q3XlprX4Lgd4UKQSHahsY,3699
11
+ valhalla/__init__.py,sha256=jxEX6PBKomyDW1D0On57Y52MIzBmmRQ8gnKb04p8tWg,374
12
+ valhalla/__version__.py,sha256=3CR9tHm_p_sRxPJJWnncp-FiRECKyV5HyHanX3vMSMY,526
12
13
  valhalla/utils.py,sha256=VCxJ5rNX4Ha8Ey4T81y1b3Ke2svUwGn5TNyW8nC_8p8,1923
13
14
  valhalla/actor.py,sha256=MviJjb6ui1KwIzJbACHncuLNDdHkj1hyzCHlDD_yEjw,4077
15
+ valhalla/_scripts.py,sha256=-zpCo07ckNy9yQFs2BymmmYwKS94ZAhlRyHLPUsfEKg,1504
14
16
  valhalla/valhalla_build_config.py,sha256=WJJG6t6I8NnkGc_Wd4vSwI2mgZcwQqPrwvKph2AjfGc,42507
17
+ valhalla/__main__.py,sha256=2X-2Wd8BOXKG63pI8M-nA2nMya2eJGU16aFK3ye0UMQ,2069
15
18
  valhalla/.dylibs/libsnappy.1.2.2.dylib,sha256=1D_MdNjNSmrGYQG30ZlmqXb2H1xTbacCevELbUEtRk0,79184
16
19
  valhalla/.dylibs/libhwy.1.2.0.dylib,sha256=Yrg_gB_yAOrT3Y494y1ePdkxz4-uSWDcin5WVWEmba4,96928
17
20
  valhalla/.dylibs/libIlmThread-3_3.32.3.3.3.dylib,sha256=Cbc2qNJa6hSvnHc_LWttt6wsd3ZgyI6CoCEd3yUlkXs,69744
@@ -86,7 +89,7 @@ valhalla/.dylibs/libssl.3.dylib,sha256=XbtHxY-Fp8FxFknYWDnlyKjSTUI44tPzH07xVDIzF
86
89
  valhalla/.dylibs/libabsl_log_internal_format.2407.0.0.dylib,sha256=1KEcZ4z8p2nlMUztcWAaZMEpQC1VDa3-Phv9cixj4Js,72112
87
90
  valhalla/.dylibs/libabsl_log_sink.2407.0.0.dylib,sha256=wmmSP56bkIXGQSKmKvqhXgp19sXigY12wt8boXNwxSU,68624
88
91
  valhalla/.dylibs/libarrow_dataset.2000.0.0.dylib,sha256=dIUWH4uFDQA5lC5-TLx_UyE6oF2HYWWV3hH9FVJ82dM,2432768
89
- valhalla/.dylibs/libprime_server.0.dylib,sha256=o3FpwXopxed6JBUPbPJTjHHn_Q-4uPOhHc14gHgH9kw,393168
92
+ valhalla/.dylibs/libprime_server.0.dylib,sha256=US-Ens9ctYyEqCRrDC9BdptthSkGj53XEQfNeZxAjMo,393168
90
93
  valhalla/.dylibs/libabsl_strerror.2407.0.0.dylib,sha256=p_NTirDupMktySlY_NFWEw-9vf3Q_mnDwvD2zO2uugI,53872
91
94
  valhalla/.dylibs/libnetcdf.22.dylib,sha256=B2gbziNwPMxNBjwrhgkAwpJeo76uXpxSGzHSWE9h1zc,1309456
92
95
  valhalla/.dylibs/libabsl_time.2407.0.0.dylib,sha256=4jzEGP5uO8FeGeMnPpxPiX2oDl_eiknqIDWaB93ENDU,111456
Binary file
valhalla/__init__.py CHANGED
@@ -1,8 +1,16 @@
1
+ from pathlib import Path
2
+
1
3
  try:
2
4
  from ._valhalla import *
3
5
  except ModuleNotFoundError:
4
6
  from _valhalla import *
5
-
6
7
  from .actor import Actor
7
8
  from .config import get_config, get_help
8
- from .__version__ import __version__
9
+
10
+ # if run from CMake, Docker or tests
11
+ try:
12
+ from .__version__ import __version__
13
+ except ModuleNotFoundError:
14
+ __version__ = "undefined"
15
+
16
+ PYVALHALLA_DIR = Path(__file__).parent.resolve()
valhalla/__main__.py ADDED
@@ -0,0 +1,68 @@
1
+ import subprocess
2
+ import sys
3
+ from typing import Optional
4
+
5
+ from ._scripts import PYVALHALLA_BIN_DIR, run
6
+ from . import __version__
7
+
8
+ PRINT_BIN_PATH = "print_bin_path"
9
+
10
+
11
+ def print_help():
12
+ # left-align executable names
13
+ exe_names = [p.name for p in PYVALHALLA_BIN_DIR.iterdir()]
14
+ fixed_width = len(max(exe_names, key=lambda x: len(x)))
15
+
16
+ # TODO: we also want the git commit to show here, probably written to __version__.py by setup.py's BDistWheelCommand
17
+ print(
18
+ F"""
19
+ valhalla Python package {__version__}
20
+
21
+ pyvalhalla package provides a CLI to run Valhalla C++ executables. Arguments are simply passed on as they are.
22
+ One notable exception is --quiet/-q, which will forward the C++ executable's stdout to /dev/null.
23
+ 'python -m valhalla --help' will print this help.
24
+
25
+ Example usage: 'python -m valhalla --quiet valhalla_build_tiles -c valhalla.json -s initialize -e build test.pbf'
26
+
27
+ Available commands (in {PYVALHALLA_BIN_DIR}):
28
+ \t{PRINT_BIN_PATH:<{fixed_width}} - Print the absolute path of directory containing the C++ executables
29
+ """
30
+ )
31
+
32
+
33
+ def main():
34
+ if len(sys.argv) < 2:
35
+ print("[FATAL] command needs arguments, see 'python -m valhalla --help': \n")
36
+ print_help()
37
+ sys.exit(1)
38
+
39
+ prog_or_opt = sys.argv[1]
40
+
41
+ if prog_or_opt in ("--help", "-h"):
42
+ print_help()
43
+ sys.exit(0)
44
+ elif prog_or_opt == PRINT_BIN_PATH:
45
+ # useful when another script wants to run the executables directly for some reason
46
+ print(PYVALHALLA_BIN_DIR)
47
+ else:
48
+ exc: Optional[Exception] = None
49
+ try:
50
+ run(from_main=True)
51
+ except (FileNotFoundError, subprocess.CalledProcessError) as e:
52
+ exc = e
53
+ finally:
54
+ if not exc:
55
+ sys.exit(0)
56
+
57
+ if isinstance(exc, subprocess.CalledProcessError):
58
+ print(f"Failed calling command '{exc.cmd}'\n")
59
+
60
+ print_help()
61
+ print("Sub-command failed with:\n")
62
+ print(exc, file=sys.stderr)
63
+
64
+ sys.exit(1)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ main()
valhalla/__version__.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '3.5.1.post187'
21
- __version_tuple__ = version_tuple = (3, 5, 1, 'post187')
20
+ __version__ = version = '3.6.0.post0'
21
+ __version_tuple__ = version_tuple = (3, 6, 0, 'post0')
valhalla/_scripts.py ADDED
@@ -0,0 +1,46 @@
1
+ from pathlib import Path
2
+ from shutil import which
3
+ import subprocess
4
+ import sys
5
+
6
+ from . import PYVALHALLA_DIR
7
+
8
+ PYVALHALLA_BIN_DIR = PYVALHALLA_DIR.joinpath("bin").resolve()
9
+
10
+
11
+ def run(from_main=False) -> None:
12
+ """
13
+ Parses the command line arguments and runs the Valhalla executables with the
14
+ provided arguments. Note, by default we assume this is not being called by
15
+ __main__.py via e.g. 'python -m valhalla ...', but directly with e.g.d
16
+ 'valhalla_build_tiles -h'. sys.argv relates to different executables for
17
+ both scenarios.
18
+
19
+ :param from_main: We parse sys.argv differently if it's called from __main__.py
20
+ """
21
+ prog = sys.argv[1] if from_main else Path(sys.argv[0]).name
22
+ prog_args = sys.argv[2:] if from_main else sys.argv[1:]
23
+
24
+ if not which(prog):
25
+ raise FileNotFoundError(f"Can't find executable at {prog}")
26
+ prog_path = PYVALHALLA_BIN_DIR.joinpath(prog).resolve()
27
+
28
+ print(f"[INFO] Running {prog_path} with args: {prog_args}...")
29
+
30
+ # --quiet/-q is our option, don't pass it to the executables
31
+ is_quiet = False
32
+ for arg in prog_args:
33
+ if arg not in ("--quiet", "-q"):
34
+ continue
35
+ prog_args.pop(prog_args.index(arg))
36
+ is_quiet = True
37
+
38
+ # recommended way to call exe
39
+ proc = subprocess.run(
40
+ [str(prog_path)] + prog_args,
41
+ stderr=sys.stderr,
42
+ stdout=subprocess.DEVNULL if is_quiet else sys.stdout,
43
+ )
44
+
45
+ # raises CalledProcessError if not successful
46
+ proc.check_returncode()
valhalla/_valhalla.cc ADDED
@@ -0,0 +1,81 @@
1
+ #include "baldr/rapidjson_utils.h"
2
+ #include "midgard/logging.h"
3
+ #include "midgard/util.h"
4
+ #include "tyr/actor.h"
5
+
6
+ #include <boost/make_shared.hpp>
7
+ #include <boost/noncopyable.hpp>
8
+ #include <boost/property_tree/ptree.hpp>
9
+ #include <pybind11/pybind11.h>
10
+
11
+ #include <string>
12
+
13
+ namespace vt = valhalla::tyr;
14
+ namespace {
15
+
16
+ // configuring multiple times is wasteful/ineffectual but not harmful
17
+ // TODO: make this threadsafe just in case its abused
18
+ const boost::property_tree::ptree configure(const std::string& config) {
19
+ boost::property_tree::ptree pt;
20
+ try {
21
+ // parse the config and configure logging
22
+ rapidjson::read_json(config, pt);
23
+
24
+ auto logging_subtree = pt.get_child_optional("mjolnir.logging");
25
+ if (logging_subtree) {
26
+ auto logging_config = valhalla::midgard::ToMap<const boost::property_tree::ptree&,
27
+ std::unordered_map<std::string, std::string>>(
28
+ logging_subtree.get());
29
+ valhalla::midgard::logging::Configure(logging_config);
30
+ }
31
+ } catch (...) { throw std::runtime_error("Failed to load config from: " + config); }
32
+
33
+ return pt;
34
+ }
35
+ } // namespace
36
+
37
+ namespace py = pybind11;
38
+
39
+ PYBIND11_MODULE(_valhalla, m) {
40
+ py::class_<vt::actor_t>(m, "_Actor", "Valhalla Actor class")
41
+ .def(py::init<>([](std::string config) { return vt::actor_t(configure(config), true); }))
42
+ .def(
43
+ "route", [](vt::actor_t& self, std::string& req) { return self.route(req); },
44
+ "Calculates a route.")
45
+ .def(
46
+ "locate", [](vt::actor_t& self, std::string& req) { return self.locate(req); },
47
+ "Provides information about nodes and edges.")
48
+ .def(
49
+ "optimized_route",
50
+ [](vt::actor_t& self, std::string& req) { return self.optimized_route(req); },
51
+ "Optimizes the order of a set of waypoints by time.")
52
+ .def(
53
+ "matrix", [](vt::actor_t& self, std::string& req) { return self.matrix(req); },
54
+ "Computes the time and distance between a set of locations and returns them as a matrix table.")
55
+ .def(
56
+ "isochrone", [](vt::actor_t& self, std::string& req) { return self.isochrone(req); },
57
+ "Calculates isochrones and isodistances.")
58
+ .def(
59
+ "trace_route", [](vt::actor_t& self, std::string& req) { return self.trace_route(req); },
60
+ "Map-matching for a set of input locations, e.g. from a GPS.")
61
+ .def(
62
+ "trace_attributes",
63
+ [](vt::actor_t& self, std::string& req) { return self.trace_attributes(req); },
64
+ "Returns detailed attribution along each portion of a route calculated from a set of input locations, e.g. from a GPS trace.")
65
+ .def(
66
+ "height", [](vt::actor_t& self, std::string& req) { return self.height(req); },
67
+ "Provides elevation data for a set of input geometries.")
68
+ .def(
69
+ "transit_available",
70
+ [](vt::actor_t& self, std::string& req) { return self.transit_available(req); },
71
+ "Lookup if transit stops are available in a defined radius around a set of input locations.")
72
+ .def(
73
+ "expansion", [](vt::actor_t& self, std::string& req) { return self.expansion(req); },
74
+ "Returns all road segments which were touched by the routing algorithm during the graph traversal.")
75
+ .def(
76
+ "centroid", [](vt::actor_t& self, std::string& req) { return self.centroid(req); },
77
+ "Returns routes from all the input locations to the minimum cost meeting point of those paths.")
78
+ .def(
79
+ "status", [](vt::actor_t& self, std::string& req) { return self.status(req); },
80
+ "Returns nothing or optionally details about Valhalla's configuration.");
81
+ }