Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dependency manager do uv and update geopandas/shapely deps #374

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/Python-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# Python 3.8 support ends in 2024-10
# Python 3.12 support starts in 2023-10
# Check Python maintenance status at: https://www.python.org/downloads/
Expand All @@ -44,18 +44,18 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Install Poetry
- name: Install uv
run: |
python -m pip install --upgrade pip
pip install poetry
curl -LsSf https://astral.sh/uv/install.sh | sh

- name: Install dependencies with Poetry
run: poetry install
- name: Install dependencies with uv
run: uv sync
working-directory: python-package

- name: Run tests with Poetry
- name: Run tests with uv
run: |
poetry run pytest ./tests
uv run pytest -n auto ./tests
working-directory: python-package

- name: Upload check results
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ python-package/.coverage
/r-package/.Rhistory
/r-package/.Rhistory
/r-package/.Rhistory
.pdm-build
7 changes: 3 additions & 4 deletions python-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
To start the development environment run

```sh
poetry install
uv sync
```

Test with

`poetry run pytest`
`uv run pytest -n auto`

You can use a helper to translate a function from R.
If you want to add `read_biomes`, just run

```sh
poetry shell
python helpers/translate_from_R.py read_biomes
uv run python helpers/translate_from_R.py read_biomes
```

It will scrape the original R function to get documentation and metadata.
Expand Down
15 changes: 8 additions & 7 deletions python-package/geobr/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from functools import lru_cache
from urllib.error import HTTPError
import tempfile

import geopandas as gpd
import pandas as pd
Expand Down Expand Up @@ -171,21 +172,21 @@ def load_gpkg(url):
raise Exception(
"Some internal url is broken."
"Please report to https://github.com/ipeaGIT/geobr/issues"
)
) from e

# This below does not work in Windows -- see the Docs
# Whether the name can be used to open the file a second time, while the named temporary file is still open,
# varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).
# https://docs.python.org/2/library/tempfile.html

# with tempfile.NamedTemporaryFile(suffix='.gpkg') as fp:
with open("temp.gpkg", "wb") as fp:

# Create a temporary file with .gpkg extension that is automatically deleted when closed
with tempfile.NamedTemporaryFile(suffix=".gpkg", delete=False) as fp:
fp.write(content)

# Need to close file before reading on Windows
fp.close()
gdf = gpd.read_file(fp.name)

os.remove("temp.gpkg")
# Clean up temp file
os.unlink(fp.name)

return gdf

Expand Down
1,013 changes: 0 additions & 1,013 deletions python-package/poetry.lock

This file was deleted.

60 changes: 38 additions & 22 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
[tool.poetry]
authors = ["João Carabetta", "Rafael H. M. Pereira", "Caio Nogueira Goncalves", "Bernardo Furtado"]
[project]
name = "geobr"
version = "0.2.2"
description = "geobr: Download Official Spatial Data Sets of Brazil"
readme = "README.md"
requires-python = "<4.0,>=3.9"
license = {text = "MIT"}
authors = [
{name = "João Carabetta"},
{name = "Rafael H. M. Pereira"},
{name = "Caio Nogueira Goncalves"},
{name = "Bernardo Furtado"},
]
dependencies = [
"geopandas>=1.0.0,<=1.1",
"shapely>=1.7.0,<=2.1.0",
"requests<3.0.0,>=2.25.1",
"lxml<6.0.0,>=5.1.0",
"html5lib==1.1",
]
classifiers = [
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
Expand All @@ -8,29 +26,19 @@ classifiers = [
"Topic :: Scientific/Engineering :: Visualization",
"Programming Language :: Python",
]
description = "geobr: Download Official Spatial Data Sets of Brazil"

[project.urls]
homepage = "https://github.com/ipeaGIT/geobr"
license = "MIT"
name = "geobr"
packages = [
{include = "geobr"},
]
readme = "README.md"
repository = "https://github.com/ipeaGIT/geobr"
version = "0.2.1"

[tool.poetry.dependencies]
geopandas = "^0.14.0"
shapely = "^1.7.0"
python = "^3.9"
requests = "^2.25.1"
lxml = "^5.1.0"
html5lib = "1.1"
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.poetry.dev-dependencies]
pytest = "^6.0"
jinja2 = "^3.1.4"
fire = "^0.5.0"
[tool.pdm.build]
includes = [
"geobr",
]

[tool.black]
line-length = 88
Expand All @@ -53,4 +61,12 @@ exclude = '''
)/
| helpers/template
)
'''
'''

[tool.uv]
dev-dependencies = [
"pytest<7.0,>=6.0",
"pytest-xdist>=3.5.0",
"jinja2<4.0.0,>=3.1.4",
"fire<1.0.0,>=0.5.0",
]
Loading
Loading