From ffd5f224135536f22dfe09ce43fdffa86c31f095 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 09:55:05 +0200 Subject: [PATCH 01/19] FEAT: add ansys-api-template --- .github/workflows/templates_python.yml | 48 +++++++----- src/ansys/templates/__init__.py | 1 + src/ansys/templates/cli.py | 6 ++ .../python/ansys_api/.github/workflows/ci.yml | 76 +++++++++++++++++++ .../templates/python/ansys_api/README.md | 63 +++++++++++++++ .../templates/python/ansys_api/pyproject.toml | 3 + src/ansys/templates/python/ansys_api/setup.py | 50 ++++++++++++ 7 files changed, 226 insertions(+), 21 deletions(-) create mode 100644 src/ansys/templates/python/ansys_api/.github/workflows/ci.yml create mode 100644 src/ansys/templates/python/ansys_api/README.md create mode 100644 src/ansys/templates/python/ansys_api/pyproject.toml create mode 100644 src/ansys/templates/python/ansys_api/setup.py diff --git a/.github/workflows/templates_python.yml b/.github/workflows/templates_python.yml index db54be81d..b13661f36 100644 --- a/.github/workflows/templates_python.yml +++ b/.github/workflows/templates_python.yml @@ -8,6 +8,9 @@ on: - main workflow_dispatch: +env: + MAIN_PYTHON_VERSION: '3.8' + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -32,29 +35,32 @@ jobs: cfg: # All pybasic template tests - - {name: "doc-project", template: "doc-project", build-system: "flit", outdir: "doc_proje0/doc-project"} - - {name: "doc-project", template: "doc-project", build-system: "poetry", outdir: "doc_proje1/doc-project"} - - {name: "doc-project", template: "doc-project", build-system: "setuptools", outdir: "doc_proje2/doc-project"} + # - {name: "doc-project", template: "doc-project", build-system: "flit", outdir: "doc_proje0/doc-project"} + # - {name: "doc-project", template: "doc-project", build-system: "poetry", outdir: "doc_proje1/doc-project"} + # - {name: "doc-project", template: "doc-project", build-system: "setuptools", outdir: "doc_proje2/doc-project"} - # All pybasic template tests - - {name: "pybasic", template: "pybasic", build-system: "setuptools", outdir: "pybasic_s0/pybasic"} + # # All pybasic template tests + # - {name: "pybasic", template: "pybasic", build-system: "setuptools", outdir: "pybasic_s0/pybasic"} - # All pybasic template tests - - {name: "pyansys", template: "pyansys", build-system: "setuptools", outdir: "pyansys_s0/pyproduct-library"} + # # All pybasic template tests + # - {name: "pyansys", template: "pyansys", build-system: "setuptools", outdir: "pyansys_s0/pyproduct-library"} + + # # # All pyansys_advanced template tests + # - {name: "pyansys-advanced-flit", template: "pyansys-advanced", build-system: "flit", outdir: "pyansys_a0/pyproduct-library"} + # - {name: "pyansys-advanced-poetry", template: "pyansys-advanced", build-system: "poetry", outdir: "pyansys_a1/pyproduct-library"} + # - {name: "pyansys-advanced-setuptools", template: "pyansys-advanced", build-system: "setuptools", outdir: "pyansys_a2/pyproduct-library"} - # # All pyansys_advanced template tests - - {name: "pyansys-advanced-flit", template: "pyansys-advanced", build-system: "flit", outdir: "pyansys_a0/pyproduct-library"} - - {name: "pyansys-advanced-poetry", template: "pyansys-advanced", build-system: "poetry", outdir: "pyansys_a1/pyproduct-library"} - - {name: "pyansys-advanced-setuptools", template: "pyansys-advanced", build-system: "setuptools", outdir: "pyansys_a2/pyproduct-library"} + # # All ansys API templates + - {name: "ansys-api", template: "ansys-api", build-system: "setuptools", outdir: "ansys_api_s0/pyproduct-library"} - # # All pyace template tests - - {name: "pyace-pkg", template: "pyace", build-system: "setuptools", outdir: "pyace_set0/project"} - - {name: "pyace-flask", template: "pyace-flask", build-system: "setuptools", outdir: "pyace_fla2/project"} - - {name: "pyace-fast", template: "pyace-fast", build-system: "setuptools", outdir: "pyace_fas2/project"} - - {name: "pyace-grpc", template: "pyace-grpc", build-system: "setuptools", outdir: "pyace_grp2/project"} + # # # All pyace template tests + # - {name: "pyace-pkg", template: "pyace", build-system: "setuptools", outdir: "pyace_set0/project"} + # - {name: "pyace-flask", template: "pyace-flask", build-system: "setuptools", outdir: "pyace_fla2/project"} + # - {name: "pyace-fast", template: "pyace-fast", build-system: "setuptools", outdir: "pyace_fas2/project"} + # - {name: "pyace-grpc", template: "pyace-grpc", build-system: "setuptools", outdir: "pyace_grp2/project"} - # All solution template tests - - {name: "solution", template: "solution", build-system: "poetry", outdir: "solution_1/solution"} + # # All solution template tests + # - {name: "solution", template: "solution", build-system: "poetry", outdir: "solution_1/solution"} fail-fast: false @@ -75,7 +81,7 @@ jobs: tox -e ${{ matrix.toxenv }}-${{ matrix.toxextra }}-template - name: Move baked project to repo again - if: matrix.python-version == '3.8' && github.event_name == 'push' + if: matrix.python-version == env.MAIN_PYTHON_VERSION && github.event_name == 'push' run: | mv "output/test_template_python_${{ matrix.cfg.outdir }}" baked_template # GitHub Apps are not allowed to deal with .github workflows @@ -83,7 +89,7 @@ jobs: ls -a baked_template - name: Create demo branch - if: matrix.python-version == '3.8' && github.event_name == 'push' + if: matrix.python-version == env.MAIN_PYTHON_VERSION && github.event_name == 'push' uses: peterjgrainger/action-create-branch@v2.4.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -91,7 +97,7 @@ jobs: branch: "demo/${{ matrix.cfg.name }}" - name: Publish demo branch - if: matrix.python-version == '3.8' && github.event_name == 'push' + if: matrix.python-version == env.MAIN_PYTHON_VERSION && github.event_name == 'push' uses: s0/git-publish-subdir-action@develop env: REPO: self diff --git a/src/ansys/templates/__init__.py b/src/ansys/templates/__init__.py index ec936e1c5..b778f36da 100644 --- a/src/ansys/templates/__init__.py +++ b/src/ansys/templates/__init__.py @@ -39,6 +39,7 @@ "pybasic": "Create a basic Python Package.", "pyansys": "Create a PyAnsys Python Package project.", "pyansys-advanced": "Create an advanced PyAnsys Python Package project.", + "ansys-api": "Create a new gRPC API definition.", "pyansys-openapi_client": "Create an OpenAPI Client Package project.", "pyace": "Create a Python project for any method developers.", "pyace-flask": "Create a Flask project initialized for any developer.", diff --git a/src/ansys/templates/cli.py b/src/ansys/templates/cli.py index 330c053c8..b1fd83d7a 100644 --- a/src/ansys/templates/cli.py +++ b/src/ansys/templates/cli.py @@ -93,6 +93,12 @@ def pyansys_advanced(): create_project("pyansys-advanced") +@new.command() +def pyansys_advanced(): + """Create a new gRPC API definition.""" + create_project("ansys-api") + + @new.command() def pyansys_openapi_client(): """Create an OpenAPI Client Package project.""" diff --git a/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml b/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml new file mode 100644 index 000000000..0ac626cf3 --- /dev/null +++ b/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml @@ -0,0 +1,76 @@ +name: GitHub CI + +# run only on main branch. This avoids duplicated actions on PRs +on: + pull_request: + push: + tags: + - "*" + branches: + - main + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + - name: Install build requirements + run: | + pip install -U pip + pip install build + - name: Build + run: python -m build + - name: Install + run: pip install dist/*.whl + - name: Test import + run: | + mkdir tmp + cd tmp + python -c "import {{ cookiecutter._dot_package_name }}; print('Sucessfully imported {{ cookiecutter._dot_package_name }}')" + python -c "from {{ cookiecutter._dot_package_name }} import __version__; print(__version__)" + - name: Upload packages + uses: actions/upload-artifact@v2 + with: + name: {{ cookiecutter.project_slug }}-packages + path: dist/ + retention-days: 7 + + Release: + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.10 + + - uses: actions/download-artifact@v2 + + - name: Display structure of downloaded files + run: ls -R + + # uncomment the following section to permit upload to public PyPI + + # - name: Upload to Public PyPi + # run: | + # pip install twine + # twine upload --skip-existing ./**/*.whl + # twine upload --skip-existing ./**/*.tar.gz + # env: + # TWINE_USERNAME: __token__ + # TWINE_PASSWORD: {% raw %}${{ secrets.PYPI_TOKEN }} {% endraw %} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + files: | + ./**/*.whl + ./**/*.tar.gz + ./**/*.pdf diff --git a/src/ansys/templates/python/ansys_api/README.md b/src/ansys/templates/python/ansys_api/README.md new file mode 100644 index 000000000..2dd418dbb --- /dev/null +++ b/src/ansys/templates/python/ansys_api/README.md @@ -0,0 +1,63 @@ +### {{ cookiecutter.project_slug }} gRPC Interface Package + +This Python package contains the auto-generated gRPC Python interface files for +{{ cookiecutter.product_name }}. + + +#### Installation + +Provided that these wheels have been published to public PyPI, they can be +installed with: + +``` +pip install {{ cookiecutter.project_slug | lower }} +``` + +Otherwise, see the + + +#### Build + +To build the gRPC packages, run: + +``` +pip install build +python -m build +``` + +This will create both the source distribution containing just the protofiles +along with the wheel containing the protofiles and build Python interface +files. + +Note that the interface files are identical regardless of the version of Python +used to generate them, but the last pre-built wheel for ``grpcio~=1.17`` was +Python 3.7, so to improve your build time, use Python 3.7 when building the +wheel. + + +#### Manual Deployment + +After building the packages, manually deploy them with: + +``` +pip install twine +twine upload dist/* +``` + +Note that this is automatically done through CI/CD. + + +#### Automatic Deployment + +This repository contains GitHub CI/CD that enables the automatic building of +source and wheel packages for these gRPC Python interface files. By default, +these are built on PRs, the main branch, and on tags when pushing. Artifacts +are uploaded for each PR. + +To publicly release wheels to PyPI, ensure your branch is up-to-date and then +push tags. For example, for the version ``v0.5.0``. + +```bash +git tag v0.5.0 +git push --tags +``` diff --git a/src/ansys/templates/python/ansys_api/pyproject.toml b/src/ansys/templates/python/ansys_api/pyproject.toml new file mode 100644 index 000000000..81deed0b5 --- /dev/null +++ b/src/ansys/templates/python/ansys_api/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools >= 42.0.0", "wheel", "ansys_tools_protoc_helper"{% for mod in cookiecutter.proto_dependencies['modules'] %}, "{{ mod }}"{% endfor %}] +build-backend = "setuptools.build_meta:__legacy__" diff --git a/src/ansys/templates/python/ansys_api/setup.py b/src/ansys/templates/python/ansys_api/setup.py new file mode 100644 index 000000000..e26275f47 --- /dev/null +++ b/src/ansys/templates/python/ansys_api/setup.py @@ -0,0 +1,50 @@ +"""Installation file for the {{ cookiecutter.project_slug }} package""" + +import os +from datetime import datetime + +import setuptools + +from ansys.tools.protoc_helper import CMDCLASS_OVERRIDE + +# Get the long description from the README file +HERE = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(HERE, "README.md"), encoding="utf-8") as f: + long_description = f.read() + +product = "{{ cookiecutter.product_name | slugify(separator='_') }}" +library = "{{ cookiecutter.library_name | slugify(separator='_') }}" +package_info = ["ansys", "api", product, library, "v{{ cookiecutter.api_version }}"] +with open(os.path.join(HERE, "src", "ansys", "api", product, library, "VERSION"), encoding="utf-8") as f: + version = f.read().strip() + +package_name = "{{ cookiecutter.project_slug | lower }}" +dot_package_name = '.'.join(filter(None, package_info)) + +description = f"Autogenerated python gRPC interface package for {package_name}, built on {datetime.now().strftime('%H:%M:%S on %d %B %Y')}" + +if __name__ == "__main__": + setuptools.setup( + name=package_name, + version=version, + author="ANSYS, Inc.", + author_email='support@ansys.com', + description=description, + long_description=long_description, + long_description_content_type='text/markdown', + url=f"https://github.com/ansys/{package_name}", + license="MIT", + python_requires=">=3.7", + install_requires=["grpcio~=1.17", "protobuf~=3.19"{% for mod in cookiecutter.proto_dependencies['modules'] %}, "{{ mod }}"{% endfor %}], + package_dir = {"": "src"}, + packages=setuptools.find_namespace_packages("src", include=("ansys.*",)), + package_data={ + "": ["*.proto", "*.pyi", "py.typed", "VERSION"], + }, + entry_points={ + "ansys.tools.protoc_helper.proto_provider": [ + f"{dot_package_name}={dot_package_name}" + ], + }, + cmdclass=CMDCLASS_OVERRIDE + ) From 4abe1e094ae0c437d08cb5017e151504d2562e8b Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 10:17:53 +0200 Subject: [PATCH 02/19] FEAT: add template to path --- src/ansys/templates/paths.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ansys/templates/paths.py b/src/ansys/templates/paths.py index 6e5bcc267..828513f71 100644 --- a/src/ansys/templates/paths.py +++ b/src/ansys/templates/paths.py @@ -48,6 +48,9 @@ PYTHON_TEMPLATES_PYANSYS_ADVANCED_PATH = PYTHON_TEMPLATES_PATH / "pyansys_advanced" """Path to the advanced PyAnsys Python Package template.""" +PYTHON_TEMPLATES_ANSYS_API_PATH = PYTHON_TEMPLATES_PATH / "ansys_api" +"""Path to the Ansys API Python Package template.""" + PYTHON_TEMPLATES_PYANSYS_OPENAPI_CLIENT_PATH = PYTHON_TEMPLATES_PATH / "pyansys_openapi_client" """Path to the PyAnsys OpenAPI Client Package template.""" @@ -79,6 +82,7 @@ "pybasic": PYTHON_TEMPLATES_PYBASIC_PATH, "pyansys": PYTHON_TEMPLATES_PYANSYS_PATH, "pyansys-advanced": PYTHON_TEMPLATES_PYANSYS_ADVANCED_PATH, + "ansys-api": PYTHON_TEMPLATES_ANSYS_API_PATH, "pyansys-openapi-client": PYTHON_TEMPLATES_PYANSYS_OPENAPI_CLIENT_PATH, "pyace": PYTHON_TEMPLATES_PYACE_PATH, "pyace-grpc": PYTHON_TEMPLATES_PYACE_GRPC_PATH, From 20ba0e669f28212de8bfec7b27e8d2fabe7ed94c Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 10:32:39 +0200 Subject: [PATCH 03/19] FEAT: add template to path --- src/ansys/templates/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/templates/cli.py b/src/ansys/templates/cli.py index b1fd83d7a..77269341e 100644 --- a/src/ansys/templates/cli.py +++ b/src/ansys/templates/cli.py @@ -94,7 +94,7 @@ def pyansys_advanced(): @new.command() -def pyansys_advanced(): +def ansys_api(): """Create a new gRPC API definition.""" create_project("ansys-api") From 2b16926be7600b740c311e2c069315cab17d86ba Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 10:47:14 +0200 Subject: [PATCH 04/19] FEAT: add template and hooks --- .../python/ansys_api/cookiecutter.json | 14 ++++++ .../ansys_api/hooks/post_gen_project.py | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/ansys/templates/python/ansys_api/cookiecutter.json create mode 100644 src/ansys/templates/python/ansys_api/hooks/post_gen_project.py diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json new file mode 100644 index 000000000..25417cc1b --- /dev/null +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -0,0 +1,14 @@ +{ + "product_name": "", + "library_name": "", + "project_slug": "ansys-api-{{ '-'.join([cookiecutter.product_name, cookiecutter.library_name]) | slugify }}", + "api_version": "0", + "_dot_package_name_no_ver": "ansys.api.{{ cookiecutter.product_name | slugify(separator='_') }}.{{ cookiecutter.library_name | slugify(separator='_') }}", + "_dot_package_name": "{{ cookiecutter._dot_package_name_no_ver }}.v{{ cookiecutter.api_version }}", + "api_package_version": "0.1.0", + "protos_dir": "", + "proto_dependencies": { + "modules": [] + }, + "_extensions": ["cookiecutter.extensions.SlugifyExtension"] +} diff --git a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py new file mode 100644 index 000000000..dab33246e --- /dev/null +++ b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py @@ -0,0 +1,49 @@ +"""Hook to copy the .proto files into the project, and create __init__.py and py.typed files.""" + +import os +import pathlib +import shutil +import sys + +PROTOS_DIR = "{{ cookiecutter.protos_dir }}" + +DEST_PATH = ( + pathlib.Path("src") + / "ansys" + / "api" + / "{{ cookiecutter.product_name | slugify(separator='_') }}" + / "{{ cookiecutter.library_name | slugify(separator='_') }}" +) +VERSION_DEST_PATH = DEST_PATH / "v{{ cookiecutter.api_version }}" + +init_content = """\ +\"\"\"Autogenerated Python gRPC interface package for {{ cookiecutter.project_slug }}.\"\"\" + +import pathlib + +__all__ = ["__version__"] + +with open(pathlib.Path(__file__).parent / "VERSION", encoding="utf-8") as f: + __version__ = f.read().strip() +""" + +if PROTOS_DIR: + source_path = pathlib.Path(PROTOS_DIR) + + if not source_path.is_dir(): + print(f"ERROR: Path '{source_path}' does not exist.") + sys.exit(1) + + shutil.copytree(source_path, VERSION_DEST_PATH) +else: + os.makedirs(VERSION_DEST_PATH) + print( + "\nNOTE: No protos directory specified. Make sure to manually " + f"copy the .proto files to '{VERSION_DEST_PATH.absolute()}'." + ) + +with open(DEST_PATH / "__init__.py", mode="w", encoding="utf-8") as out_f: + out_f.write(init_content) +(DEST_PATH / "py.typed").touch() +with open(DEST_PATH / "VERSION", mode="w", encoding="utf-8") as out_f: + out_f.write("{{ cookiecutter.api_package_version }}") From 45f18591e44013adc2398ba58657b8eb21eff9f7 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 11:04:47 +0200 Subject: [PATCH 05/19] FIX: cookiecutter vars --- src/ansys/templates/python/ansys_api/cookiecutter.json | 2 +- .../{ => {{ cookiecutter.__project_name_slug }}}/README.md | 4 ++-- .../pyproject.toml | 0 .../{ => {{ cookiecutter.__project_name_slug }}}/setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/ansys/templates/python/ansys_api/{ => {{ cookiecutter.__project_name_slug }}}/README.md (91%) rename src/ansys/templates/python/ansys_api/{ => {{ cookiecutter.__project_name_slug }}}/pyproject.toml (100%) rename src/ansys/templates/python/ansys_api/{ => {{ cookiecutter.__project_name_slug }}}/setup.py (96%) diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json index 25417cc1b..64ee58506 100644 --- a/src/ansys/templates/python/ansys_api/cookiecutter.json +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -1,7 +1,7 @@ { "product_name": "", "library_name": "", - "project_slug": "ansys-api-{{ '-'.join([cookiecutter.product_name, cookiecutter.library_name]) | slugify }}", + "__project_name_slug": "ansys-api-{{ '-'.join([cookiecutter.product_name, cookiecutter.library_name]) | slugify }}", "api_version": "0", "_dot_package_name_no_ver": "ansys.api.{{ cookiecutter.product_name | slugify(separator='_') }}.{{ cookiecutter.library_name | slugify(separator='_') }}", "_dot_package_name": "{{ cookiecutter._dot_package_name_no_ver }}.v{{ cookiecutter.api_version }}", diff --git a/src/ansys/templates/python/ansys_api/README.md b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/README.md similarity index 91% rename from src/ansys/templates/python/ansys_api/README.md rename to src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/README.md index 2dd418dbb..6653ddf33 100644 --- a/src/ansys/templates/python/ansys_api/README.md +++ b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/README.md @@ -1,4 +1,4 @@ -### {{ cookiecutter.project_slug }} gRPC Interface Package +### {{ cookiecutter.__project_name_slug }} gRPC Interface Package This Python package contains the auto-generated gRPC Python interface files for {{ cookiecutter.product_name }}. @@ -10,7 +10,7 @@ Provided that these wheels have been published to public PyPI, they can be installed with: ``` -pip install {{ cookiecutter.project_slug | lower }} +pip install {{ cookiecutter.__project_name_slug | lower }} ``` Otherwise, see the diff --git a/src/ansys/templates/python/ansys_api/pyproject.toml b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/pyproject.toml similarity index 100% rename from src/ansys/templates/python/ansys_api/pyproject.toml rename to src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/pyproject.toml diff --git a/src/ansys/templates/python/ansys_api/setup.py b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py similarity index 96% rename from src/ansys/templates/python/ansys_api/setup.py rename to src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py index e26275f47..d681dfc32 100644 --- a/src/ansys/templates/python/ansys_api/setup.py +++ b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py @@ -18,7 +18,7 @@ with open(os.path.join(HERE, "src", "ansys", "api", product, library, "VERSION"), encoding="utf-8") as f: version = f.read().strip() -package_name = "{{ cookiecutter.project_slug | lower }}" +package_name = "{{ cookiecutter.__project_name_slug | lower }}" dot_package_name = '.'.join(filter(None, package_info)) description = f"Autogenerated python gRPC interface package for {package_name}, built on {datetime.now().strftime('%H:%M:%S on %d %B %Y')}" From 1368f8f315bd54490125c5a2c9a98f7c95034a7b Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 11:40:02 +0200 Subject: [PATCH 06/19] FIX: cookiecutter.json --- .../templates/python/ansys_api/cookiecutter.json | 14 ++++++++++---- .../setup.py | 13 +++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json index 64ee58506..30785d35a 100644 --- a/src/ansys/templates/python/ansys_api/cookiecutter.json +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -1,11 +1,17 @@ { "product_name": "", + "__product_name_slug": "{{ cookiecutter.product_name | slugify(separator=('_')) }}", "library_name": "", - "__project_name_slug": "ansys-api-{{ '-'.join([cookiecutter.product_name, cookiecutter.library_name]) | slugify }}", + "__library_name_slug": "{{ cookiecutter.library_name | slugify(separator=('_')) }}", + "__project_name_slug": "ansys-api-{{ cookiecutter.__product_name_slug }}{% if cookiecutter.__library_name_slug %}-{{ cookiecutter.__library_name_slug }}{% endif %}", "api_version": "0", - "_dot_package_name_no_ver": "ansys.api.{{ cookiecutter.product_name | slugify(separator='_') }}.{{ cookiecutter.library_name | slugify(separator='_') }}", - "_dot_package_name": "{{ cookiecutter._dot_package_name_no_ver }}.v{{ cookiecutter.api_version }}", - "api_package_version": "0.1.0", + "__api_version": "{{ cookiecutter.api_version }}", + "__pkg_namespace": "ansys.{{ cookiecutter.__product_name_slug }}.{{ cookiecutter.__library_name_slug }}", + "__pkg_namespace_with_version": "{{ cookiecutter.__pkg_namespace}}-v{{ cookiecutter.__api_version }}", + "version": "0.1.dev0", + "__version": "{{ cookiecutter.version }}", + "short_description": "A collection of gRPC API definitions for Ansys {{ cookiecutter.product_name }} {{ cookiecutter.library_name }}", + "__short_description": "{{ cookiecutter.short_description | capitalize }}", "protos_dir": "", "proto_dependencies": { "modules": [] diff --git a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py index d681dfc32..182543428 100644 --- a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py +++ b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/setup.py @@ -1,4 +1,4 @@ -"""Installation file for the {{ cookiecutter.project_slug }} package""" +"""Installation file for the {{ cookiecutter.__project_name_slug }} package""" import os from datetime import datetime @@ -12,13 +12,13 @@ with open(os.path.join(HERE, "README.md"), encoding="utf-8") as f: long_description = f.read() -product = "{{ cookiecutter.product_name | slugify(separator='_') }}" -library = "{{ cookiecutter.library_name | slugify(separator='_') }}" -package_info = ["ansys", "api", product, library, "v{{ cookiecutter.api_version }}"] +product = "{{ cookiecutter.__product_name_slug }}" +library = "{{ cookiecutter.__library_name_slug }}" +package_info = ["ansys", "api", product, library, "v{{ cookiecutter.__api_version }}"] with open(os.path.join(HERE, "src", "ansys", "api", product, library, "VERSION"), encoding="utf-8") as f: version = f.read().strip() -package_name = "{{ cookiecutter.__project_name_slug | lower }}" +package_name = "{{ cookiecutter.__project_name_slug }}" dot_package_name = '.'.join(filter(None, package_info)) description = f"Autogenerated python gRPC interface package for {package_name}, built on {datetime.now().strftime('%H:%M:%S on %d %B %Y')}" @@ -28,8 +28,9 @@ name=package_name, version=version, author="ANSYS, Inc.", - author_email='support@ansys.com', + author_email='pyansys.core@ansys.com', description=description, + short_description="{{ cookiecutter.__short_description }}", long_description=long_description, long_description_content_type='text/markdown', url=f"https://github.com/ansys/{package_name}", From c5c91e92a7d2c6c83733c4c8195a31be4fb6cb33 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 11:48:29 +0200 Subject: [PATCH 07/19] FEAT: working template --- .../python/ansys_api/hooks/post_gen_project.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py index dab33246e..483a929b1 100644 --- a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py +++ b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py @@ -11,13 +11,13 @@ pathlib.Path("src") / "ansys" / "api" - / "{{ cookiecutter.product_name | slugify(separator='_') }}" - / "{{ cookiecutter.library_name | slugify(separator='_') }}" + / "{{ cookiecutter.__product_name_slug }}" + / "{{ cookiecutter.__library_name_slug }}" ) -VERSION_DEST_PATH = DEST_PATH / "v{{ cookiecutter.api_version }}" +VERSION_DEST_PATH = DEST_PATH / "v{{ cookiecutter.__api_version }}" init_content = """\ -\"\"\"Autogenerated Python gRPC interface package for {{ cookiecutter.project_slug }}.\"\"\" +\"\"\"Autogenerated Python gRPC interface package for {{ cookiecutter.__project_name_slug }}.\"\"\" import pathlib @@ -46,4 +46,4 @@ out_f.write(init_content) (DEST_PATH / "py.typed").touch() with open(DEST_PATH / "VERSION", mode="w", encoding="utf-8") as out_f: - out_f.write("{{ cookiecutter.api_package_version }}") + out_f.write("{{ cookiecutter.__version }}") From 95f22264d55db7012a00f35947ca54b8a9dcd4d7 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 15:35:09 +0200 Subject: [PATCH 08/19] FIX: template rendering --- .../ansys_api/hooks/post_gen_project.py | 72 +++++++------------ .../VERSION | 0 .../__init__.py | 8 +++ .../py.typed | 0 .../python/pybasic/hooks/post_gen_project.py | 32 ++------- 5 files changed, 38 insertions(+), 74 deletions(-) create mode 100644 src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/VERSION create mode 100644 src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/__init__.py create mode 100644 src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/py.typed diff --git a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py index 483a929b1..76166f77f 100644 --- a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py +++ b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py @@ -1,49 +1,27 @@ """Hook to copy the .proto files into the project, and create __init__.py and py.typed files.""" -import os -import pathlib -import shutil -import sys - -PROTOS_DIR = "{{ cookiecutter.protos_dir }}" - -DEST_PATH = ( - pathlib.Path("src") - / "ansys" - / "api" - / "{{ cookiecutter.__product_name_slug }}" - / "{{ cookiecutter.__library_name_slug }}" -) -VERSION_DEST_PATH = DEST_PATH / "v{{ cookiecutter.__api_version }}" - -init_content = """\ -\"\"\"Autogenerated Python gRPC interface package for {{ cookiecutter.__project_name_slug }}.\"\"\" - -import pathlib - -__all__ = ["__version__"] - -with open(pathlib.Path(__file__).parent / "VERSION", encoding="utf-8") as f: - __version__ = f.read().strip() -""" - -if PROTOS_DIR: - source_path = pathlib.Path(PROTOS_DIR) - - if not source_path.is_dir(): - print(f"ERROR: Path '{source_path}' does not exist.") - sys.exit(1) - - shutil.copytree(source_path, VERSION_DEST_PATH) -else: - os.makedirs(VERSION_DEST_PATH) - print( - "\nNOTE: No protos directory specified. Make sure to manually " - f"copy the .proto files to '{VERSION_DEST_PATH.absolute()}'." - ) - -with open(DEST_PATH / "__init__.py", mode="w", encoding="utf-8") as out_f: - out_f.write(init_content) -(DEST_PATH / "py.typed").touch() -with open(DEST_PATH / "VERSION", mode="w", encoding="utf-8") as out_f: - out_f.write("{{ cookiecutter.__version }}") +from ansys.templates.utils import keep_files + +src_path = "src/ansys/api/{{ cookiecutter.__product_name_slug }}" + +if "{{ cookiecutter.__library_name_slug }}" != "": + src_path += "/{{ cookiecutter.__library_name_slug }}" + +DESIRED_STRUCTURE = [ + "README.md", + "pyproject.toml", + "setup.py", + f"{src_path}/__init__.py", + f"{src_path}/VERSION", + f"{src_path}/py.typed", + f"{src_path}/v0", +] +"""A list holding all desired files to be included in the project.""" + +def main(): + """Entry point of the script.""" + # Apply the desired structure to the project + keep_files(DESIRED_STRUCTURE) + +if __name__ == "__main__": + main() diff --git a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/VERSION b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/VERSION new file mode 100644 index 000000000..e69de29bb diff --git a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/__init__.py b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/__init__.py new file mode 100644 index 000000000..5a4b1eb4b --- /dev/null +++ b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/__init__.py @@ -0,0 +1,8 @@ +"""Autogenerated Python gRPC interface package for {{ cookiecutter.__project_name_slug }}.""" + +import pathlib + +__all__ = ["__version__"] + +with open(pathlib.Path(__file__).parent / "VERSION", encoding="utf-8") as f: + __version__ = f.read().strip() diff --git a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/py.typed b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/src/ansys/api/{{ cookiecutter.__product_name_slug }}/{{ cookiecutter.__library_name_slug }}/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/src/ansys/templates/python/pybasic/hooks/post_gen_project.py b/src/ansys/templates/python/pybasic/hooks/post_gen_project.py index 956951e9e..184879eb8 100644 --- a/src/ansys/templates/python/pybasic/hooks/post_gen_project.py +++ b/src/ansys/templates/python/pybasic/hooks/post_gen_project.py @@ -1,38 +1,16 @@ from ansys.templates.utils import keep_files - DESIRED_STRUCTURE = [ - ".coveragerc", - "CHANGELOG.md", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.md", - "doc/Makefile", - "doc/make.bat", - "doc/.vale.ini", - "doc/styles/.gitignore", - "doc/styles/Vocab/ANSYS/accept.txt", - "doc/styles/Vocab/ANSYS/reject.txt", - "doc/source/conf.py", - "doc/source/index.rst", - "doc/source/_static/README.md", - "doc/source/_templates/README.md", - "examples/README.md", - ".flake8", - ".gitattributes", - ".gitignore", - "LICENSE", + "README.md", "pyproject.toml", - "README.rst", - "requirements_build.txt", - "requirements_doc.txt", - "requirements_tests.txt", "setup.py", - "src/{{ cookiecutter.__project_name_slug }}/__init__.py", - "tests/test_metadata.py", + "src/ansys/api/{{ cookiecutter.__project_name_slug }}/__init__.py", + "src/ansys/api/{{ cookiecutter.__project_name_slug }}/VERSION", + "src/ansys/api/{{ cookiecutter.__project_name_slug }}/py.typed", + "src/ansys/api/{{ cookiecutter.__project_name_slug }}/v0", ] """A list holding all desired files to be included in the project.""" - def main(): """Entry point of the script.""" # Apply the desired structure to the project From f954469bcb903f16306763bc391724cd48c0af98 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 16:07:32 +0200 Subject: [PATCH 09/19] FEAT: update actions generation --- .../python/ansys_api/cookiecutter.json | 2 +- .../ansys_api/hooks/post_gen_project.py | 1 + .../.github/workflows/ci.yml | 72 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/.github/workflows/ci.yml diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json index 30785d35a..cda6c62c1 100644 --- a/src/ansys/templates/python/ansys_api/cookiecutter.json +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -6,7 +6,7 @@ "__project_name_slug": "ansys-api-{{ cookiecutter.__product_name_slug }}{% if cookiecutter.__library_name_slug %}-{{ cookiecutter.__library_name_slug }}{% endif %}", "api_version": "0", "__api_version": "{{ cookiecutter.api_version }}", - "__pkg_namespace": "ansys.{{ cookiecutter.__product_name_slug }}.{{ cookiecutter.__library_name_slug }}", + "__pkg_namespace": "ansys.api.{{ cookiecutter.__product_name_slug }}.{{ cookiecutter.__library_name_slug }}", "__pkg_namespace_with_version": "{{ cookiecutter.__pkg_namespace}}-v{{ cookiecutter.__api_version }}", "version": "0.1.dev0", "__version": "{{ cookiecutter.version }}", diff --git a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py index 76166f77f..766bb5ad5 100644 --- a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py +++ b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py @@ -15,6 +15,7 @@ f"{src_path}/VERSION", f"{src_path}/py.typed", f"{src_path}/v0", + ".github/workflows/ci.yml", ] """A list holding all desired files to be included in the project.""" diff --git a/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/.github/workflows/ci.yml b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/.github/workflows/ci.yml new file mode 100644 index 000000000..61682cfdf --- /dev/null +++ b/src/ansys/templates/python/ansys_api/{{ cookiecutter.__project_name_slug }}/.github/workflows/ci.yml @@ -0,0 +1,72 @@ +name: CI + +on: + pull_request: + push: + tags: + - "*" + branches: + - main + +env: + MAIN_PYTHON_VERSION: '3.10' + LIBRARY_NAME: '{{ cookiecutter.__pkg_namespace | replace(".", "-") }}' + LIBRARY_NAMESPACE: '{{ cookiecutter.__pkg_namespace }}' + +concurrency: + group: {{ '${{ github.workflow }}-${{ github.ref }}' }} + cancel-in-progress: true + +jobs: + + tests: + name: "Build package" + runs-on: ubuntu-latest + steps: + + - name: "Checkout repository" + uses: actions/checkout@v3 + + - name: "Setup Python" + uses: actions/setup-python@v4 + with: + python-version: {{ '${{ env.MAIN_PYTHON_VERSION }}' }} + + - name: "Install the library" + run: | + python -m pip install . + + - name: "Test import" + run: | + {{ 'python -c "from ${{ env.LIBRARY_NAMESPACE }} import __version__; print(__version__)"' }} + + build-library: + name: "Build library" + needs: tests + runs-on: ubuntu-latest + steps: + - uses: ansys/actions/build-library@v4 + with: + library-name: {{ '${{ env.LIBRARY_NAME }}' }} + + release: + name: "Release library" + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + needs: build-package + runs-on: ubuntu-latest + steps: + + - name: "Release to the private PyPI" + uses: ansys/actions/release-pypi-private@v4 + with: + library-name: {{ '${{ env.LIBRARY_NAME }}' }} + twine-username: "__token__" + twine-token: {{ '${{ secrets.PYANSYS_PYPI_PRIVATE_PAT }}' }} + + - name: "Release to GitHub" + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + files: | + {{ '${{ env.LIBRARY_NAME }}-artifacts/*.whl }}' }} + {{ '${{ env.LIBRARY_NAME }}-artifacts/*.tar.gz' }} From f3c903f5d336241d315c3d88636c4528b67cdc4c Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 16:20:31 +0200 Subject: [PATCH 10/19] FEAT: add tests --- .../tests_templates/test_python_templates.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/tests_templates/test_python_templates.py b/tests/tests_templates/test_python_templates.py index 8ab6dc7c4..eabb066c9 100644 --- a/tests/tests_templates/test_python_templates.py +++ b/tests/tests_templates/test_python_templates.py @@ -50,6 +50,14 @@ requires_python="3.7", ) +ANSYS_API_VARS = PYANSYS_ADVANCED_VARS = dict( + product_name="product", + library_name="library", + __product_name_slug="product", + __library_name_slug="library", + __project_name_slug="ansys-api-product-library", +) + PYANSYS_OPENAPI_VARS = dict( product_name="product", library_name="library", @@ -145,6 +153,17 @@ ["azure-pipeline.yml", "setup.py", ".coveragerc", "requirements_build.txt", "requirements_doc.txt", "requirements_tests.txt"]] +# Structure for pyansys-advanced projects +ANSYS_API_STRUCTURE = [ + "README.md", + "pyproject.toml", + "setup.py", + f"src/ansys/api/{ANSYS_API_VARS['__product_name_slug']}/{ANSYS_API_VARS['__library_name_slug']}/__init__.py", + f"src/ansys/api/{ANSYS_API_VARS['__product_name_slug']}/{ANSYS_API_VARS['__library_name_slug']}/py.typed", + f"src/ansys/api/{ANSYS_API_VARS['__product_name_slug']}/{ANSYS_API_VARS['__library_name_slug']}/VERSION", + ".github/workflows/ci.yml", +] + PYACE_FLASK_STRUCTURE = deepcopy(PYCOMMON_STRUCTURE) + [ "src/__init__.py", "src/_version.py", @@ -416,6 +435,7 @@ "pybasic": [PYBASIC_VARS, PYBASIC_STRUCTURE], "pyansys": [PYANSYS_VARS, PYANSYS_STRUCTURE], "pyansys-advanced": [PYANSYS_ADVANCED_VARS, PYANSYS_ADVANCED_STRUCTURE], + "ansys-api": [ANSYS_API_VARS, ANSYS_API_STRUCTURE], "pyansys-openapi-client": [PYANSYS_OPENAPI_VARS, PYANSYS_OPENAPI_STRUCTURE], "pyace-flask": [PYACE_VARS, PYACE_FLASK_STRUCTURE], "pyace-grpc": [PYACE_VARS, PYACE_GRPC_STRUCTURE], From 0af79cf4caa4baa5a22a57934fb271443510a478 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 16:23:13 +0200 Subject: [PATCH 11/19] FIX: reset file --- .../python/pybasic/hooks/post_gen_project.py | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/ansys/templates/python/pybasic/hooks/post_gen_project.py b/src/ansys/templates/python/pybasic/hooks/post_gen_project.py index 184879eb8..956951e9e 100644 --- a/src/ansys/templates/python/pybasic/hooks/post_gen_project.py +++ b/src/ansys/templates/python/pybasic/hooks/post_gen_project.py @@ -1,16 +1,38 @@ from ansys.templates.utils import keep_files + DESIRED_STRUCTURE = [ - "README.md", + ".coveragerc", + "CHANGELOG.md", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "doc/Makefile", + "doc/make.bat", + "doc/.vale.ini", + "doc/styles/.gitignore", + "doc/styles/Vocab/ANSYS/accept.txt", + "doc/styles/Vocab/ANSYS/reject.txt", + "doc/source/conf.py", + "doc/source/index.rst", + "doc/source/_static/README.md", + "doc/source/_templates/README.md", + "examples/README.md", + ".flake8", + ".gitattributes", + ".gitignore", + "LICENSE", "pyproject.toml", + "README.rst", + "requirements_build.txt", + "requirements_doc.txt", + "requirements_tests.txt", "setup.py", - "src/ansys/api/{{ cookiecutter.__project_name_slug }}/__init__.py", - "src/ansys/api/{{ cookiecutter.__project_name_slug }}/VERSION", - "src/ansys/api/{{ cookiecutter.__project_name_slug }}/py.typed", - "src/ansys/api/{{ cookiecutter.__project_name_slug }}/v0", + "src/{{ cookiecutter.__project_name_slug }}/__init__.py", + "tests/test_metadata.py", ] """A list holding all desired files to be included in the project.""" + def main(): """Entry point of the script.""" # Apply the desired structure to the project From b53b09a217944100e74731ac7314a8ebf71638ce Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 16:36:14 +0200 Subject: [PATCH 12/19] FIX: void mother variables --- src/ansys/templates/python/ansys_api/cookiecutter.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json index cda6c62c1..aa606b03d 100644 --- a/src/ansys/templates/python/ansys_api/cookiecutter.json +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -1,9 +1,11 @@ { + "__template_name": "ansys-api", "product_name": "", "__product_name_slug": "{{ cookiecutter.product_name | slugify(separator=('_')) }}", "library_name": "", "__library_name_slug": "{{ cookiecutter.library_name | slugify(separator=('_')) }}", "__project_name_slug": "ansys-api-{{ cookiecutter.__product_name_slug }}{% if cookiecutter.__library_name_slug %}-{{ cookiecutter.__library_name_slug }}{% endif %}", + "__pkg_name": "{{ cookiecutter.__project_name_slug }}", "api_version": "0", "__api_version": "{{ cookiecutter.api_version }}", "__pkg_namespace": "ansys.api.{{ cookiecutter.__product_name_slug }}.{{ cookiecutter.__library_name_slug }}", @@ -16,5 +18,13 @@ "proto_dependencies": { "modules": [] }, + "__requires_python": "", + "__repository_url": "", + "__build_system": "", + "__logo": "", + "__logo_color": "", + "__max_linelength": "", + "__coverage_source": "", + "__is_pyansys": "false", "_extensions": ["cookiecutter.extensions.SlugifyExtension"] } From d818b4ffa0bcc2a9b60a4842b51974b1b8f5c795 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 16:54:52 +0200 Subject: [PATCH 13/19] CI: update --- .github/workflows/templates_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/templates_python.yml b/.github/workflows/templates_python.yml index b13661f36..b8c0866bf 100644 --- a/.github/workflows/templates_python.yml +++ b/.github/workflows/templates_python.yml @@ -51,7 +51,7 @@ jobs: # - {name: "pyansys-advanced-setuptools", template: "pyansys-advanced", build-system: "setuptools", outdir: "pyansys_a2/pyproduct-library"} # # All ansys API templates - - {name: "ansys-api", template: "ansys-api", build-system: "setuptools", outdir: "ansys_api_s0/pyproduct-library"} + - {name: "ansys-api", template: "ansys-api", build-system: "setuptools", outdir: "ansys_api2/ansys-api-product-library"} # # # All pyace template tests # - {name: "pyace-pkg", template: "pyace", build-system: "setuptools", outdir: "pyace_set0/project"} From 5db941dd5d3cbbe2bc89a484ad5e93d941371e99 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 17:56:57 +0200 Subject: [PATCH 14/19] CI: update --- .github/workflows/templates_python.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/templates_python.yml b/.github/workflows/templates_python.yml index b8c0866bf..1792bcd88 100644 --- a/.github/workflows/templates_python.yml +++ b/.github/workflows/templates_python.yml @@ -18,7 +18,7 @@ concurrency: jobs: tests: - name: ${{ matrix.cfg.template }} / ${{ matrix.cfg.build-system }} / ${{ matrix.python-version }} + name: "${{ matrix.cfg.template }} / ${{ matrix.cfg.build-system }} / ${{ matrix.python-version }}" runs-on: ubuntu-latest strategy: matrix: @@ -32,7 +32,6 @@ jobs: - python-version: "3.11" toxenv: py311 toxextra: keep-output - cfg: # All pybasic template tests # - {name: "doc-project", template: "doc-project", build-system: "flit", outdir: "doc_proje0/doc-project"} @@ -63,24 +62,25 @@ jobs: # - {name: "solution", template: "solution", build-system: "poetry", outdir: "solution_1/solution"} fail-fast: false - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - name: "Checkout project" + uses: actions/checkout@v3 + + - name: "Set up Python ${{ matrix.python-version }}" uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: "Install dependencies" run: | python -m pip install --upgrade pip tox - - name: Bake ${{ matrix.cfg.template }} + - name: "Bake ${{ matrix.cfg.template }}" run: | export TEMPLATE=${{ matrix.cfg.template }} - tox -e ${{ matrix.toxenv }}-${{ matrix.toxextra }}-template + tox -r -e ${{ matrix.toxenv }}-${{ matrix.toxextra }}-template - - name: Move baked project to repo again + - name: "Move baked project to repo again" if: matrix.python-version == env.MAIN_PYTHON_VERSION && github.event_name == 'push' run: | mv "output/test_template_python_${{ matrix.cfg.outdir }}" baked_template From 18d665015a44f3d29b702f6d38229234b4f73d2e Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 18:08:48 +0200 Subject: [PATCH 15/19] CI: update --- src/ansys/templates/python/ansys_api/cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/templates/python/ansys_api/cookiecutter.json b/src/ansys/templates/python/ansys_api/cookiecutter.json index aa606b03d..132df0cf2 100644 --- a/src/ansys/templates/python/ansys_api/cookiecutter.json +++ b/src/ansys/templates/python/ansys_api/cookiecutter.json @@ -20,7 +20,7 @@ }, "__requires_python": "", "__repository_url": "", - "__build_system": "", + "__build_system": "setuptools", "__logo": "", "__logo_color": "", "__max_linelength": "", From 3fe290499cb2c256362aecdec517af6af8b049b1 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 18:12:33 +0200 Subject: [PATCH 16/19] FIX: remove unrquired folder --- .../python/ansys_api/.github/workflows/ci.yml | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/ansys/templates/python/ansys_api/.github/workflows/ci.yml diff --git a/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml b/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml deleted file mode 100644 index 0ac626cf3..000000000 --- a/src/ansys/templates/python/ansys_api/.github/workflows/ci.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: GitHub CI - -# run only on main branch. This avoids duplicated actions on PRs -on: - pull_request: - push: - tags: - - "*" - branches: - - main - -jobs: - build: - name: Build package - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: "3.7" - - name: Install build requirements - run: | - pip install -U pip - pip install build - - name: Build - run: python -m build - - name: Install - run: pip install dist/*.whl - - name: Test import - run: | - mkdir tmp - cd tmp - python -c "import {{ cookiecutter._dot_package_name }}; print('Sucessfully imported {{ cookiecutter._dot_package_name }}')" - python -c "from {{ cookiecutter._dot_package_name }} import __version__; print(__version__)" - - name: Upload packages - uses: actions/upload-artifact@v2 - with: - name: {{ cookiecutter.project_slug }}-packages - path: dist/ - retention-days: 7 - - Release: - if: github.event_name == 'push' && contains(github.ref, 'refs/tags') - needs: [build] - runs-on: ubuntu-latest - steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.10 - - - uses: actions/download-artifact@v2 - - - name: Display structure of downloaded files - run: ls -R - - # uncomment the following section to permit upload to public PyPI - - # - name: Upload to Public PyPi - # run: | - # pip install twine - # twine upload --skip-existing ./**/*.whl - # twine upload --skip-existing ./**/*.tar.gz - # env: - # TWINE_USERNAME: __token__ - # TWINE_PASSWORD: {% raw %}${{ secrets.PYPI_TOKEN }} {% endraw %} - - - name: Release - uses: softprops/action-gh-release@v1 - with: - generate_release_notes: true - files: | - ./**/*.whl - ./**/*.tar.gz - ./**/*.pdf From 5cf225d4a15a6e595327e03efd846d5720727a6f Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 19:31:32 +0200 Subject: [PATCH 17/19] DBG --- tests/tests_templates/test_python_templates.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/tests_templates/test_python_templates.py b/tests/tests_templates/test_python_templates.py index eabb066c9..e88d0cfe5 100644 --- a/tests/tests_templates/test_python_templates.py +++ b/tests/tests_templates/test_python_templates.py @@ -50,7 +50,7 @@ requires_python="3.7", ) -ANSYS_API_VARS = PYANSYS_ADVANCED_VARS = dict( +ANSYS_API_VARS = dict( product_name="product", library_name="library", __product_name_slug="product", @@ -486,4 +486,6 @@ def test_template_python(tmp_path, build_system, template): keep_files(EXPECTED_STRUCTURE, project_path) # Check that all common files are included in baked project + print(EXPECTED_STRUCTURE) + print(project_path) assert_project_structure(EXPECTED_STRUCTURE, project_path) From bbf534351682b27d3e92d11edac1dd6e9e400347 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 19:43:27 +0200 Subject: [PATCH 18/19] DBG: hooks --- src/ansys/templates/python/ansys_api/hooks/post_gen_project.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py index 766bb5ad5..c0b0c6f76 100644 --- a/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py +++ b/src/ansys/templates/python/ansys_api/hooks/post_gen_project.py @@ -14,7 +14,6 @@ f"{src_path}/__init__.py", f"{src_path}/VERSION", f"{src_path}/py.typed", - f"{src_path}/v0", ".github/workflows/ci.yml", ] """A list holding all desired files to be included in the project.""" From af955f19074b2f78a431323482e5c30f486699e8 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Garrido Date: Wed, 21 Jun 2023 19:49:03 +0200 Subject: [PATCH 19/19] FEAT: restore the CI/CD --- .github/workflows/templates_python.yml | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/templates_python.yml b/.github/workflows/templates_python.yml index 1792bcd88..180b79db9 100644 --- a/.github/workflows/templates_python.yml +++ b/.github/workflows/templates_python.yml @@ -34,32 +34,32 @@ jobs: toxextra: keep-output cfg: # All pybasic template tests - # - {name: "doc-project", template: "doc-project", build-system: "flit", outdir: "doc_proje0/doc-project"} - # - {name: "doc-project", template: "doc-project", build-system: "poetry", outdir: "doc_proje1/doc-project"} - # - {name: "doc-project", template: "doc-project", build-system: "setuptools", outdir: "doc_proje2/doc-project"} + - {name: "doc-project", template: "doc-project", build-system: "flit", outdir: "doc_proje0/doc-project"} + - {name: "doc-project", template: "doc-project", build-system: "poetry", outdir: "doc_proje1/doc-project"} + - {name: "doc-project", template: "doc-project", build-system: "setuptools", outdir: "doc_proje2/doc-project"} - # # All pybasic template tests - # - {name: "pybasic", template: "pybasic", build-system: "setuptools", outdir: "pybasic_s0/pybasic"} + # All pybasic template tests + - {name: "pybasic", template: "pybasic", build-system: "setuptools", outdir: "pybasic_s0/pybasic"} - # # All pybasic template tests - # - {name: "pyansys", template: "pyansys", build-system: "setuptools", outdir: "pyansys_s0/pyproduct-library"} + # All pybasic template tests + - {name: "pyansys", template: "pyansys", build-system: "setuptools", outdir: "pyansys_s0/pyproduct-library"} - # # # All pyansys_advanced template tests - # - {name: "pyansys-advanced-flit", template: "pyansys-advanced", build-system: "flit", outdir: "pyansys_a0/pyproduct-library"} - # - {name: "pyansys-advanced-poetry", template: "pyansys-advanced", build-system: "poetry", outdir: "pyansys_a1/pyproduct-library"} - # - {name: "pyansys-advanced-setuptools", template: "pyansys-advanced", build-system: "setuptools", outdir: "pyansys_a2/pyproduct-library"} + # # All pyansys_advanced template tests + - {name: "pyansys-advanced-flit", template: "pyansys-advanced", build-system: "flit", outdir: "pyansys_a0/pyproduct-library"} + - {name: "pyansys-advanced-poetry", template: "pyansys-advanced", build-system: "poetry", outdir: "pyansys_a1/pyproduct-library"} + - {name: "pyansys-advanced-setuptools", template: "pyansys-advanced", build-system: "setuptools", outdir: "pyansys_a2/pyproduct-library"} - # # All ansys API templates + # All ansys API templates - {name: "ansys-api", template: "ansys-api", build-system: "setuptools", outdir: "ansys_api2/ansys-api-product-library"} - # # # All pyace template tests - # - {name: "pyace-pkg", template: "pyace", build-system: "setuptools", outdir: "pyace_set0/project"} - # - {name: "pyace-flask", template: "pyace-flask", build-system: "setuptools", outdir: "pyace_fla2/project"} - # - {name: "pyace-fast", template: "pyace-fast", build-system: "setuptools", outdir: "pyace_fas2/project"} - # - {name: "pyace-grpc", template: "pyace-grpc", build-system: "setuptools", outdir: "pyace_grp2/project"} + # # All pyace template tests + - {name: "pyace-pkg", template: "pyace", build-system: "setuptools", outdir: "pyace_set0/project"} + - {name: "pyace-flask", template: "pyace-flask", build-system: "setuptools", outdir: "pyace_fla2/project"} + - {name: "pyace-fast", template: "pyace-fast", build-system: "setuptools", outdir: "pyace_fas2/project"} + - {name: "pyace-grpc", template: "pyace-grpc", build-system: "setuptools", outdir: "pyace_grp2/project"} - # # All solution template tests - # - {name: "solution", template: "solution", build-system: "poetry", outdir: "solution_1/solution"} + # All solution template tests + - {name: "solution", template: "solution", build-system: "poetry", outdir: "solution_1/solution"} fail-fast: false steps: