From 0068ac3935f7bb915f67b13a3e00ac1d1fbd6f7a Mon Sep 17 00:00:00 2001 From: Davide Fioriti <67809479+davide-f@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:24:32 +0100 Subject: [PATCH] Add setuptools to install dependency (#56) * 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 --- .github/workflows/release.yml | 73 +++++++++++++++--------- CONTRIBUTING.md | 5 +- MANIFEST.in | 1 - Makefile | 6 +- README.md | 2 +- earth_osm/__init__.py | 8 ++- pyproject.toml | 101 ++++++++++++++++++++++++++++++++++ requirements-docs.txt | 6 -- requirements-test.txt | 13 ----- requirements.txt | 5 -- setup.py | 93 ------------------------------- 11 files changed, 160 insertions(+), 153 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements-docs.txt delete mode 100644 requirements-test.txt delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d3033aa..3352c3a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 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 + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c0b24b9..e2192e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in index 731ca3e..4edf8c1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include LICENSE include HISTORY.md -include requirements graft tests graft earth_osm \ No newline at end of file diff --git a/Makefile b/Makefile index 31fb843..44cd7c4 100644 --- a/Makefile +++ b/Makefile @@ -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. @@ -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 !!!" @@ -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" \ diff --git a/README.md b/README.md index b33d6a8..3334811 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/earth_osm/__init__.py b/earth_osm/__init__.py index f87d37a..ccd748a 100644 --- a/earth_osm/__init__.py +++ b/earth_osm/__init__.py @@ -1,4 +1,10 @@ import logging +import os logging.basicConfig(level=logging.INFO) # Basic configuration -logger = logging.getLogger('eo') \ No newline at end of file +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() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c2edea7 --- /dev/null +++ b/pyproject.toml @@ -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 \ No newline at end of file diff --git a/requirements-docs.txt b/requirements-docs.txt deleted file mode 100644 index fe1d957..0000000 --- a/requirements-docs.txt +++ /dev/null @@ -1,6 +0,0 @@ -lazydocs -mkdocs -mkdocs-material -mkdocs-awesome-pages-plugin -mkdocstrings[python] -markdown-include \ No newline at end of file diff --git a/requirements-test.txt b/requirements-test.txt deleted file mode 100644 index 7647525..0000000 --- a/requirements-test.txt +++ /dev/null @@ -1,13 +0,0 @@ -pytest -coverage -flake8 -black -isort -pytest-cov -codecov -mypy>=0.9 -gitchangelog -mkdocs -pprint -osmium - diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 3825b78..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -geopandas -pandas -tqdm -requests -protobuf>=4.21.1 \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 49f1f4f..0000000 --- a/setup.py +++ /dev/null @@ -1,93 +0,0 @@ -"""Python setup.py for earth_osm package""" -import io -import os -from setuptools import find_packages, setup - - -def read(*paths, **kwargs): - """Read the contents of a text file safely. - >>> read("earth_osm", "VERSION") - '0.1.0' - >>> read("README.md") - ... - """ - content = "" - with io.open( - os.path.join(os.path.dirname(__file__), *paths), - encoding=kwargs.get("encoding", "utf8"), - ) as open_file: - content = open_file.read().strip() - return content - -# mirror of dependencies in setup and requirements.txt -install_requires=[ - "geopandas", - "pandas", - "tqdm", - "requests", - "protobuf>=4.21.1", -] - -extras_require={"test": [ - "pytest", - "coverage", - "flake8", - "black", - "isort", - "pytest-cov", - "codecov", - "mypy>=0.9", - "gitchangelog", - "mkdocs", - "pprint", - "osmium", - ] -} - -assert read("requirements.txt") == "\n".join(install_requires) -assert read("requirements-test.txt") == "\n".join(extras_require["test"]) - -setup( - name="earth_osm", - version=read("earth_osm", "VERSION"), - description="Python tool to extract large-amounts of OpenStreetMap data", - long_description=read("README.md"), - long_description_content_type="text/markdown", - author="pypsa-meets-earth", - url="https://github.com/pypsa-meets-earth/earth-osm/", - packages=find_packages(exclude=["docs", "tests"]), - include_package_data=True, - python_requires=">=3.6", - entry_points={ - "console_scripts": ["earth_osm = earth_osm.__main__:main"] - }, - install_requires=[ - "geopandas", - "pandas", - "tqdm", - "requests", - "protobuf>=4.21.1", - ], - extras_require={"test": [ - "pytest", - "coverage", - "flake8", - "black", - "isort", - "pytest-cov", - "codecov", - "mypy>=0.9", - "gitchangelog", - "mkdocs", - "osmium", - ], - }, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Natural Language :: English", - "Operating System :: OS Independent", - ], -) \ No newline at end of file