diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..238869b --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# These owners will be the default owners for everything in the repo. Unless a +# later match takes precedence, the PyAnsys Core team will be requested for +# review when someone opens a pull request. +* @ansys/scade-experts diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b640fb0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,20 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/requirements" + schedule: + interval: "daily" + commit-message: + prefix: "build" + labels: + - "maintenance" + - "dependencies" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: "build" + labels: + - "maintenance" diff --git a/.github/labeler.yml b/.github/labeler.yml index e5b01e6..9b7a2f3 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,2 +1,8 @@ maintenance: - any-glob-to-any-file: ['.github/**/*', '.pre-commit-config.yaml', 'VERSION'] +testing: +- any-glob-to-any-file: ['tests/**/*'] +documentation: +- any-glob-to-any-file: ['doc/**/*'] +dependencies: +- any-glob-to-any-file: ['requirements/**/*'] diff --git a/.github/labels.yml b/.github/labels.yml index cbc13d2..92971ef 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -29,3 +29,7 @@ - name: release description: Anything related to an incoming release color: ffffff + +- name: testing + description: Anything related to tests + color: BFE4D6 \ No newline at end of file diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index f12f4e2..fdcfee3 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -72,24 +72,25 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | Please add one of the following labels to add this contribution to the Release Notes :point_down: - - [bug](https://github.com/ansys/actions/pulls?q=label%3Abug+) - - [documentation](https://github.com/ansys/actions/pulls?q=label%3Adocumentation+) - - [enhancement](https://github.com/ansys/actions/pulls?q=label%3Aenhancement+) - - [good first issue](https://github.com/ansys/actions/pulls?q=label%3Agood+first+issue) - - [maintenance](https://github.com/ansys/actions/pulls?q=label%3Amaintenance+) - - [release](https://github.com/ansys/actions/pulls?q=label%3Arelease+) + - [bug](https://github.com/ansys/scade-actions/pulls?q=label%3Abug+) + - [documentation](https://github.com/ansys/scade-actions/pulls?q=label%3Adocumentation+) + - [enhancement](https://github.com/ansys/scade-actions/pulls?q=label%3Aenhancement+) + - [good first issue](https://github.com/ansys/scade-actions/pulls?q=label%3Agood+first+issue) + - [maintenance](https://github.com/ansys/scade-actions/pulls?q=label%3Amaintenance+) + - [release](https://github.com/ansys/scade-actions/pulls?q=label%3Arelease+) commit-and-branch-style: name: "Commit and branch style" runs-on: ubuntu-latest needs: labeler steps: - - - uses: ansys/actions/commit-style@main + - name: "Check commit style" + uses: ansys/actions/commit-style@v5 with: token: ${{ secrets.GITHUB_TOKEN }} - - uses: ansys/actions/branch-name-style@main + - name: "Check branch naming convention" + uses: ansys/actions/branch-name-style@v5 code-style: name: "Code style" @@ -131,34 +132,92 @@ jobs: skip-install: true python-version: ${{ env.MAIN_PYTHON_VERSION }} use-python-cache: false + dependencies: "texlive-fonts-extra qpdf" tests: name: "Tests" runs-on: [self-hosted, 'SCADE'] strategy: matrix: - # scade-version: ['23.1', '23.2'] scade-version: ['23.2'] fail-fast: false steps: - # - name: Checkout - # uses: actions/checkout@v4 - # - - name: Execute tests + - name: "Execute setup.py tests" + uses: ./scade-tests-pytest + with: + scade-version: ${{ matrix.scade-version }} + library-dir: "tests/python-setup" + pytest-postargs: "tests/python-setup/tests -vv" + checkout: false + - name: "Execute pyproject tests" uses: ./scade-tests-pytest with: scade-version: ${{ matrix.scade-version }} - library-dir: "tests/python" - pytest-postargs: "tests/python/tests -vv" + library-dir: "tests/python-pyproject" + pytest-postargs: "tests/python-pyproject/tests -vv" checkout: false doc-deploy-dev: name: "Deploy developers documentation" + needs: [doc-build, tests] runs-on: ubuntu-latest if: github.event_name == 'push' && !contains(github.ref, 'refs/tags') - needs: [doc-build, tests] steps: - uses: ansys/actions/doc-deploy-dev@v5 with: cname: ${{ env.DOCUMENTATION_CNAME }} token: ${{ secrets.GITHUB_TOKEN }} + + release: + name: "Release to GitHub" + runs-on: ubuntu-latest + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + needs: [doc-build, tests] + steps: + + - name: "Download HTML documentation" + uses: actions/download-artifact@v4 + with: + name: documentation-html + path: documentation-html + + - name: "Zip HTML documentation" + uses: vimtor/action-zip@v1.2 + with: + files: documentation-html + dest: documentation-html.zip + + - name: "Download PDF documentation" + uses: actions/download-artifact@v4 + with: + name: documentation-pdf + path: documentation-pdf + + - name: "Zip PDF documentation" + uses: vimtor/action-zip@v1.2 + with: + files: documentation-pdf + dest: documentation-pdf.zip + + - name: "Display the structure of downloaded files" + shell: bash + run: ls -R + + - name: "Release to GitHub" + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + files: | + documentation-html.zip + documentation-pdf.zip + + doc-deploy-stable: + name: "Upload stable documentation" + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + runs-on: ubuntu-latest + needs: release + steps: + - uses: ansys/actions/doc-deploy-stable@v5 + with: + cname: ${{ env.DOCUMENTATION_CNAME }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..111c460 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Rolling release +on: + push: + tags: + - "v*.*.*" + +permissions: write-all + +jobs: + automate-tagging: + name: "Perform rolling release" + runs-on: ubuntu-latest + steps: + - name: "Checkout repository" + uses: actions/checkout@v4 + + - name: "Configure git" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + + - name: "Decompose tag into components" + run: | + if [[ ${{ github.ref_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + # Split the tag into its components + IFS='.' read -ra PARTS <<< "${{ github.ref_name }}" + echo "X=${PARTS[0]}" >> $GITHUB_ENV + echo "Y=${PARTS[1]}" >> $GITHUB_ENV + echo "Z=${PARTS[2]}" >> $GITHUB_ENV + else + echo "Invalid tag format. Expected vX.Y.Z but got ${{ github.ref_name }}" + exit 1 + fi + + - name: "Verify tag was created in the proper release branch" + run: | + # Remove leading "v" from env.X + X_NO_V="${X:1}" + # Check if the tag was created in the proper branch + if [[ ${{ github.event.base_ref }} != "refs/heads/release/${X_NO_V}.${{ env.Y }}" ]]; then + echo "Tag ${{ github.ref_name }} was created in the wrong branch. Expected branch name release/${X_NO_V}.${{ env.Y }}" + exit 1 + fi + + - name: "Remove old tags" + run: | + git push --delete origin ${{ env.X }} + git push --delete origin ${{ env.X }}.${{ env.Y }} + + - name: "Create new tags" + run: | + git tag ${{ env.X }}.${{ env.Y }} + git tag ${{ env.X }} + git push origin ${{ env.X }}.${{ env.Y }} + git push origin ${{ env.X }} diff --git a/.gitignore b/.gitignore index 2b2f3c3..bf706df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -41,6 +45,7 @@ pip-delete-this-directory.txt htmlcov/ .tox/ .nox/ +.cov .coverage .coverage.* .cache @@ -50,6 +55,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -69,9 +75,10 @@ instance/ .scrapy # Sphinx documentation -docs/_build/ +doc/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook @@ -82,15 +89,24 @@ profile_default/ ipython_config.py # pyenv -.python-version +# For a library or package, you might want to ignore these files because the code is +# intended to run in multiple environments. Otherwise, check them in: +# .python-version # pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# According to pypa/pipenv#598, you should include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock +# poetry +# Similar to the Pipfile.lock recommendation, you should generally include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility. This +# recommendation is commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ @@ -127,5 +143,25 @@ dmypy.json # Pyre type checker .pyre/ -doc/_build/ -*-rendered-example.yml + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into the gitignore. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +# Visual Studio +.vs/ +.vscode/ + +# End of https://www.toptal.com/developers/gitignore/api/python + +# Ignore rendered examples +*-rendered-example.yml \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9f1ec9b..e122989 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,24 @@ repos: - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.2.0 hooks: - id: black - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: - --line-length=88 - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: check-yaml @@ -26,8 +26,17 @@ repos: - id: trailing-whitespace - id: debug-statements +- repo: https://github.com/ansys/pre-commit-hooks + rev: v0.2.9 + hooks: + - id: add-license-headers + files: '(tests)/.*\.(py)|./.*\.(yml)' + args: + - --start_year=2024 + exclude: '^(.github|doc)/.*' + # Validate our github workflow files - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.22.0 + rev: 0.28.0 hooks: - - id: check-github-workflows \ No newline at end of file + - id: check-github-workflows diff --git a/LICENSE b/LICENSE index c4968b8..1327840 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Ansys SCADE +Copyright (c) 2024 ANSYS, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 63c4df3..f850c1c 100644 --- a/README.rst +++ b/README.rst @@ -1,20 +1,21 @@ -.. readme_common_begins Ansys SCADE actions =================== |ansys| |CI-CD| |MIT| .. |ansys| image:: https://img.shields.io/badge/Ansys-ffc107.svg?labelColor=black&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABDklEQVQ4jWNgoDfg5mD8vE7q/3bpVyskbW0sMRUwofHD7Dh5OBkZGBgW7/3W2tZpa2tLQEOyOzeEsfumlK2tbVpaGj4N6jIs1lpsDAwMJ278sveMY2BgCA0NFRISwqkhyQ1q/Nyd3zg4OBgYGNjZ2ePi4rB5loGBhZnhxTLJ/9ulv26Q4uVk1NXV/f///////69du4Zdg78lx//t0v+3S88rFISInD59GqIH2esIJ8G9O2/XVwhjzpw5EAam1xkkBJn/bJX+v1365hxxuCAfH9+3b9/+////48cPuNehNsS7cDEzMTAwMMzb+Q2u4dOnT2vWrMHu9ZtzxP9vl/69RVpCkBlZ3N7enoDXBwEAAA+YYitOilMVAAAAAElFTkSuQmCC - :target: https://actions.docs.ansys.com/ + :target: https://actions.scade.docs.pyansys.com/ :alt: Ansys -.. |CI-CD| image:: https://github.com/ansys/actions/actions/workflows/ci_cd.yml/badge.svg - :target: https://github.com/ansys/actions/actions/workflows/ci_cd.yml +.. |CI-CD| image:: https://github.com/ansys/scade-actions/actions/workflows/ci_cd.yml/badge.svg + :target: https://github.com/ansys/scade-actions/actions/workflows/ci_cd.yml :alt: CI-CD .. |MIT| image:: https://img.shields.io/badge/License-MIT-blue.svg - :target: https://opensource.org/licenses/MIT + :target: https://opensource.org/blog/license/mit :alt: MIT +.. readme_common_begins + A repository containing a collection of `GitHub Actions `_ to be reused by projects in the Ansys SCADE ecosystem. @@ -26,8 +27,9 @@ For more information on available actions and how to use them, see Purpose -======= +------- The Ansys SCADE actions prepare a SCADE environment for executing tests. -They are driven by a Ansys SCADE version, such as ``23.1`` or ``24.1``, instead of a Python version, such as ``3.7`` or ``3.10``. +They are driven by a Ansys SCADE version, such as ``23.1`` or ``24.1``, +instead of a Python version, such as ``3.7`` or ``3.10``. diff --git a/create-scade-venv/action.yml b/create-scade-venv/action.yml index f39a182..946cdcc 100644 --- a/create-scade-venv/action.yml +++ b/create-scade-venv/action.yml @@ -1,3 +1,25 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + # create-scade-venv.yml name: 'Create a virtual Python environment' description: > @@ -28,24 +50,24 @@ runs: - name: Pass Inputs to Shell shell: cmd run: | - :: Pass inputs to the shell - echo INPUT_PYTHON_DIR=${{ inputs.python-dir }}>> %GITHUB_ENV% - echo INPUT_TARGET_DIR=${{ inputs.target-dir }}>> %GITHUB_ENV% - echo INPUT_TARGET_NAME=${{ inputs.target-name}}>> %GITHUB_ENV% + :: Pass inputs to the shell + echo INPUT_PYTHON_DIR=${{ inputs.python-dir }}>> %GITHUB_ENV% + echo INPUT_TARGET_DIR=${{ inputs.target-dir }}>> %GITHUB_ENV% + echo INPUT_TARGET_NAME=${{ inputs.target-name}}>> %GITHUB_ENV% - name: Create environment id: venv shell: cmd run: | - :: Create virtual environment - set VENV=%INPUT_TARGET_DIR%\%INPUT_TARGET_NAME% - if not exist "%VENV%" ( - echo Create virtual environment "%VENV%" - "%INPUT_PYTHON_DIR%\python.exe" -m venv "%VENV%" - ) else ( - echo Skip existing virtual environment "%VENV%" - ) - rem add the environment to the path - set PATH=%VENV%\Scripts;%PATH% - python --version - echo scripts-dir=%VENV%\Scripts>> %GITHUB_OUTPUT% + :: Create virtual environment + set VENV=%INPUT_TARGET_DIR%\%INPUT_TARGET_NAME% + if not exist "%VENV%" ( + echo Create virtual environment "%VENV%" + "%INPUT_PYTHON_DIR%\python.exe" -m venv "%VENV%" + ) else ( + echo Skip existing virtual environment "%VENV%" + ) + rem add the environment to the path + set PATH=%VENV%\Scripts;%PATH% + python --version + echo scripts-dir=%VENV%\Scripts>> %GITHUB_OUTPUT% diff --git a/doc/Makefile b/doc/Makefile index 1d2170d..aefaff2 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -3,7 +3,7 @@ # You can set these variables from the command line. You can also # set the first two from the environment. -SPHINXOPTS ?= +SPHINXOPTS ?= -j auto -W SPHINXBUILD ?= sphinx-build SOURCEDIR = source BUILDDIR = _build @@ -27,4 +27,4 @@ clean: pdf: @$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) cd $(BUILDDIR)/latex && latexmk -r latexmkrc -pdf *.tex -interaction=nonstopmode || true - (test -f $(BUILDDIR)/latex/*.pdf && echo pdf exists) || exit 1 + qpdf --check $(BUILDDIR)/latex/ansysscadeactions.pdf && echo "File is OK" && exit 0 || echo "File is corrupt" && exit 1 diff --git a/doc/make.bat b/doc/make.bat index 6039c18..21eec62 100644 --- a/doc/make.bat +++ b/doc/make.bat @@ -40,10 +40,11 @@ goto end %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% :pdf - %SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - cd "%BUILDDIR%\latex" - for %%f in (*.tex) do ( - pdflatex "%%f" --interaction=nonstopmode) +%SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +cd "%BUILDDIR%\latex" +for %%f in (*.tex) do ( +pdflatex "%%f" --interaction=nonstopmode) +goto end :end popd diff --git a/doc/source/conf.py b/doc/source/conf.py index f49fcb1..c314cb4 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -17,10 +17,6 @@ ACTIONS_SUFFIXES = "" ACTIONS_INPUTS_FIELDS = ("description", "required", "type", "default") ACTIONS_OUTPUTS_FIELDS = ("description",) -ACCEPTED_LICENSES = BASE_DIR / "check-licenses" / "accepted-licenses.txt" -IGNORED_PACKAGES = BASE_DIR / "check-licenses" / "ignored-packages.txt" -IGNORED_SAFETY = BASE_DIR / "check-vulnerabilities" / "ignored-safety.txt" - # Project information project = "Ansys SCADE Actions" copyright = f"(c) 2023-{datetime.today().year} ANSYS, Inc. and/or its affiliates." @@ -61,18 +57,12 @@ "use_edit_page_button": True, "additional_breadcrumbs": [ ("PyAnsys", "https://docs.pyansys.com/"), - ("PyAnsys Developer’s Guide", "https://dev.docs.pyansys.com/"), ], "switcher": { "json_url": f"https://{cname}/versions.json", "version_match": get_version_match(__version__), }, - "use_meilisearch": { - "api_key": os.getenv("MEILISEARCH_PUBLIC_API_KEY", ""), - "index_uids": { - f"actions-v{get_version_match(__version__).replace('.', '-')}": "Ansys-scade-actions", - }, - }, + "check_switcher": False, } # Specify Sphinx extensions to use @@ -87,6 +77,9 @@ # Specify the static path html_static_path = ["_static"] +html_css_files = [ + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" +] # Add any paths that contain templates, relative to this directory templates_path = ["_templates"] @@ -100,7 +93,12 @@ # Generate section labels for up to four levels autosectionlabel_maxdepth = 2 +# TODO: remove this when library is public +linkcheck_ignore = [ + r"https://github.com/ansys/scade-actions*", +] +sd_fontawesome_latex = True # Auxiliary routines for automatic documentation generation @@ -345,41 +343,3 @@ def get_example_file_title(example_file): jinja_contexts[action_name]["examples"] = [ [file.name, get_example_file_title(file)] for file in examples ] - - -# Dynamically load the file contents for accepted licenses and ignored packages -def load_file_lines_as_list(file_path): - """Loads the lines of a file in the form of a Python list. - - Parameters - ---------- - file_path : ~pathlib.Path - The ``Path`` instance representing the file location. - - Returns - ------- - list[str] - A list of strings representing the lines of the file. - - Notes - ----- - This function is expected to be used for loading the contents of TXT files. - - """ - with open(file_path) as accepted_licenses_file: - return list(accepted_licenses_file.read().split("\n")) - - -if False: - # TODO: should that be replicated this in this context? - # Check licenses - for var, file in zip( - ["accepted_licenses", "ignored_packages"], [ACCEPTED_LICENSES, IGNORED_PACKAGES] - ): - jinja_contexts["check-licenses"][var] = load_file_lines_as_list(file) - - # Check vulnerabilities - jinja_contexts["check-vulnerabilities"]["ignored_safety"] = load_file_lines_as_list( - IGNORED_SAFETY - ) - print(jinja_contexts["check-vulnerabilities"]["ignored_safety"]) diff --git a/doc/source/index.rst b/doc/source/index.rst index 286485d..5aab9ef 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1,3 +1,6 @@ +Ansys SCADE actions +################### + .. include:: ../../README.rst :start-after: .. readme_common_begins :end-before: .. readme_common_ends diff --git a/doc/source/query-actions/index.rst b/doc/source/query-actions/index.rst index 43d2de2..11a59be 100644 --- a/doc/source/query-actions/index.rst +++ b/doc/source/query-actions/index.rst @@ -1,5 +1,5 @@ Query actions -=================== +============= The query actions allow for querying Ansys SCADE installations and Python environments. diff --git a/doc/styles/Vocab/ANSYS/accept.txt b/doc/styles/Vocab/ANSYS/accept.txt index d70bb4b..591c295 100644 --- a/doc/styles/Vocab/ANSYS/accept.txt +++ b/doc/styles/Vocab/ANSYS/accept.txt @@ -6,3 +6,5 @@ GitHub pytest PyPI TXT +(?!)scade +(?!)python diff --git a/get-scade-dir/action.yml b/get-scade-dir/action.yml index ea44f62..cbe55ed 100644 --- a/get-scade-dir/action.yml +++ b/get-scade-dir/action.yml @@ -1,39 +1,69 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + # get-scade-dir.yml name: 'Retrieve the installation directory of an Ansys SCADE version' + description: > A GitHub action that takes as input an Ansys SCADE version and returns its installation directory. + inputs: + scade-version: - description: 'SCADE version: 19.2, 20.1, ..., 23.1, ...' + description: > + SCADE version: ``19.2, 20.1, ..., 23.1, ...``. required: true + outputs: + scade-directory: - description: 'Installation directory of the requested version' + description: > + Installation directory of the requested version. value: ${{ steps.find-scade-dir.outputs.scade-dir }} author: 'ESEG' runs: using: composite steps: - - name: Pass Inputs to Shell + + - name: "Pass Inputs to Shell" shell: cmd run: | - :: Pass Inputs to Shell - echo INPUT_SCADE_VERSION=${{ inputs.scade-version }}>> %GITHUB_ENV% + :: Pass Inputs to Shell + echo INPUT_SCADE_VERSION=${{ inputs.scade-version }}>> %GITHUB_ENV% - - name: Find SCADE_DIR + - name: "Find SCADE_DIR" id: find-scade-dir shell: cmd run: | - :: Find SCADE_DIR - echo Searching for Ansys SCADE "%INPUT_SCADE_VERSION%" - if "%INPUT_SCADE_VERSION%" lss "21.2" (set SCADE_COMPANY=Esterel Technologies) else (set SCADE_COMPANY=Ansys Inc) - echo SCADE registry company is "%SCADE_COMPANY%" - for /f "usebackq skip=2 tokens=2,*" %%A in (`REG QUERY "HKLM\SOFTWARE\%SCADE_COMPANY%\SCADE\%INPUT_SCADE_VERSION%" /v InstallDir 2^>nul`) do (set SCADE_DIR=%%B) - if "%SCADE_DIR%" == "" ( - echo Ansys SCADE "%INPUT_SCADE_VERSION%" not available - exit /b 1 - ) - echo Ansys SCADE %INPUT_SCADE_VERSION% found in "%SCADE_DIR%" - echo scade-dir=%SCADE_DIR%>> %GITHUB_OUTPUT% + :: Find SCADE_DIR + echo Searching for Ansys SCADE "%INPUT_SCADE_VERSION%" + if "%INPUT_SCADE_VERSION%" lss "21.2" (set SCADE_COMPANY=Esterel Technologies) else (set SCADE_COMPANY=Ansys Inc) + echo SCADE registry company is "%SCADE_COMPANY%" + for /f "usebackq skip=2 tokens=2,*" %%A in (`REG QUERY "HKLM\SOFTWARE\%SCADE_COMPANY%\SCADE\%INPUT_SCADE_VERSION%" /v InstallDir 2^>nul`) do (set SCADE_DIR=%%B) + if "%SCADE_DIR%" == "" ( + echo Ansys SCADE "%INPUT_SCADE_VERSION%" not available + exit /b 1 + ) + echo Ansys SCADE %INPUT_SCADE_VERSION% found in "%SCADE_DIR%" + echo scade-dir=%SCADE_DIR%>> %GITHUB_OUTPUT% diff --git a/get-scade-python/action.yml b/get-scade-python/action.yml index 7e19de6..f81c8f6 100644 --- a/get-scade-python/action.yml +++ b/get-scade-python/action.yml @@ -1,3 +1,25 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + # get-scade-python name: 'Retrieve the Python installation installed with Ansys SCADE' @@ -6,58 +28,63 @@ description: > and returns the name and path to the corresponding Python installation. inputs: + scade-dir: description: > - Ansys SCADE Installation directory, e.g.:: - - C:\Program Files\Ansys Inc\v231\SCADE + Ansys SCADE Installation directory. for instance + ``'C:\Program Files\Ansys Inc\v231\SCADE'``. required: true outputs: + python-name: - description: Name of the directory containing python.exe + description: > + Name of the directory containing python.exe. value: ${{ steps.get.outputs.python-name }} python-dir: - description: Directory containing python.exe + description: > + Directory containing python.exe. value: ${{ steps.get.outputs.python-dir }} python-version: - description: Version of python.exe, two digits + description: > + Version of python.exe, two digits. value: ${{ steps.get.outputs.python-version }} author: 'ESEG' runs: using: composite steps: - - name: Pass Inputs to Shell + + - name: "Pass Inputs to Shell" id: set shell: cmd run: | - :: Pass Inputs to Shell - echo INPUT_SCADE_DIR=${{ inputs.scade-dir }}>> %GITHUB_ENV% + :: Pass Inputs to Shell + echo INPUT_SCADE_DIR=${{ inputs.scade-dir }}>> %GITHUB_ENV% - - name: Retrieve Python name/directory/version + - name: "Retrieve Python name/directory/version" id: get shell: cmd run: | - :: Retrieve Python name/directory - setlocal ENABLEDELAYEDEXPANSION - echo Get Python interpreter for "%INPUT_SCADE_DIR%" - set PYTHON_VERSION=0 - for /f "usebackq" %%A in (`dir /B "%INPUT_SCADE_DIR%\contrib\Python*"`) do ( - set CURRENT_VERSION=%%A - set CURRENT_VERSION=!CURRENT_VERSION:Python=%! - if !CURRENT_VERSION! GTR !PYTHON_VERSION! ( - set PYTHON_VERSION=!CURRENT_VERSION! - ) - ) - set PYTHON_NAME=Python%PYTHON_VERSION% - echo Python name="%PYTHON_NAME%" - echo python-name=%PYTHON_NAME%>> %GITHUB_OUTPUT% - set PYTHON_DIR=%INPUT_SCADE_DIR%\contrib\%PYTHON_NAME% - echo Python directory="%PYTHON_DIR%" - echo python-dir=%PYTHON_DIR%>> %GITHUB_OUTPUT% - for /f "usebackq tokens=2,3 delims=. " %%A in (`"%PYTHON_DIR%\python" --version`) do (set PYTHON_VERSION=%%A.%%B) - echo Python version="%PYTHON_VERSION%" - echo python-version=%PYTHON_VERSION%>> %GITHUB_OUTPUT% + :: Retrieve Python name/directory + setlocal ENABLEDELAYEDEXPANSION + echo Get Python interpreter for "%INPUT_SCADE_DIR%" + set PYTHON_VERSION=0 + for /f "usebackq" %%A in (`dir /B "%INPUT_SCADE_DIR%\contrib\Python*"`) do ( + set CURRENT_VERSION=%%A + set CURRENT_VERSION=!CURRENT_VERSION:Python=%! + if !CURRENT_VERSION! GTR !PYTHON_VERSION! ( + set PYTHON_VERSION=!CURRENT_VERSION! + ) + ) + set PYTHON_NAME=Python%PYTHON_VERSION% + echo Python name="%PYTHON_NAME%" + echo python-name=%PYTHON_NAME%>> %GITHUB_OUTPUT% + set PYTHON_DIR=%INPUT_SCADE_DIR%\contrib\%PYTHON_NAME% + echo Python directory="%PYTHON_DIR%" + echo python-dir=%PYTHON_DIR%>> %GITHUB_OUTPUT% + for /f "usebackq tokens=2,3 delims=. " %%A in (`"%PYTHON_DIR%\python" --version`) do (set PYTHON_VERSION=%%A.%%B) + echo Python version="%PYTHON_VERSION%" + echo python-version=%PYTHON_VERSION%>> %GITHUB_OUTPUT% diff --git a/requirements/requirements_doc.txt b/requirements/requirements_doc.txt index 0a3d756..314f61b 100644 --- a/requirements/requirements_doc.txt +++ b/requirements/requirements_doc.txt @@ -1,6 +1,6 @@ -ansys-sphinx-theme==0.13.4 +ansys-sphinx-theme==0.14.0 pyyaml==6.0.1 -Sphinx==7.1.1 +Sphinx==7.2.6 sphinx-copybutton==0.5.2 sphinx-jinja==2.0.2 sphinx_design==0.5.0 diff --git a/requirements/requirements_tests.txt b/requirements/requirements_tests.txt index 71b21e3..6f59f1f 100644 --- a/requirements/requirements_tests.txt +++ b/requirements/requirements_tests.txt @@ -1,2 +1,2 @@ -pytest==7.1.2 -pytest-cov==3.0.0 +pytest==8.0.1 +pytest-cov==4.1.0 diff --git a/scade-tests-pytest/action.yml b/scade-tests-pytest/action.yml index db6d697..0661233 100644 --- a/scade-tests-pytest/action.yml +++ b/scade-tests-pytest/action.yml @@ -1,3 +1,25 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + # action derived from ansys/actions/tests-pytest name: > Tests pytest action @@ -56,7 +78,7 @@ runs: uses: ./get-scade-dir id: get-scade-dir with: - scade-version: ${{ inputs.scade-version }} + scade-version: ${{ inputs.scade-version }} - name: "Retrieve SCADE Python interpreter" uses: ./get-scade-python diff --git a/tests-pytest/action.yml b/tests-pytest/action.yml index 2bd78bf..9699ff4 100644 --- a/tests-pytest/action.yml +++ b/tests-pytest/action.yml @@ -1,3 +1,25 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + # tests-pytest # action derived from ansys/actions/tests-pytest name: > @@ -47,7 +69,6 @@ inputs: default: 'true' required: false - runs: using: "composite" steps: @@ -56,48 +77,46 @@ runs: uses: actions/checkout@v4 if: ${{ inputs.checkout == 'true' }} - - name: Pass Inputs to Shell + - name: "Pass Inputs to Shell" shell: cmd run: | - :: Pass inputs to the shell - echo INPUT_PYTHON_DIR=${{ inputs.python-dir }}>> %GITHUB_ENV% + :: Pass inputs to the shell + echo INPUT_PYTHON_DIR=${{ inputs.python-dir }}>> %GITHUB_ENV% - - name: Check python + - name: "Check python" shell: cmd run: | - :: Check python - echo Activate the environment %INPUT_PYTHON_DIR% - call %INPUT_PYTHON_DIR%\activate.bat - python.exe --version - :: store the "exe for the next steps" - echo PYTHON_EXE=%INPUT_PYTHON_DIR%\python.exe>> %GITHUB_ENV% + :: Check python + echo Activate the environment %INPUT_PYTHON_DIR% + call %INPUT_PYTHON_DIR%\activate.bat + python.exe --version + :: store the "exe for the next steps" + echo PYTHON_EXE=%INPUT_PYTHON_DIR%\python.exe>> %GITHUB_ENV% - name: "Update pip" shell: cmd run: | - %PYTHON_EXE% -m pip install -U pip + %PYTHON_EXE% -m pip install -U pip - name: "Install Python library" shell: cmd run: | - %PYTHON_EXE% -m pip install ${{ inputs.library-dir }} + %PYTHON_EXE% -m pip install ${{ inputs.library-dir }} - name: "Check if requirements_tests.txt file exists" shell: cmd run: | - :: Add the requirements - if exist ${{ inputs.library-dir }}/requirements/requirements_tests.txt ( - echo Install test dependencies from the requirements file - %PYTHON_EXE% -m pip install -r ${{ inputs.library-dir }}/requirements/requirements_tests.txt - ) - - # - name: "Install test dependencies from pyproject.toml" - # shell: cmd - # if: env.EXISTS_TESTS_REQUIREMENTS == 'false' - # run: python -m pip install .[tests] + :: Check if requirements_tests.txt file exists + if exist {{ inputs.library-dir }}/requirements/requirements_tests.txt ( + echo Installing test dependencies from requirements_tests.txt + %PYTHON_EXE% -m pip install -r %GITHUB_WORKSPACE%\${{ inputs.library-dir }}/requirements/requirements_tests.txt + ) else ( + echo Installing test dependencies from pyproject.toml + %PYTHON_EXE% -m pip install ${{ inputs.library-dir }}[tests] + ) - name: "Executing test suite" shell: cmd run: | - :: Run tests - %PYTHON_EXE% -m pytest ${{ inputs.pytest-markers }} ${{ inputs.pytest-extra-args }} ${{ inputs.pytest-postargs }} + :: Run tests + %PYTHON_EXE% -m pytest ${{ inputs.pytest-markers }} ${{ inputs.pytest-extra-args }} ${{ inputs.pytest-postargs }} diff --git a/tests/python/.gitignore b/tests/python-pyproject/.gitignore similarity index 100% rename from tests/python/.gitignore rename to tests/python-pyproject/.gitignore diff --git a/tests/python-pyproject/pyproject.toml b/tests/python-pyproject/pyproject.toml new file mode 100644 index 0000000..fe776fb --- /dev/null +++ b/tests/python-pyproject/pyproject.toml @@ -0,0 +1,14 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name="test_package" +version="0.1.dev0" +description ="Test purpose" + +[project.optional-dependencies] +test = [ + "pytest==7.1.2", + "pytest-cov==3.0.0" +] diff --git a/tests/python/src/test_package/__init__.py b/tests/python-pyproject/src/test_package/__init__.py similarity index 100% rename from tests/python/src/test_package/__init__.py rename to tests/python-pyproject/src/test_package/__init__.py diff --git a/tests/python/src/test_package/script.py b/tests/python-pyproject/src/test_package/script.py similarity index 100% rename from tests/python/src/test_package/script.py rename to tests/python-pyproject/src/test_package/script.py diff --git a/tests/python/tests/conftest.py b/tests/python-pyproject/tests/conftest.py similarity index 100% rename from tests/python/tests/conftest.py rename to tests/python-pyproject/tests/conftest.py diff --git a/tests/python/tests/resources/Model.etp b/tests/python-pyproject/tests/resources/Model.etp similarity index 100% rename from tests/python/tests/resources/Model.etp rename to tests/python-pyproject/tests/resources/Model.etp diff --git a/tests/python/tests/resources/P.xscade b/tests/python-pyproject/tests/resources/P.xscade similarity index 100% rename from tests/python/tests/resources/P.xscade rename to tests/python-pyproject/tests/resources/P.xscade diff --git a/tests/python/tests/test_script.py b/tests/python-pyproject/tests/test_script.py similarity index 100% rename from tests/python/tests/test_script.py rename to tests/python-pyproject/tests/test_script.py diff --git a/tests/python-setup/.gitignore b/tests/python-setup/.gitignore new file mode 100644 index 0000000..c024220 --- /dev/null +++ b/tests/python-setup/.gitignore @@ -0,0 +1,32 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +TestResults +*.pyproj +*.sln +*.vsw diff --git a/tests/python/requirements/requirements_tests.txt b/tests/python-setup/requirements/requirements_tests.txt similarity index 100% rename from tests/python/requirements/requirements_tests.txt rename to tests/python-setup/requirements/requirements_tests.txt diff --git a/tests/python-setup/setup.py b/tests/python-setup/setup.py new file mode 100644 index 0000000..7eda28c --- /dev/null +++ b/tests/python-setup/setup.py @@ -0,0 +1,34 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from setuptools import find_packages, setup + +setup( + name="test_package", + version="0.1.dev0", + url="https://github.com/test-package-for-scade-actions.git", + author="ESEG", + author_email="test@unknown.com", + description="Test purpose", + packages=find_packages(where="./src"), + package_dir={"": "src"}, +) diff --git a/tests/python-setup/src/test_package/__init__.py b/tests/python-setup/src/test_package/__init__.py new file mode 100644 index 0000000..3bc3c8e --- /dev/null +++ b/tests/python-setup/src/test_package/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/tests/python-setup/src/test_package/script.py b/tests/python-setup/src/test_package/script.py new file mode 100644 index 0000000..458e59d --- /dev/null +++ b/tests/python-setup/src/test_package/script.py @@ -0,0 +1,45 @@ +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""" +Simple script to verify the correct execution of the actions. +""" + +from pathlib import Path + +from scade import output +from scade.model.project.stdproject import get_roots as get_projects +from scade.model.suite import get_roots as get_sessions + + +def get_project_names(projects): + return [Path(_.pathname).name for _ in projects] + + +def get_operator_paths(model): + return [_.get_full_path() for _ in model.all_operators] + + +if __name__ == "__main__": + output(str(get_project_names(get_projects())) + "\n") + # assume one and only one SCADE project + output(str(get_operator_paths(get_sessions()[0].model)) + "\n") diff --git a/tests/python-setup/tests/conftest.py b/tests/python-setup/tests/conftest.py new file mode 100644 index 0000000..95db65f --- /dev/null +++ b/tests/python-setup/tests/conftest.py @@ -0,0 +1,90 @@ +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +"""Unit tests fixtures.""" + +import os +import re +import sys +from inspect import getsourcefile +from pathlib import Path + +# import pytest + +# set sys.path from the python interpreter location (/SCADE/contrib/Python3xx) +# note: these tests are executed in the context of a virtual environment +# on top of a SCADE's Python distribution + +for line in (Path(sys.executable).parent.parent / "pyvenv.cfg").open("r"): + m = re.match(r"^home\s*=\s*(.*)$", line) + if m: + contrib = Path(m.groups()[0]).parent + break + +assert contrib +base = contrib.parent / "SCADE" +bin = base / "bin" +assert bin.exists() +sys.path.append(str(bin)) +lib = base / "APIs" / "Python" / "lib" +assert lib.exists() +sys.path.append(str(lib)) + + +# can be imported since sys.path is updated +# isort: split +# activate the SCADE Python APIs by importing scade_env +import scade_env # noqa: E402, F401 + +# must be imported after scade_env +# isort: split +import scade # noqa: E402 +import scade.model.suite as suite # noqa: E402 + + +def get_resources_dir() -> Path: + """Return the directory ./resources relative to this file's directory.""" + script_path = Path(os.path.abspath(getsourcefile(lambda: 0))) + return script_path.parent + + +def load_session(pathname: Path): + """ + Load a Scade model in a separate environment. + + Note: The model can have unresolved references since the libraries + are not loaded. + """ + session = suite.Session() + session.load2(str(pathname)) + assert session.model + return session + + +def load_project(pathname: Path): + """ + Load a Scade project in a separate environment. + + Note: Undocumented API. + """ + project_ = scade.load_project(str(pathname)) + return project_ diff --git a/tests/python-setup/tests/resources/Model.etp b/tests/python-setup/tests/resources/Model.etp new file mode 100644 index 0000000..50af156 --- /dev/null +++ b/tests/python-setup/tests/resources/Model.etp @@ -0,0 +1,364 @@ + + + + + SC + + + SCADE65 + + + $(Configuration) + 14 + + + /nologo /ML /O2 + 14 + + + C QUAL663 + 14 + + + char + float32 + float64 + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + size + 14 + + + $(TargetDir)\user_macros.h + 14 + + + false + 14 + + + win64 + 14 + + + Code Generator + 14 + 23 + 44 + 57 + + + $(Configuration) + 23 + + + /nologo /ML /O2 + 23 + + + C QUAL663 + 23 + + + char + float32 + float64 + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + size + 23 + + + true + 23 + + + true + 23 + + + true + 23 + + + Simulator + 23 + + + $(TargetDir)\user_macros.h + 23 + + + win64 + 23 + + + Reporter/ScadeReport.tcl + 34 + + + true + 34 + + + Flat + 34 + + + Reporter + 34 + 39 + 44 + 65 + + + rtf + 39 + + + Reporter/ScadeReport.tcl + 39 + + + true + 39 + + + Flat + 39 + + + $(Configuration) + 44 + + + /nologo /ML /O2 + 44 + + + C QUAL663 + 44 + + + char + float32 + float64 + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + size + 44 + + + $(TargetDir)\user_macros.h + 44 + + + true + 44 + + + + 44 + + + Simulator + 44 + + + win64 + 44 + + + $(SCADE)/scripts/MetricRule/DefaultMetrics.py + $(SCADE)/scripts/MetricRule/DefaultRules.py + + + Metrics and Rules Checker + 54 + + + $(Configuration) + 57 + + + /nologo /ML /O2 + 57 + + + C QUAL663 + 57 + + + char + float32 + float64 + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + size + 57 + + + $(TargetDir)\user_macros.h + 57 + + + T&S Optimizer + 57 + + + Timing and Stack Verifiers + 57 + + + rtf + 65 + + + Reporter/ScadeQualifiedReport.tcl + 65 + + + true + 65 + + + Flat + 65 + + + true + 65 + + + true + 65 + + + true + 65 + + + Model.xscade + + + Model.err + + + $(SCADE)/lib/DefaultAty.aty + + + true + + + <title> + + + <subtitle> + + + <description> + + + <authors> + + + <company> + + + <date> + + + <index> + + + <reference> + + + Timing and Stack Analysis Tools + 14 + 23 + 34 + 39 + 44 + 54 + 57 + 65 + + + DiffAnalyzer + 14 + 23 + 34 + 39 + 44 + 54 + 57 + 65 + + + Synchronization + 14 + 23 + 34 + 39 + 44 + 54 + 57 + 65 + + + Import/Export + 14 + 23 + 34 + 39 + 44 + 54 + 57 + 65 + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/python-setup/tests/resources/P.xscade b/tests/python-setup/tests/resources/P.xscade new file mode 100644 index 0000000..fb969fe --- /dev/null +++ b/tests/python-setup/tests/resources/P.xscade @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/python-setup/tests/test_script.py b/tests/python-setup/tests/test_script.py new file mode 100644 index 0000000..dad14ed --- /dev/null +++ b/tests/python-setup/tests/test_script.py @@ -0,0 +1,54 @@ +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""" +Test suite for script.py. + +Test strategy: + +* Verify the returned values for a simple Scade model. +""" + +import pytest +from conftest import get_resources_dir, load_project, load_session +from test_package import script + + +@pytest.fixture(scope="session") +def roots(): + """Unique instance of the test model Model.""" + path = get_resources_dir() / "resources" / "Model.etp" + project = load_project(path) + session = load_session(path) + return project, session + + +def test_get_project_names(roots): + project, _ = roots + names = script.get_project_names([project]) + assert names == ["Model.etp"] + + +def test_get_operator_paths(roots): + _, session = roots + paths = script.get_operator_paths(session.model) + assert paths == ["P::Root/"] diff --git a/tests/python/setup.py b/tests/python/setup.py deleted file mode 100644 index f7196ab..0000000 --- a/tests/python/setup.py +++ /dev/null @@ -1,12 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name="test_package", - version="0.1.dev0", - url="https://github.com/test-package-for-scade-actions.git", - author="ESEG", - author_email="test@unknown.com", - description="Test purpose", - packages=find_packages(where="./src"), - package_dir={"": "src"}, -)