From 961ae621619f1fccd6407cfb69ba420382afd187 Mon Sep 17 00:00:00 2001 From: Lea Vauchier Date: Mon, 24 Jun 2024 17:47:09 +0200 Subject: [PATCH] Refactor python part to publish on pypi + automate pypi publication --- .github/workflows/cicd_release.yml | 41 +++++++++++++++++-- .gitignore | 1 + Dockerfile | 3 +- README.md | 2 +- environment.yml | 2 + {macro => pdal_ign_macro}/__init__.py | 0 {macro => pdal_ign_macro}/macro.py | 0 ...e_for_digital_models_with_new_dimension.py | 8 ++-- ...assign_classification_for_digital_model.py | 2 +- {macro => pdal_ign_macro}/version.py | 0 pyproject.toml | 10 ++++- ...e_for_digital_models_with_new_dimension.py | 8 +++- 12 files changed, 63 insertions(+), 14 deletions(-) rename {macro => pdal_ign_macro}/__init__.py (100%) rename {macro => pdal_ign_macro}/macro.py (100%) rename {scripts => pdal_ign_macro}/mark_points_to_use_for_digital_models_with_new_dimension.py (96%) rename scripts/ex_filtering_points.py => pdal_ign_macro/reassign_classification_for_digital_model.py (99%) rename {macro => pdal_ign_macro}/version.py (100%) rename test/{scripts => pdal_ign_macro}/test_mark_points_to_use_for_digital_models_with_new_dimension.py (69%) diff --git a/.github/workflows/cicd_release.yml b/.github/workflows/cicd_release.yml index b328ae8..1e9df94 100644 --- a/.github/workflows/cicd_release.yml +++ b/.github/workflows/cicd_release.yml @@ -6,13 +6,48 @@ on: - "v*.*.*" jobs: - build: + release-github: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Release + - name: Release on github uses: softprops/action-gh-release@v2 with: generate_release_notes: true - make_latest: true \ No newline at end of file + make_latest: true + + deploy-pypi: + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/pdal-ign-macro/ + permissions: + contents: read + packages: write + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + + steps: + - name: Checkout branch + uses: actions/checkout@v4 + + # See https://github.com/marketplace/actions/setup-micromamba + - name: setup-micromamba + uses: mamba-org/setup-micromamba@v1.9.0 + with: + environment-file: environment.yml + environment-name: pdal_ign_plugin # activate the environment + cache-environment: true + cache-downloads: true + generate-run-shell: true + + - name: Build pip package + shell: micromamba-shell {0} + run: | + rm -rf tmp + rm -rf pdal_ign_macro.egg-info + rm -rf dist + python -m build + + - name: pypi-publish + uses: pypa/gh-action-pypi-publish@v1.9.0 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 87156dd..4410299 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ xcode .vscode build install +dist # all pycache directories __pycache__ diff --git a/Dockerfile b/Dockerfile index f082bce..730b11c 100755 --- a/Dockerfile +++ b/Dockerfile @@ -23,11 +23,10 @@ ENV PROJ_LIB=/opt/conda/envs/pdal_ign_plugin/share/proj/ ENV PDAL_DRIVER_PATH=/pdal_ign_plugin/install/lib # Install python macro module -COPY macro /pdal_ign_plugin/macro +COPY pdal_ign_macro /pdal_ign_plugin/pdal_ign_macro COPY pyproject.toml /pdal_ign_plugin/pyproject.toml WORKDIR /pdal_ign_plugin RUN pip install . # Add example scripts + test data (to be able to test inside the docker image) -COPY scripts /pdal_ign_plugin/scripts COPY test /pdal_ign_plugin/test diff --git a/README.md b/README.md index 553ed59..8b1e758 100755 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ docker image. ### Syntax to use it in a python script ```python -from macro import macro +from pdal_ign_macro import macro marco.my_macro(...) ``` diff --git a/environment.yml b/environment.yml index 9182325..64da390 100755 --- a/environment.yml +++ b/environment.yml @@ -13,6 +13,8 @@ dependencies: - isort # import sorting - flake8 # code analysis - pytest + - build + - twine # --------- pip & pip libraries --------- # - pip - pip: diff --git a/macro/__init__.py b/pdal_ign_macro/__init__.py similarity index 100% rename from macro/__init__.py rename to pdal_ign_macro/__init__.py diff --git a/macro/macro.py b/pdal_ign_macro/macro.py similarity index 100% rename from macro/macro.py rename to pdal_ign_macro/macro.py diff --git a/scripts/mark_points_to_use_for_digital_models_with_new_dimension.py b/pdal_ign_macro/mark_points_to_use_for_digital_models_with_new_dimension.py similarity index 96% rename from scripts/mark_points_to_use_for_digital_models_with_new_dimension.py rename to pdal_ign_macro/mark_points_to_use_for_digital_models_with_new_dimension.py index de13703..a57c1c2 100755 --- a/scripts/mark_points_to_use_for_digital_models_with_new_dimension.py +++ b/pdal_ign_macro/mark_points_to_use_for_digital_models_with_new_dimension.py @@ -2,7 +2,7 @@ import pdal -from macro import macro +from pdal_ign_macro import macro """ This tool applies a pdal pipeline to select points for DSM and DTM calculation @@ -42,7 +42,9 @@ def parse_args(): return parser.parse_args() -def main(input_las, output_las, dsm_dimension, dtm_dimension, output_dsm, output_dtm): +def mark_points_to_use_for_digital_models_with_new_dimension( + input_las, output_las, dsm_dimension, dtm_dimension, output_dsm, output_dtm +): pipeline = pdal.Pipeline() | pdal.Reader.las(input_las) # 0 - ajout de dimensions temporaires et de sortie @@ -192,4 +194,4 @@ def main(input_las, output_las, dsm_dimension, dtm_dimension, output_dsm, output if __name__ == "__main__": args = parse_args() - main(**vars(args)) + mark_points_to_use_for_digital_models_with_new_dimension(**vars(args)) diff --git a/scripts/ex_filtering_points.py b/pdal_ign_macro/reassign_classification_for_digital_model.py similarity index 99% rename from scripts/ex_filtering_points.py rename to pdal_ign_macro/reassign_classification_for_digital_model.py index 37987c9..be3f13a 100755 --- a/scripts/ex_filtering_points.py +++ b/pdal_ign_macro/reassign_classification_for_digital_model.py @@ -2,7 +2,7 @@ import pdal -from macro import macro +from pdal_ign_macro import macro """ This tool shows how to use functions of macro in a pdal pipeline diff --git a/macro/version.py b/pdal_ign_macro/version.py similarity index 100% rename from macro/version.py rename to pdal_ign_macro/version.py diff --git a/pyproject.toml b/pyproject.toml index 165ffe3..cef05a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,19 @@ [project] name = "pdal_ign_macro" dynamic = ["version"] +readme = "README.md" +description = "Macros and pipelines for Pdal based on the https://github.com/IGNF/pdal-ign-plugin plugin" dependencies = [] +authors = [ + { name = "Antoine Lavenant", email = "antoine.lavenant@ign.fr" }, + { name = "Léa Vauchier", email = "lea.vauchier@ign.fr" }, +] [tool.setuptools.dynamic] -version = { attr = "macro.version.__version__" } +version = { attr = "pdal_ign_macro.version.__version__" } [tool.setuptools] -packages = ["macro"] +packages = ["pdal_ign_macro"] [tool.black] line-length = 99 diff --git a/test/scripts/test_mark_points_to_use_for_digital_models_with_new_dimension.py b/test/pdal_ign_macro/test_mark_points_to_use_for_digital_models_with_new_dimension.py similarity index 69% rename from test/scripts/test_mark_points_to_use_for_digital_models_with_new_dimension.py rename to test/pdal_ign_macro/test_mark_points_to_use_for_digital_models_with_new_dimension.py index 570d247..d66a811 100644 --- a/test/scripts/test_mark_points_to_use_for_digital_models_with_new_dimension.py +++ b/test/pdal_ign_macro/test_mark_points_to_use_for_digital_models_with_new_dimension.py @@ -3,7 +3,9 @@ import numpy as np import pdal -from scripts.mark_points_to_use_for_digital_models_with_new_dimension import main +from pdal_ign_macro.mark_points_to_use_for_digital_models_with_new_dimension import ( + mark_points_to_use_for_digital_models_with_new_dimension, +) def test_main(): @@ -11,7 +13,9 @@ def test_main(): dsm_dimension = "dsm_marker" dtm_dimension = "dtm_marker" with tempfile.NamedTemporaryFile(suffix="_mark_points_output.las") as las_output: - main(ini_las, las_output.name, dsm_dimension, dtm_dimension, "", "") + mark_points_to_use_for_digital_models_with_new_dimension( + ini_las, las_output.name, dsm_dimension, dtm_dimension, "", "" + ) pipeline = pdal.Pipeline() pipeline |= pdal.Reader.las(las_output.name) assert dsm_dimension in pipeline.quickinfo["readers.las"]["dimensions"].split(", ")