pyvalhalla-git 3.5.1.post187__cp312-cp312-macosx_14_0_arm64.whl → 3.5.1.post193__cp312-cp312-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.5.1.post193
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,6 +34,8 @@ This package contains the Python bindings to [Valhalla routing engine](https://g
34
34
  > - `win-amd64`
35
35
  > - `macos-arm64`
36
36
 
37
+ On top of the (very) high-level Python bindings, we package some data-building Valhalla executables to ease the process of graph creation.
38
+
37
39
  ### License
38
40
 
39
41
  Due to the dependencies we package, the Python bindings are licensed under GNU Lesser General Public License v2 or later (LGPLv2+).
@@ -47,6 +49,8 @@ We distribute all currently maintained CPython versions as **binary wheels** for
47
49
 
48
50
  ### Usage
49
51
 
52
+ #### Bindings
53
+
50
54
  Find a more extended notebook in `./examples`, e.g. how to [use the actor](./examples/actor_examples.ipynb).
51
55
 
52
56
  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`:
@@ -71,6 +75,24 @@ actor = Actor(config)
71
75
  route = actor.route({"locations": [...]})
72
76
  ```
73
77
 
78
+ #### Valhalla executables
79
+
80
+ To access the C++ (native) executables, there are 2 options:
81
+ - (recommended) execute the module, e.g. `python -m valhalla valhalla_build_tiles -h`
82
+ - execute the Python wrapper scripts directly, e.g. `valhalla_build_tiles -h`
83
+
84
+ > [!NOTE]
85
+ > 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.
86
+
87
+ 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.
88
+
89
+ There are also some additional commands we added:
90
+ - `--help`: print the help for `python -m valhalla` explicitly
91
+ - `--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
92
+ - `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
93
+
94
+ 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.
95
+
74
96
  ### Building from source
75
97
 
76
98
  #### Linux
@@ -94,7 +116,7 @@ Once built, start a container to actually build Valhalla using AlmaLinux 8:
94
116
  ```shell
95
117
  cd valhalla
96
118
  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
119
+ docker exec -t valhalla-py /valhalla-py/src/bindings/python/build_linux.sh build_manylinux 3.13
98
120
  ```
99
121
 
100
122
  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.
@@ -1,17 +1,20 @@
1
1
  _valhalla.cpython-312-darwin.so,sha256=yRMF10AknDjRFSuzbFdm2VpKKWXSTvObE0BkvRzzQgI,11478864
2
- pyvalhalla_git-3.5.1.post187.dist-info/RECORD,,
3
- pyvalhalla_git-3.5.1.post187.dist-info/WHEEL,sha256=VrhWOWJdu4wN9IKhAFBqWPMo6yuww-SFg9GbWc0qbmI,136
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.5.1.post193.dist-info/RECORD,,
3
+ pyvalhalla_git-3.5.1.post193.dist-info/WHEEL,sha256=VrhWOWJdu4wN9IKhAFBqWPMo6yuww-SFg9GbWc0qbmI,136
4
+ pyvalhalla_git-3.5.1.post193.dist-info/top_level.txt,sha256=mU472JpF5fOfpVQ8UxZ_dwLmecLogajAMO5RmYsU1gw,19
5
+ pyvalhalla_git-3.5.1.post193.dist-info/METADATA,sha256=yE_nUq5JEu1Gdl7hI9obCXKTop4bRF0UoIMwrtDaK7U,6335
6
+ pyvalhalla_git-3.5.1.post193.dist-info/licenses/LICENSE.md,sha256=sZlxfQFAuJ8ba_1E8G3hYQ7eC770tBIywEWAg3rrixM,44
7
+ pyvalhalla_git-3.5.1.post193.dist-info/licenses/AUTHORS,sha256=IGm6Dg1NRkmFHV2GWvlPdfiqVoc1kfoc0pMbcKiCs30,171
8
+ pyvalhalla_git-3.5.1.post193.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=hkaH-hN0yQ4NLDcAD-d5Jm1Qne6rc7HcDJimDZ92-B8,269
12
+ valhalla/__version__.py,sha256=Ayqd5H42DgZ_KBT7ApCl3-fCyWjKpNYrTUjrUdD0Qz4,530
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=X6B0ffW0-hWWJ-ZowzWnK9tFCF1himT3eQkTWyJ_xL0,2273
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=h_ScEhTzdwdHHS5UCpDq60I9j423In1XM84PM_MwIjY,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,11 @@
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
9
  from .__version__ import __version__
10
+
11
+ PYVALHALLA_DIR = Path(__file__).parent.resolve()
valhalla/__main__.py ADDED
@@ -0,0 +1,69 @@
1
+ import subprocess
2
+ import sys
3
+ from typing import Optional
4
+
5
+ from ._scripts import PYVALHALLA_BIN_DIR, run
6
+
7
+ PRINT_BIN_PATH = "print_bin_path"
8
+
9
+
10
+ def print_help():
11
+ print(
12
+ "\npyvalhalla package provides a CLI to run Valhalla C++ executables. Arguments are simply passed on as they are."
13
+ )
14
+ print(
15
+ "One notable exception is --quiet/-q, which will forward the C++ executable's stdout to /dev/null."
16
+ )
17
+ print("'python -m valhalla --help' will print this help.")
18
+ print(
19
+ "\nExample usage: 'python -m valhalla --quiet valhalla_build_tiles -c valhalla.json -s initialize -e build test.pbf'"
20
+ )
21
+ print("\nAvailable commands:")
22
+ # left-align executable names
23
+ exe_names = [p.name for p in PYVALHALLA_BIN_DIR.iterdir()]
24
+ fixed_width = len(max(exe_names, key=lambda x: len(x)))
25
+ print(
26
+ f"\t{PRINT_BIN_PATH:<{fixed_width}} - Print the absolute path of directory containing the C++ executables"
27
+ )
28
+ for command in exe_names:
29
+ print(f"\t{command:<{fixed_width}} - see usage with 'python -m pyvalhalla {command} --help' ")
30
+
31
+
32
+ def main():
33
+ if len(sys.argv) < 2:
34
+ print("[FATAL] command needs arguments, see 'python -m valhalla --help': \n")
35
+ print_help()
36
+ sys.exit(1)
37
+
38
+ prog_or_opt = sys.argv[1]
39
+
40
+ if prog_or_opt in ("--help", "-h"):
41
+ print_help()
42
+ sys.exit(0)
43
+ elif prog_or_opt == PRINT_BIN_PATH:
44
+ # useful when another script wants to run the executables directly for some reason
45
+ # in theory one doesn't even need a python installation for the Valhalla executables
46
+ # to still work, provided the correct wheel is used for the specific platform
47
+ print(PYVALHALLA_BIN_DIR)
48
+ else:
49
+ exc: Optional[Exception] = None
50
+ try:
51
+ run(from_main=True)
52
+ except (FileNotFoundError, subprocess.CalledProcessError) as e:
53
+ exc = e
54
+ finally:
55
+ if not exc:
56
+ sys.exit(0)
57
+
58
+ if isinstance(exc, subprocess.CalledProcessError):
59
+ print(f"Failed calling command '{exc.cmd}'\n")
60
+
61
+ print_help()
62
+ print("Sub-command failed with:\n")
63
+ print(exc, file=sys.stderr)
64
+
65
+ sys.exit(1)
66
+
67
+
68
+ if __name__ == "__main__":
69
+ 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.5.1.post193'
21
+ __version_tuple__ = version_tuple = (3, 5, 1, 'post193')
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
+ }