Skip to content

Commit 5ccfad7

Browse files
Merge pull request #23 from tilery/PreCommitAndWheels
add pre-commit and cibuildwheel
2 parents 0324b1b + 6cf6cce commit 5ccfad7

File tree

17 files changed

+248
-148
lines changed

17 files changed

+248
-148
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
ignore = E501,W503,E203
3+
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
4+
max-line-length = 90

.github/codecov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
comment: off
2+
3+
coverage:
4+
status:
5+
project:
6+
default:
7+
target: auto
8+
threshold: 5

.github/workflows/ci.yml

Lines changed: 101 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,126 @@ on:
1111

1212
jobs:
1313
tests:
14-
runs-on: ubuntu-latest
14+
name: ${{ matrix.name }}
15+
runs-on: ${{ matrix.os }}
1516
strategy:
17+
fail-fast: false
1618
matrix:
17-
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
19+
include:
20+
- {name: Windows, python: '3.10', os: windows-latest}
21+
- {name: Mac, python: '3.10', os: macos-latest}
22+
- {name: 'Ubuntu', python: '3.10', os: ubuntu-latest}
23+
- {name: '3.11', python: '3.11.0-rc.2 - 3.11', os: ubuntu-latest}
24+
- {name: '3.9', python: '3.9', os: ubuntu-latest}
25+
- {name: '3.8', python: '3.8', os: ubuntu-latest}
26+
- {name: '3.7', python: '3.7', os: ubuntu-latest}
27+
- {name: '3.6', python: '3.6', os: ubuntu-latest}
28+
- {name: '3.5', python: '3.5', os: ubuntu-latest}
1829

1930
steps:
20-
- uses: actions/checkout@v2
21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
31+
- uses: actions/checkout@v3
32+
- name: Set up Python ${{ matrix.python }}
33+
uses: actions/setup-python@v4
2334
with:
24-
python-version: ${{ matrix.python-version }}
35+
python-version: ${{ matrix.python }}
2536
- name: Install dependencies
2637
run: |
2738
python -m pip install --upgrade pip
28-
python -m pip install tox
2939
git submodule update --init
40+
python -m pip install -e .["test"]
3041
31-
# Run tox using the version of Python in `PATH`
32-
- name: Run Tox
33-
run: tox -e py
42+
- name: Run pre-commit
43+
if: ${{ matrix.name == 'Ubuntu' }}
44+
run: |
45+
python -m pip install pre-commit
46+
pre-commit run --all-files
3447
35-
publish:
48+
- name: Run Tests
49+
run: |
50+
python -m pytest --cov vtzero --cov-report xml --cov-report term-missing
51+
52+
- name: Upload Results
53+
if: ${{ matrix.name == 'Ubuntu' }}
54+
uses: codecov/codecov-action@v1
55+
with:
56+
file: ./coverage.xml
57+
flags: unittests
58+
name: ${{ matrix.python }}
59+
fail_ci_if_error: false
60+
61+
#######################################################################################
62+
# Deploy
63+
#######################################################################################
64+
build_wheels:
3665
needs: [tests]
37-
runs-on: ubuntu-latest
3866
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
67+
name: ${{ matrix.os }}
68+
runs-on: ${{ matrix.os }}
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
os: [ubuntu-latest, windows-latest, macos-latest]
73+
3974
steps:
40-
- uses: actions/checkout@v2
41-
- name: Set up Python
42-
uses: actions/setup-python@v1
75+
- uses: actions/checkout@v3
76+
77+
# Used to host cibuildwheel
78+
- uses: actions/setup-python@v4
4379
with:
44-
python-version: "3.x"
80+
python-version: '3.10'
81+
82+
- name: Install cibuildwheel
83+
run: python -m pip install cibuildwheel==2.11.1
4584

4685
- name: Install dependencies
4786
run: |
48-
python -m pip install --upgrade pip
49-
python -m pip install tox setuptools cython>=0.29.23
5087
git submodule update --init
51-
python setup.py build_ext --inplace
5288
53-
- name: Set tag version
54-
id: tag
55-
# https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
56-
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
89+
- name: Build wheels
90+
run: python -m cibuildwheel --output-dir wheelhouse
91+
env:
92+
CIBW_SKIP: 'pp*'
93+
CIBW_ARCHS_MACOS: auto universal2
5794

