Skip to content

Commit

Permalink
Merge pull request #34 from gb-libs/up-workflow
Browse files Browse the repository at this point in the history
💡 up python and add new workflow
  • Loading branch information
folt authored Dec 9, 2024
2 parents 5dea9b2 + 310d1d7 commit b310480
Show file tree
Hide file tree
Showing 20 changed files with 931 additions and 160 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ updates:
- dependencies
schedule:
interval: "daily"
commit-message:
prefix:

# Maintain dependencies for Python
- package-ecosystem: "pip"
Expand All @@ -17,3 +19,5 @@ updates:
schedule:
interval: "daily"
open-pull-requests-limit: 10
commit-message:
prefix:
17 changes: 3 additions & 14 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.9

- name: Bootstrap poetry
run: |
curl -sL https://install.python-poetry.org | python - -y ${{ matrix.bootstrap-args }}
run: curl -sL https://install.python-poetry.org | python - -y

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v4
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will upload a Python Package using poetry when a release is created
# Note that you must manually update the version number in pyproject.toml before attempting this.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: debug-statements

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
pass_filenames: false

- repo: https://github.com/python-poetry/poetry
rev: '1.8.5'
hooks:
- id: poetry-check
- id: poetry-lock

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: help lint ruff-fix clean test


help: ## Display this help screen
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

lint: ## Auto fix lint
pre-commit run --all-files

ruff-fix: ## Auto fix lint ruff
ruff check . --fix

clean: ## Clear temp files
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -rf dist *.egg-info
rm -rf .cache
rm -rf .pytest_cache
rm -f .coverage
rm -f .coverage.*

test: ## Run tests
pytest --cov=pydantic_geojson --cov-report=xml
754 changes: 754 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pydantic_geojson/feature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Any
from typing import Any, Union

from pydantic import BaseModel

Expand Down
19 changes: 9 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydantic_geojson"
version = "0.1.1"
version = "0.2.0"
description = "Pydantic validation for GeoJson"
authors = [
"Aliaksandr Vaskevich <[email protected]>",
Expand Down Expand Up @@ -31,26 +31,25 @@ classifiers = [
"Topic :: Scientific/Engineering :: GIS",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"License :: OSI Approved :: MIT License",
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.9"
pydantic = ">=1.9,<3.0"

[tool.poetry.dev-dependencies]
isort = "^5.10.1"
pytest = "^7.1.1"
pytest-cov = "^4.0.0"
mypy = "^1.4.1"

[tool.poetry.group.dev.dependencies]
bandit = "^1.7.5"
isort = "^5.13.2"
pytest = "^8.3.4"
pytest-cov = "^6.0.0"
mypy = "^1.13.0"
pre-commit = "^4.0.1"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
1 change: 0 additions & 1 deletion tests/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


class TestFeatureModel:

def test_geometry_model_type(self):
f_model = FeatureModel(**data)
assert f_model.geometry.type == data["geometry"]["type"]
Expand Down
21 changes: 9 additions & 12 deletions tests/test_feature_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-80.870885, 35.215151]
},
"properties": {}
"geometry": {"type": "Point", "coordinates": [-80.870885, 35.215151]},
"properties": {},
},
{
"type": "Feature",
Expand All @@ -22,13 +19,13 @@
[-80.722646, 35.260338],
[-80.720329, 35.260618],
[-80.704793, 35.268397],
[-80.724878, 35.265454]
[-80.724878, 35.265454],
]
]
],
},
"properties": {}
}
]
"properties": {},
},
],
}


Expand All @@ -38,9 +35,9 @@ def test_loads_model(self):
features = fc_model.features

for fc_key, fc_item in enumerate(features):
assert fc_item.type == data['features'][fc_key]['type']
assert fc_item.type == data["features"][fc_key]["type"]

assert fc_model.type == data['type']
assert fc_model.type == data["type"]

