************ Contributing ************ Issues ====== Please report bugs or feature requests by `creating GitHub issues`_. .. _creating GitHub issues: https://github.com/eclipse-aascw/aas-client3.2-python/issues In Code ======= If you want to contribute in code, pull requests are welcome! Please do `create a new issue`_ before you dive into coding. It can well be that we already started working on the feature, or that there are upstream or downstream complexities involved which you might not be aware of. .. _create a new issue: https://github.com/eclipse-aascw/aas-client3.2-python/issues Development Environment ======================= Create a virtual environment, and activate it (from the repository root): .. code-block:: python3 -m venv venv source venv/bin/activate On Windows, activate it with ``venv\Scripts\activate`` instead. Install the client, the testing client and all the development requirements in editable mode, so that your changes take effect without re-installing: .. code-block:: pip3 install --editable . pip3 install --editable aas-testing-client3.2/ pip3 install --editable dev/ ``dev/`` is a separate distribution, ``aas-client3.2-dev``, which lists all the development requirements (the formatter, the linters, the type checker, the test and the coverage tools *etc.*), and provides the packages ``dev_scripts`` and ``tests``. If you develop the client together with a local checkout of `aas-core3.2`_, install the checkout in the same environment. Use the compatibility mode of the editable installation, since otherwise mypy can not find the package: .. code-block:: pip3 install --editable path/to/aas-core3.2-python --config-settings editable_mode=compat Versions ======== Each version of the specification Part 2 has its own client, in its own package and repository, named ``aas-client.``; this one, ``aas-client3.2``, implements the version 3.2. This follows `aas-core3.2`_ and its siblings, so that the clients of different versions can be installed side by side, and your code switches between them explicitly by the import. The version of the package itself (such as ``1.0.0``) is the version of the client, not of the specification. Updating the OpenAPI ==================== The client is checked against copies of the OpenAPI documents of `admin-shell-io/aas-specs-api`_ in ``dev/test_data/openapi``. Do not edit them by hand; update them to the newest release of the implemented version with: .. code-block:: python dev/dev_scripts/update_openapi.py The script also tells you if a later version of the specification has been released. Inspect the changes with ``git diff``. The workflow ``check-openapi.yml`` runs the tests which depend on the copies whenever they change; locally, run the pre-commit checks. They report the operations which no function implements, the functions which disagree with the OpenAPI, and the profiles whose functions changed. Regenerate the profiles with: .. code-block:: python dev/dev_scripts/generate_profiles.py The modules of the concurrent testing client, ``aas_testing_client3_2.concurrent``, are generated from the testing client. After you add, rename or change a function of the testing client, regenerate them with: .. code-block:: python dev/dev_scripts/generate_concurrent_testing_client.py The script lists in ``TRACKED`` which operations write or read a whole resource, and which change it only in part; a new operation of a tracked module which changes the server must be added there. The sequential testing client, ``aas_testing_client3_2.sequential``, is written by hand; a new operation which changes the server needs its snapshots there, and a new operation which only reads is re-exported. The pre-commit checks tell you if either subpackage misses a function. The individual development scripts are in `dev/dev_scripts/`_. .. _dev/dev_scripts/: https://github.com/eclipse-aascw/aas-client3.2-python/tree/main/dev/dev_scripts .. _admin-shell-io/aas-specs-api: https://github.com/admin-shell-io/aas-specs-api Moving to a New Version of the Specification ============================================ The client of a new version of Part 2 is a new package in a new repository, started as a copy of this one. In the copy, on a clean working tree, run: .. code-block:: python dev/dev_scripts/bump_specification_version.py --to 3.3 It renames the packages, the environment variables, the links to the prose and the version from which the development scripts and the tests derive the names of the OpenAPI documents and the identifiers of the profiles. It then lists the remaining mentions of the old version, which you review by hand, and prints the next steps: copy the new OpenAPI with ``update_openapi.py``, install the new aas-core, and let the pre-commit checks show what needs to be implemented. .. _aas-core3.2: https://github.com/eclipse-aascw/aas-core3.2-python What the Checks Do Not Derive ============================= The checks against the OpenAPI derive as much as possible from the OpenAPI itself: the operations, their methods, paths, parameters and encodings, the return types, the modules (by the API groups, the tags of the OpenAPI), the prefixes of the APIs relative to an endpoint, the names of the functions and their variants, and the profiles. Hence a new or changed OpenAPI is checked without changing the checks, and every mismatch is reported. The following places record design decisions of the client, which can not be derived. Revisit them whenever the OpenAPI changes, and whenever a check reports a mismatch which is intended: * ``RETURN_TYPE_DEVIATIONS`` in ``dev/dev_scripts/openapi_conformance.py``: the operations whose return types deviate on purpose from the schemas of the OpenAPI, such as ``GetSelfDescription``, which gives the profiles as strings. Add an operation here only if the deviation is deliberate, and explain why in a comment. * ``_PATH_PARAMETERS_AS_GIVEN`` in the same script: the path parameters which the client sends as given rather than base64url-encoded, namely the handles which the server gives in ``Location``. * ``example`` in the same script: the example arguments with which every function is called. If a new function takes a parameter of a new type, the check fails with ``No example for the parameter``; add an example of the type there. * In the static part of ``dev/tests/test_openapi_conformance.py``: the parameters of an operation which the client does not take as keyword arguments, namely ``serializationFormat``, which the client sends as ``Accept``, and the ``fileName`` and ``contentType`` of an upload, which are attributes of the multipart part rather than its fields. * ``_CONSTANT_PREFIXES``, ``_SPECIFICATION_NAMES`` and ``_KINDS`` in ``dev/dev_scripts/generate_profiles.py``: the names of the constants and the descriptions of the profiles. The script fails with a message if a new service specification or a new profile is not listed there. The checks can not tell whether the client behaves correctly, only that it conforms to the OpenAPI. For every new operation, also write by hand: * the function in the client, with the ``:implements:`` field in its docstring (the checks report a missing function, a wrong name, path, method, parameter or return type), * the function with the contracts in the testing client (the checks report a missing function or different parameters, but not missing contracts), * the unit tests with the golden files, and * the live tests against a server. Pre-commit Checks ================= The pre-commit checks need the development environment (see `Development Environment`_). Execute them from the repository root: .. code-block:: python dev/continuous_integration/precommit.py Some of the checks, such as formatting, can be automatically fixed. If you want self-healing checks, run: .. code-block:: python dev/continuous_integration/precommit.py --overwrite Running the Tests ================= The tests need the development environment (see `Development Environment`_). **Unit tests**. The unit tests need no server. Run all of them (from the repository root): .. code-block:: python dev/continuous_integration/precommit.py --select test To run a single test module, run it from the directory ``dev``: .. code-block:: cd dev python -m unittest tests.test_profiles Many unit tests compare the requests and the responses with the golden files in ``dev/test_data``. If you changed the requests on purpose, re-record the golden files, and inspect the changes with ``git diff``: .. code-block:: python dev/dev_scripts/rerecord_tests.py **Live tests**. The live tests in ``dev/live_tests`` run the client against real servers, the Eclipse BaSyx Go components, which Docker Compose starts from ``dev/live_tests/docker/docker-compose.yml``. You need Docker with Docker Compose, and the ports 5004 to 5011 free on the host. Start the servers, run all the live tests, and stop the servers with: .. code-block:: python dev/dev_scripts/run_live_tests.py Pass ``--keep`` to keep the servers running after the tests, for example, for debugging, and ``--timeout`` to wait longer for the servers to start. The ports can be changed with the arguments of the script; see ``--help``. The live tests also run all the examples of the getting started (``dev/live_tests/test_getting_started.py``), in the order of the pages, so that the documentation does not drift from the client. The unit tests check that the examples compile and refer only to what the modules have (``dev/tests/test_docs.py``), and that the API reference has one page per public module. If an example can not run against the servers of the live tests, put the comment ``.. skip-live-test: `` right before its ``code-block``. Every page cleans up what it creates, so that the examples can run again. The known bugs of the servers are marked as expected failures, so a run passes with them; a fix of a server shows up as an unexpected success. The live tests are agnostic of the server: they read the base URLs from the environment variables ``AAS_CLIENT3_2_LIVE_*`` (see ``dev/live_tests/common.py``), and skip the tests of a service whose variable is not set. To run them against other servers, set the variables, and run from the repository root: .. code-block:: python -m unittest discover --start-directory dev/live_tests --verbose Documentation ============= The documentation lives in ``docs/source``, and is built with Sphinx in a separate virtual environment. See `docs/how-to-build-docs.md`_ for how to build, test and publish it. .. _docs/how-to-build-docs.md: https://github.com/eclipse-aascw/aas-client3.2-python/blob/main/docs/how-to-build-docs.md Pull Requests ============= **Feature branches**. We develop using the feature branches, see `this section of the Git book`_. .. _this section of the Git book: https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows If you are a member of the development team, create a feature branch directly within the repository. Otherwise, if you are a non-member contributor, fork the repository and create the feature branch in your forked repository. See `this GitHub tutorial`_ for more guidance. .. _this GitHub tutorial: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork **Branch Prefix**. Please prefix the branch with your Github user name (*e.g.,* ``mristin/Add-some-feature``). **Continuous Integration**. GitHub will run the continuous integration (CI) automatically through GitHub actions. The CI includes running the tests, inspecting the code, re-building the documentation *etc.* Commit Messages =============== The commit messages follow the guidelines from https://chris.beams.io/posts/git-commit: * Separate subject from body with a blank line, * Limit the subject line to 50 characters, * Capitalize the subject line, * Do not end the subject line with a period, * Use the imperative mood in the subject line, * Wrap the body at 72 characters, and * Use the body to explain *what* and *why* (instead of *how*).