From 86a35b7b2014dec205f80ff9e9887d98f04d02c0 Mon Sep 17 00:00:00 2001 From: BossyRomain Date: Thu, 30 Jan 2025 10:56:16 +0100 Subject: [PATCH 1/5] feat(CD): add pipeline to build and deploy package on PyPi --- .github/workflows/continuous_development.yml | 52 +++++++++++++++++++ pyproject.toml | 54 ++++++++++++++++++++ setup.py | 15 ------ 3 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/continuous_development.yml create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/continuous_development.yml b/.github/workflows/continuous_development.yml new file mode 100644 index 0000000..c6b133c --- /dev/null +++ b/.github/workflows/continuous_development.yml @@ -0,0 +1,52 @@ +name: Publish release to PyPi + +on: + # pull_request: + push: + branches: + - dev + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - name: Checkout the source ode + uses: actions/checkout@v3 + + - name: Setup the Python environment + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Build the universal wheel + run: | + python -m pip install hatchling + python -m hatchling build + + - uses: actions/upload-artifact@v4 + with: + name: wheel + path: dist/ + + publish: + name: publish + needs: build + runs-on: ubuntu-latest + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + environment: + name: pypi + url: https://pypi.org/p/appabuild + steps: + - uses: actions/download-artifact@v4 + with: + name: wheel + path: dist/ + + - name: Publish distribution package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + packages-dir: dist + password: ${{ secrets.PYPI_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9c1ddd0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[build-system] +requires = ["setuptools>=61.0.0", "wheel", "numpy"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +where = ["app", "appabuild"] + +[project] +name = "appabuild" +version = "0.3.0" +authors = [{ name = "Maxime Peralta", email = "maxime.peralta@cea.fr"}] +maintainers= [{name = "Maxime Peralta", email = "maxime.peralta@cea.fr"}] +description = "Appa Build is a package to build impact models" +keywords = [] +license = { file = "LICENSE.md" } +readme = "README.md" +classifiers = [ + "License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Intended Audience :: Developers", +] +requires-python = ">=3.6" +dependencies = [ + "numpy>=1.26.4", + "pandas>=2.0.0", + "brightway2>=2.4.7", + "bw2io==0.8.12", + "lca_algebraic>=1.0.0", + "fastapi", + "uvicorn[standard]", + "flake8", + "black", + "isort", + "typer", + "omegaconf", + "pydantic", + "scipy", + "matplotlib>=3.10.0", + "seaborn>=0.12.2", + "plotly", + "aenum", + "kaleido", + "tqdm", + "ruamel.yaml", + "apparun>=0.3.0", + "pre-commit", +] + +[project.scripts] +appabuild = "app.cli.main:cli_app" + +[project.urls] +"Source" = "https://github.com/appalca/appabuild/" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 1cff867..0000000 --- a/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name="appabuild", - version="0.3.0", - author="Maxime Peralta", - author_email="maxime.peralta@cea.fr", - description="Appa Build is a package to build impact models", - packages=find_packages(), - entry_points={ - "console_scripts": [ - "appabuild=app.cli.__main__:app", - ], - }, -) \ No newline at end of file From bdadf78844899cb74c564ca51f403a28b9df32ee Mon Sep 17 00:00:00 2001 From: BossyRomain Date: Fri, 31 Jan 2025 14:27:22 +0100 Subject: [PATCH 2/5] feat: update files to install and package the project --- app/cli/__main__.py | 11 ----------- app/cli/main.py | 12 ++++++++++++ pyproject.toml | 30 +++++++++++++++++------------- requirements.txt | 5 +++-- 4 files changed, 32 insertions(+), 26 deletions(-) delete mode 100644 app/cli/__main__.py create mode 100644 app/cli/main.py diff --git a/app/cli/__main__.py b/app/cli/__main__.py deleted file mode 100644 index c5054f7..0000000 --- a/app/cli/__main__.py +++ /dev/null @@ -1,11 +0,0 @@ -from .database import app as database_app -from .lca import app as lca_app -import typer - -app = typer.Typer() -app.add_typer(database_app, name="database") -app.add_typer(lca_app, name="lca") - - -if __name__ == "__main__": - typer.run(app) diff --git a/app/cli/main.py b/app/cli/main.py new file mode 100644 index 0000000..a4b15b8 --- /dev/null +++ b/app/cli/main.py @@ -0,0 +1,12 @@ +from app.cli.database import app as database_app +from app.cli.lca import app as lca_app +import typer + + +cli_app = typer.Typer() +cli_app.add_typer(database_app, name="database") +cli_app.add_typer(lca_app, name="lca") + + +if __name__ == "__main__": + cli_app() diff --git a/pyproject.toml b/pyproject.toml index 9c1ddd0..61c54f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [build-system] -requires = ["setuptools>=61.0.0", "wheel", "numpy"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" -[tool.setuptools.packages.find] -where = ["app", "appabuild"] +[tool.hatch.build.targets.wheel] +packages = ["app", "appabuild"] [project] name = "appabuild" @@ -11,7 +11,7 @@ version = "0.3.0" authors = [{ name = "Maxime Peralta", email = "maxime.peralta@cea.fr"}] maintainers= [{name = "Maxime Peralta", email = "maxime.peralta@cea.fr"}] description = "Appa Build is a package to build impact models" -keywords = [] +keywords = ["ecodesign", "life cycle assessment"] license = { file = "LICENSE.md" } readme = "README.md" classifiers = [ @@ -19,14 +19,17 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Intended Audience :: Developers", + "Intended Audience :: Manufacturing", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", ] -requires-python = ">=3.6" +requires-python = ">=3.11,<3.12" dependencies = [ - "numpy>=1.26.4", - "pandas>=2.0.0", - "brightway2>=2.4.7", + "numpy==1.26.4", + "pandas==2.0.0", + "brightway2==2.4.7", "bw2io==0.8.12", - "lca_algebraic>=1.0.0", + "lca_algebraic==1.0.0", "fastapi", "uvicorn[standard]", "flake8", @@ -36,15 +39,16 @@ dependencies = [ "omegaconf", "pydantic", "scipy", - "matplotlib>=3.10.0", - "seaborn>=0.12.2", + "matplotlib==3.10.0", + "seaborn==0.12.2", "plotly", "aenum", "kaleido", "tqdm", "ruamel.yaml", - "apparun>=0.3.0", + "apparun==0.3.1", "pre-commit", + "typer==0.15.1", ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 0d4c463..5b7fa50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ numpy==1.26.4 pandas==2.0.0 brightway2==2.4.7 -bw2io==0.8.12 +bw2i==0.8.12 lca_algebraic==1.0.0 fastapi uvicorn[standard] flake8 black isort -typer +typer==0.15.1 omegaconf pydantic scipy @@ -22,3 +22,4 @@ tqdm ruamel.yaml apparun==0.3.0 pre-commit +hatchling From b20b2af5c37e140210e3902f9052e7e99fbab370 Mon Sep 17 00:00:00 2001 From: BossyRomain Date: Fri, 31 Jan 2025 14:30:10 +0100 Subject: [PATCH 3/5] fix(CD): fix trigger of the deploy package pipeline --- .github/workflows/continuous_development.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous_development.yml b/.github/workflows/continuous_development.yml index c6b133c..421a7b1 100644 --- a/.github/workflows/continuous_development.yml +++ b/.github/workflows/continuous_development.yml @@ -1,10 +1,9 @@ name: Publish release to PyPi on: - # pull_request: - push: + pull_request: branches: - - dev + - master jobs: build: @@ -17,7 +16,7 @@ jobs: - name: Setup the Python environment uses: actions/setup-python@v5 with: - python-version: "3.x" + python-version: "3.11" - name: Build the universal wheel run: | From f99e38ce4fe408cb1edfd64fb5ca9747d4aec237 Mon Sep 17 00:00:00 2001 From: BossyRomain Date: Fri, 31 Jan 2025 14:44:30 +0100 Subject: [PATCH 4/5] fix(dev): fix one dependency in the development requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5b7fa50..59b3ff1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ numpy==1.26.4 pandas==2.0.0 brightway2==2.4.7 -bw2i==0.8.12 +bw2io==0.8.12 lca_algebraic==1.0.0 fastapi uvicorn[standard] From 63144b304f3d72f4840d891532fba098ddcb98e3 Mon Sep 17 00:00:00 2001 From: BossyRomain Date: Fri, 31 Jan 2025 15:10:00 +0100 Subject: [PATCH 5/5] fix(CD): fix trigger event for the pipeline to package and deploy the project --- .github/workflows/continuous_development.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/continuous_development.yml b/.github/workflows/continuous_development.yml index 421a7b1..edca2b7 100644 --- a/.github/workflows/continuous_development.yml +++ b/.github/workflows/continuous_development.yml @@ -2,12 +2,15 @@ name: Publish release to PyPi on: pull_request: + types: + - closed branches: - master jobs: build: name: build + if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout the source ode