58-
- name: Set module version
59-
id: module
60-
# https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
61-
run: echo ::set-output name=version::$(python setup.py --version)
95+
- uses: actions/upload-artifact@v3
96+
with:
97+
path: ./wheelhouse
6298

63-
- name: Build and publish
64-
if: steps.tag.outputs.tag == steps.module.outputs.version
65-
env:
66-
TOXENV: release
67-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
68-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
69-
run: tox
99+
build_sdist:
100+
needs: [tests]
101+
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
102+
name: Build source distribution
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v3
106+
107+
- uses: actions/setup-python@v4
108+
name: Install Python
109+
with:
110+
python-version: '3.10'
111+
112+
- name: Install dependencies
113+
run: |
114+
python -m pip install numpy Cython
115+
git submodule update --init
116+
117+
- name: Build sdist
118+
run: python setup.py sdist
119+
120+
- uses: actions/upload-artifact@v3
121+
with:
122+
path: dist/*.tar.gz
123+
124+
upload_pypi:
125+
needs: [build_wheels, build_sdist]
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: actions/download-artifact@v2
129+
with:
130+
name: artifact
131+
path: dist
132+
133+
- uses: pypa/gh-action-pypi-publish@master
134+
with:
135+
user: ${{ secrets.PYPI_USERNAME }}
136+
password: ${{ secrets.PYPI_PASSWORD }}

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.3.0
4+
hooks:
5+
- id: black
6+
language_version: python
7+
args: [--safe]
8+
9+
- repo: https://github.com/PyCQA/isort
10+
rev: 5.10.1
11+
hooks:
12+
- id: isort
13+
language_version: python
14+
15+
- repo: https://github.com/PyCQA/flake8
16+
rev: 5.0.4
17+
hooks:
18+
- id: flake8
19+
language_version: python
20+
21+
- repo: https://github.com/PyCQA/pydocstyle
22+
rev: 6.1.1
23+
hooks:
24+
- id: pydocstyle
25+
language_version: python
26+
additional_dependencies:
27+
- toml

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release Notes
22

3+
### 0.0.1b3 - 2022-10-25
4+
5+
- add python 3.9, 3.10, 3.11 support
6+
- add python wheels
7+
- update vendor submodules
38

49
### 0.0.1b2 - 2021-06-16
510

example/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
from vtzero.tile import VectorTile, Tile, Layer, Point, Polygon, Linestring
1+
"""Example of python-vtzero usage."""
2+
3+
from vtzero.tile import Layer, Linestring, Point, Polygon, Tile, VectorTile
24

35
# Create MVT
46
tile = Tile()
57

68
# Add a layer
7-
layer = Layer(tile, b'my_layer')
9+
layer = Layer(tile, b"my_layer")
810

911
# Add a point
1012
feature = Point(layer)
1113
feature.add_points(1)
1214
feature.set_point(10, 10)
13-
feature.add_property(b'foo', b'bar')
14-
feature.add_property(b'x', b'y')
15+
feature.add_property(b"foo", b"bar")
16+
feature.add_property(b"x", b"y")
1517
feature.commit()
1618

1719
# Add a polygon
@@ -47,4 +49,4 @@
4749
if f.geometry_type == 0:
4850
break
4951
features.append(f)
50-
print(f"Nb Features: {len(features)}")
52+
print(f"Nb Features: {len(features)}")

pyproject.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
requires = ["setuptools>=40.8.0", "wheel", "Cython>=0.29.23"]
33
build-backend = "setuptools.build_meta"
44

5-
[tool.flake8]
6-
exclude = ".git,__pycache__,docs/source/conf.py,old,build,dist"
7-
max-line-length = 90
5+
[tool.isort]
6+
profile = "black"
7+
known_first_party = ["vtzero"]
8+
default_section = "THIRDPARTY"
9+
10+
[tool.mypy]
11+
no_strict_optional = "True"
12+
13+
[tool.pydocstyle]
14+
select = "D1"
15+
match = "(?!test).*.py"

setup.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
"""python-vtzero setup."""
22

3+
from Cython.Build import cythonize
34
from setuptools import setup
45
from setuptools.extension import Extension
5-
from Cython.Build import cythonize
66

77
with open("README.md") as f:
88
long_description = f.read()
99

1010
ext_options = {
11-
'include_dirs': ['./vendor/vtzero/include', './vendor/protozero/include'],
12-
'extra_compile_args': ['-O2', '-std=c++11']
11+
"include_dirs": ["./vendor/vtzero/include", "./vendor/protozero/include"],
12+
"extra_compile_args": ["-O2", "-std=c++11"],
1313
}
14-
ext_modules = cythonize([
15-
Extension('vtzero.tile', ['vtzero/tile.pyx'], language="c++", **ext_options)
16-
])
14+
ext_modules = cythonize(
15+
[Extension("vtzero.tile", ["vtzero/tile.pyx"], language="c++", **ext_options)]
16+
)
1717

1818
extra_reqs = {
19-
"test": ["pytest"],
19+
"test": ["pytest", "pytest-cov"],
2020
}
2121

2222

2323
setup(
24-
name='vtzero',
25-
description='Python wrapper for vtzero C++ library.',
24+
name="vtzero",
25+
description="Python wrapper for vtzero C++ library.",
2626
long_description=long_description,
2727
long_description_content_type="text/markdown",
2828
classifiers=[
29-
'License :: OSI Approved :: MIT License',
30-
'Intended Audience :: Developers',
31-
'Programming Language :: Python :: 3',
32-
'Operating System :: POSIX',
33-
'Environment :: Web Environment',
34-
'Development Status :: 2 - Pre-Alpha',
35-
'Topic :: Scientific/Engineering :: GIS'
29+
"License :: OSI Approved :: MIT License",
30+
"Intended Audience :: Developers",
31+
"Programming Language :: Python :: 3",
32+
"Operating System :: POSIX",
33+
"Environment :: Web Environment",
34+
"Development Status :: 2 - Pre-Alpha",
35+
"Topic :: Scientific/Engineering :: GIS",
3636
],
37-
keywords='mvt mapbox vector tile gis',
38-
platforms=['POSIX'],
39-
author='Yohan Boniface',
40-
author_email='[email protected]',
41-
license='MIT',
42-
packages=['vtzero'],
37+
keywords="mvt mapbox vector tile gis",
38+
platforms=["POSIX"],
39+
author="Yohan Boniface",
40+
author_email="[email protected]",
41+
license="MIT",
42+
packages=["vtzero"],
4343
ext_modules=ext_modules,
44-
provides=['vtzero'],
44+
provides=["vtzero"],
4545
include_package_data=True,
4646
extras_require=extra_reqs,
4747
)

tests/test_fixtures.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import json
22
from pathlib import Path
33

4-
from vtzero.tile import VectorTile
5-
64
import pytest
75

8-
ROOT = Path(__file__).parent.parent / 'vendor/mvt-fixtures/fixtures'
6+
from vtzero.tile import VectorTile
7+
8+
ROOT = Path(__file__).parent.parent / "vendor/mvt-fixtures/fixtures"
99

1010
# Magic: Generate tests from yml.
1111
# def pytest_generate_tests(metafunc):
@@ -28,36 +28,37 @@
2828
def fixture():
2929
def _(id):
3030
path = ROOT / id
31-
with (path / 'info.json').open('r') as f:
31+
with (path / "info.json").open("r") as f:
3232
info = json.loads(f.read())
33-
with (path / 'tile.json').open('r') as f:
33+
with (path / "tile.json").open("r") as f:
3434
data = json.loads(f.read())
35-
with (path / 'tile.mvt').open('rb') as f:
35+
with (path / "tile.mvt").open("rb") as f:
3636
mvt = f.read()
3737
return info, data, mvt
38+
3839
return _
3940

4041

4142
def first_feature(tile):
4243
assert not tile.empty()
4344
assert len(tile) == 1
4445
layer = next(tile)
45-
assert layer.name == b'hello'
46+
assert layer.name == b"hello"
4647
assert layer.version == 2
4748
assert layer.extent == 4096
4849
assert len(layer) == 1
4950
return next(layer)
5051

5152

5253
def test_empty_tile(fixture):
53-
info, data, mvt = fixture('001')
54+
info, data, mvt = fixture("001")
5455
tile = VectorTile(mvt)
5556
assert tile.empty()
5657
assert len(tile) == 0
5758

5859

5960
def test_single_point_without_id(fixture):
60-
info, data, mvt = fixture('002')
61+
info, data, mvt = fixture("002")
6162
tile = VectorTile(mvt)
6263
feature = first_feature(tile)
6364
assert not feature.has_id()

0 commit comments

Comments
 (0)