def test_model_type(self):
fc_model = FeatureCollectionModel(**data)
Expand Down
52 changes: 14 additions & 38 deletions tests/test_feature_on_lat_lon_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,23 @@
"coordinates": [
[-180.0, -90],
[180.0, 90],
]
],
}

data_point = {
'type': 'Point',
'coordinates': [-180, 90]
}

data_point_error_lon_min = {
'type': 'Point',
'coordinates': [-181, 90]
}
data_point = {"type": "Point", "coordinates": [-180, 90]}

data_point_error_lon_max = {
'type': 'Point',
'coordinates': [181, 90]
}
data_point_error_lon_min = {"type": "Point", "coordinates": [-181, 90]}

data_point_error_lon_max = {"type": "Point", "coordinates": [181, 90]}

data_point_error_lat_min = {
'type': 'Point',
'coordinates': [-180, -91]
}

data_point_error_lat_max = {
'type': 'Point',
'coordinates': [180, 91]
data_point_error_lat_min = {"type": "Point", "coordinates": [-180, -91]}

}
data_point_error_lat_max = {"type": "Point", "coordinates": [180, 91]}

data_polygon = {
'type': 'Polygon',
'coordinates': [
[
[-180, 90],
[180, 90],
[180, -90],
[-180, -90],
[180, 90]
]
]
"type": "Polygon",
"coordinates": [[[-180, 90], [180, 90], [180, -90], [-180, -90], [180, 90]]],
}


Expand All @@ -56,18 +32,18 @@ def test_loads_model_linestring(self):

for lsi_key, ls_item in enumerate(coordinates):
lon, lat = ls_item
assert data_linestring['coordinates'][lsi_key] == [lon, lat]
assert data_linestring["coordinates"][lsi_key] == [lon, lat]

assert ls_model.type == data_linestring['type']
assert ls_model.type == data_linestring["type"]

def test_loads_model_point(self):
p_model = PointModel(**data_point)
coordinates = p_model.coordinates

lon, lat = coordinates.lon, coordinates.lat
assert data_point['coordinates'] == [lon, lat]
assert data_point["coordinates"] == [lon, lat]

assert p_model.type == data_point['type']
assert p_model.type == data_point["type"]

def test_loads_model(self):
p_model = PolygonModel(**data_polygon)
Expand All @@ -76,9 +52,9 @@ def test_loads_model(self):
for pi_key, p_item in enumerate(coordinates):
for pl_key, p_coordinate in enumerate(p_item):
lon, lat = p_coordinate.lon, p_coordinate.lat
assert data_polygon['coordinates'][pi_key][pl_key] == [lon, lat]
assert data_polygon["coordinates"][pi_key][pl_key] == [lon, lat]

assert p_model.type == data_polygon['type']
assert p_model.type == data_polygon["type"]

def test_error_in_output_range_lon_min(self):
try:
Expand Down
21 changes: 9 additions & 12 deletions tests/test_geometry_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
data = {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [-80.660805, 35.049392]
},
{"type": "Point", "coordinates": [-80.660805, 35.049392]},
{
"type": "Polygon",
"coordinates": [
Expand All @@ -16,19 +13,19 @@
[-80.663874, 35.04428],
[-80.662586, 35.04558],
[-80.663444, 35.046036],
[-80.664582, 35.044965]
[-80.664582, 35.044965],
]
]
],
},
{
"type": "LineString",
"coordinates": [
[-80.662372, 35.059509],
[-80.662693, 35.059263],
[-80.662844, 35.05893]
]
}
]
[-80.662844, 35.05893],
],
},
],
}


Expand All @@ -38,9 +35,9 @@ def test_loads_model(self):
geometries = gc_model.geometries

for g_key, g_item in enumerate(geometries):
assert g_item.type == data['geometries'][g_key]['type']
assert g_item.type == data["geometries"][g_key]["type"]

assert gc_model.type == data['type']
assert gc_model.type == data["type"]

def test_model_type(self):
gc_model = GeometryCollectionModel(**data)
Expand Down
Loading

0 comments on commit b310480

Please sign in to comment.