Skip to content

Commit

Permalink
Add setuptools to install dependency (#56)
Browse files Browse the repository at this point in the history
* Add setuptools to install dependency

* Update min python version

* Add pyproject and revise setup

* drop url pyproject

* restore test env

* fix pyproject

* Revise toml

* Revise order of rules

* Removing older requirements file

* Drop duplicated github release

* Implement dynamic versioning pyproject

* Revise path of VERSION file
  • Loading branch information
davide-f authored Dec 12, 2024
1 parent f47402d commit 0068ac3
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 153 deletions.
73 changes: 47 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
name: Upload Python Package
name: Publish Python 🐍 distribution 📦 to PyPI

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

release:
name: Create Release
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -26,23 +46,24 @@ jobs:
with:
body_path: release_message.md

deploy:
needs: release
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs:
- release
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/earth-osm # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
- name: Download all the dists
uses: actions/download-artifact@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ The project's CLI is not using click because it is an external dependency. The g
│   ├── __main__.py # The entry point for the project
│   └── VERSION # The version for the project is kept in a static file
├── README.md # The main readme for the project
├── setup.py # The setup.py file for installing and packaging the project
├── requirements.txt # An empty file to hold the requirements for the project
├── requirements-test.txt # List of requirements for testing and devlopment
├── setup.py # The setup.py file for installing and packaging the project
├── pyproject.toml # Configuration file used by packaging tools
└── tests # Unit tests for the project (add mote tests files here)
├── conftest.py # Configuration, hooks and fixtures for pytest
├── __init__.py # This tells Python that this is a test package
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include LICENSE
include HISTORY.md
include requirements
graft tests
graft earth_osm
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ show: ## Show the current environment.
.PHONY: install
install: ## Install the project in dev mode.
@echo "Don't forget to run 'make virtualenv' if you got errors."
$(ENV_PREFIX)pip install -e .[test]
$(ENV_PREFIX)pip install -e .[dev]

.PHONY: fmt
fmt: ## Format code using black & isort.
Expand Down Expand Up @@ -67,7 +67,7 @@ virtualenv: ## Create a virtual environment.
@rm -rf .venv
@python3 -m venv .venv
@./.venv/bin/pip install -U pip
@./.venv/bin/pip install -e .[test]
@./.venv/bin/pip install -e .[dev]
@echo
@echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!"

Expand All @@ -90,7 +90,7 @@ api-docs: ## Generate the API documentation.
echo "There are uncommitted changes. Stash or commit changes first"; \
else \
echo "Generating API documentation..."; \
$(ENV_PREFIX)pip install -r requirements-docs.txt; \
$(ENV_PREFIX)pip install -r .[docs]; \
$(ENV_PREFIX)lazydocs \
--output-path="./docs/api-docs" \
--overview-file="README.md" \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ To contribute to earth-osm, follow these steps:
3. Install the development dependencies:
```bash
pip install git+https://github.com/pypsa-meets-earth/earth-osm.git
pip install -r requirements-test.txt
pip install -r .[test]
```

4. Read the [CONTRIBUTING.md](CONTRIBUTING.md) file for more detailed information on how to contribute to the project.
Expand Down
8 changes: 7 additions & 1 deletion earth_osm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import logging
import os

logging.basicConfig(level=logging.INFO) # Basic configuration
logger = logging.getLogger('eo')
logger = logging.getLogger('eo')

# specify version
fp_version = os.path.join(os.path.dirname(__file__), "VERSION")
with open(fp_version) as f:
__version__ = f.read().strip()
101 changes: 101 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[build-system]
requires = ["pip", "setuptools>=64", "setuptools-scm", "wheel", "twine"]
build-backend = "setuptools.build_meta"

[project]
name = "earth_osm"
dynamic = ["version"]
authors = [
{ name="pypsa-meets-earth" },
]
description = "Python tool to extract large-amounts of OpenStreetMap data"
readme = "README.md"
requires-python = ">=3.8"
license = {text = "MIT License"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
]
dependencies = [
"geopandas",
"pandas",
"tqdm",
"requests",
"protobuf>=4.21.1",
]

[project.urls]
Homepage = "https://github.com/pypsa-meets-earth/earth-osm/"
Issues = "https://github.com/pypsa-meets-earth/earth-osm/issues"

[project.optional-dependencies]
dev = [
"pytest",
"coverage",
"flake8",
"black",
"isort",
"pytest-cov",
"codecov",
"mypy>=0.9",
"gitchangelog",
"mkdocs",
"osmium",
]
docs = [
"lazydocs",
"mkdocs",
"mkdocs-material",
"mkdocs-awesome-pages-plugin",
"mkdocstrings[python]",
"markdown-include",
]

[console_scripts]
earth_osm = "earth_osm.__main__:main"

[tool.setuptools_scm]
version_scheme = "no-guess-dev"

[tool.setuptools.packages.find]
include = ["earth-osm"]

[tool.setuptools.package-data]
"earth_osm" = ["py.typed"]

# Pytest settings

[tool.pytest.ini_options]
filterwarnings = [
"error::DeprecationWarning", # Raise all DeprecationWarnings as errors
"error::FutureWarning", # Raise all FutureWarnings as errors
]

# Coverage settings

[tool.coverage.run]
branch = true
source = ["earth_osm"]
omit = ["test/*"]
[tool.coverage.report]
exclude_also = [
"if TYPE_CHECKING:",
]

# Static type checker settings
[tool.mypy]
exclude = ['dev/*', 'examples/*', 'docs/*']
ignore_missing_imports = true
no_implicit_optional = true
warn_unused_ignores = true
show_error_code_links = true


[[tool.mypy.overrides]]
module = "earth_osm.*"
disallow_untyped_defs = true
check_untyped_defs = true
6 changes: 0 additions & 6 deletions requirements-docs.txt

This file was deleted.

13 changes: 0 additions & 13 deletions requirements-test.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

93 changes: 0 additions & 93 deletions setup.py

This file was deleted.

0 comments on commit 0068ac3

Please sign in to comment.