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

Python 0.2.1 #341

Merged
merged 3 commits into from
Feb 28, 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
46 changes: 9 additions & 37 deletions .github/workflows/Python-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest , windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
# 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 @@ -42,48 +42,20 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache: "pip"

- name: Install dependencies (Ubuntu)
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Add the Ubuntu GIS PPA
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt update
# Install geos library (shapely requirement)
sudo apt-get install libgeos++-dev libgeos3.10.2 libgeos-c1v5 libgeos-dev libgeos-doc
if: matrix.os == 'ubuntu-latest'
working-directory: python-package
pip install poetry

- name: Install dependencies (Windows)
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
if: matrix.os == 'windows-latest'
working-directory: python-package

- name: Install dependencies (MacOS)
run: |
python -m pip install --upgrade pip
brew install geos
pip install shapely --no-binary shapely
pip install -r requirements.txt
if: matrix.os == 'macOS-latest'
- name: Install dependencies with Poetry
run: poetry install
working-directory: python-package

- name: Save dependencies
run: pip freeze > requirements.txt

- name: Install testing dependencies
run: |
pip install pytest
pip install coverage

- name: Run tests
- name: Run tests with Poetry
run: |
coverage run -m pytest -x ./tests
coverage report --omit="tests/*" -m >> test-results.txt
poetry run pytest ./tests
working-directory: python-package

- name: Upload check results
Expand Down
1 change: 1 addition & 0 deletions python-package/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
16 changes: 0 additions & 16 deletions python-package/Makefile

This file was deleted.

39 changes: 7 additions & 32 deletions python-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
To start the development environment run

```sh
make
. .venv/bin/activate
poetry install
```

Test with

`python -m pytest`
`poetry run pytest`

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

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

It will scrape the original R function to get documentation and metadata.
It adds:
Expand All @@ -32,37 +34,10 @@ It adds:
- larger documentation
- very basic tests

! Be aware that if the function that you are adding is more complicated than the template. So, double always double check !

Before pushing, run

`make prepare-push`

#### For Windows

We recommend using conda and creating an environment that includes all libraries simultaneously.

First create an environment and install Shapely and GDAL as such:

`conda create --name geobr_env python=3.7`

Activate the environmnet

`conda activate geobr_env`

Then add Shapely from conda-forge channel
`conda install shapely gdal -c conda-forge`

Then the other packages
`conda install fiona pandas geopandas requests -c conda-forge`

**Alternatively**, type on a terminal
! Be aware that if the function that you are adding is more complicated than the template. So, always double check !

`conda create --name <env> --file conda_requirements.txt`

Finally, if **not** using conda, try:

`pip install -r pip_requirements.txt`

## Translation Status

Expand Down
Binary file removed python-package/conda_requirements.txt
Binary file not shown.
3 changes: 2 additions & 1 deletion python-package/geobr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
from .read_intermediate_region import read_intermediate_region
from .read_urban_concentrations import read_urban_concentrations
from .read_schools import read_schools
from .read_comparable_areas import read_comparable_areas
from .read_comparable_areas import read_comparable_areas
from .read_biomes import read_biomes
21 changes: 12 additions & 9 deletions python-package/geobr/list_geobr.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
from requests import get
import pandas as pd
from io import StringIO
from urllib.error import HTTPError


def list_geobr():
""" Prints available functions, according to latest README.md file
"""Prints available functions, according to latest README.md file

Example output
------------------------------
Function: read_immediate_region
Geographies available: Immediate region
Years available: 2017
Source: IBGE
------------------------------
Example output
------------------------------
Function: read_immediate_region
Geographies available: Immediate region
Years available: 2017
Source: IBGE
------------------------------

"""

try:
df = pd.read_html(get("https://github.com/ipeaGIT/geobr/blob/master/README.md").text)[1]
html_data = get("https://github.com/ipeaGIT/geobr/blob/master/README.md").text

df = pd.read_html(StringIO(html_data))[1]

except HTTPError:
print(
Expand Down
Loading
Loading