osmcode / pyosmium

Python bindings for libosmium
https://osmcode.org/pyosmium
BSD 2-Clause "Simplified" License
318 stars 65 forks source link

Introduce type annotations #211

Closed lonvia closed 2 years ago

lonvia commented 2 years ago

Supersedes #59. Now that the minimum requirement is Python 3.6 it is fairly easy to intermingle the type annotations in the code directly.

Please test this against your typed code to make sure the annotations are correct.

ltog commented 2 years ago

@lonvia : Thank you for this change! I am interested to use/test the type annotations in combination with mypy. Do you plan to release this anytime soon (under a new version number) for pypi? That would make it super-easy to include it in my (pet) project.

lonvia commented 2 years ago

A new release is imminent because I have a couple of bugs piled up where fixes need to be published. However, I would be really grateful if you could give it a quick try before the release to test if I haven't broken things.

ltog commented 2 years ago

@lonvia : I tested ee760fa with my current pet project. It uses only SimpleHandler and SimpleWriter. The result is: mypy --strict runs through without issues and the .pbf output is the byte-exact output as in my other setup.

I had an issue building pyosmium. As far as I could understand, it is related to the usage of Python 3.10. I attach my notes from the process, but apart from maybe adjusting your README there is probably not much you can do about it. I used Ubuntu MATE 22.04.1 LTS.

sudo apt install python3-build python3.10-venv
git clone https://github.com/osmcode/pyosmium.git
cd pyosmium
mkdir contrib
cd contrib
git clone https://github.com/osmcode/libosmium
git clone https://github.com/mapbox/protozero
git clone https://github.com/pybind/pybind11
cd ..

l@box:~/Desktop/pyosmium$ python3 -m build -w
* Creating venv isolated environment...

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/build/__main__.py", line 372, in main
    built = build_call(
  File "/usr/lib/python3/dist-packages/build/__main__.py", line 202, in build_package
    out = _build(isolation, builder, outdir, distribution, config_settings, skip_dependency_check)
  File "/usr/lib/python3/dist-packages/build/__main__.py", line 140, in _build
    return _build_in_isolated_env(builder, outdir, distribution, config_settings)
  File "/usr/lib/python3/dist-packages/build/__main__.py", line 104, in _build_in_isolated_env
    with _IsolatedEnvBuilder() as env:
  File "/usr/lib/python3/dist-packages/build/env.py", line 104, in __enter__
    executable, scripts_dir = _create_isolated_env_venv(self._path)
  File "/usr/lib/python3/dist-packages/build/env.py", line 258, in _create_isolated_env_venv
    executable, script_dir, purelib = _find_executable_and_scripts(path)
  File "/usr/lib/python3/dist-packages/build/env.py", line 303, in _find_executable_and_scripts
    raise RuntimeError(f'Virtual environment creation failed, executable {executable} missing')
RuntimeError: Virtual environment creation failed, executable /tmp/build-env-uni1pvd8/local/bin/python missing

ERROR Virtual environment creation failed, executable /tmp/build-env-uni1pvd8/local/bin/python missing

# some links:
# - https://github.com/pypa/build/issues/215
# - https://github.com/deadsnakes/issues/issues/198

sudo apt install python3-virtualenv
virtualenv -p python3 venv/
source venv/bin/activate
pip install build[virtualenv]  # per https://github.com/pypa/build/issues/215#issuecomment-1016989092

sudo apt install cmake libbz2-dev libboost-dev # install the minimum of dependencies of osmium according to https://osmcode.org/libosmium/manual.html#dependencies

python3 -m build -w  # will create ./dist/osmium-3.5.0-cp310-cp310-linux_x86_64.whl

# some info about my system

l@box:~$ python3 --version
Python 3.10.6

l@box:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy

I am looking forward to your release. Thank you for maintaining pyosmium! 👍👍👍