saas-api-python includes a file .pre-commit-config.yaml.
The following command installs the pre-commit hooks, see also framework pre-commmit and Git documentation on Customizing Git Git Hooks:
poetry run -- pre-commit installWhen the hooks are installed, then git will run each of the hooks on the resp. stage, e.g. before executing a commit. The Hooks include linting, code-formating and generating the api for each commit, so it stays up to date.
The model layer of this API has been generated from the OpenAPI specification in JSON format of the SaaS API https://cloud.exasol.com/openapi.json using openapi-python-client.
See also API Documentation and Swagger UI.
In order to regenerate the model layer please use the following command line:
poetry run -- nox -s api:generateThe CI checks include a check "Check API Outdated" (file check-api-outdated.yml, uses nox task api:check-outdated),
which regenerates the api, and checks it against the api version commited to GitHub.
If this check fails, it is likely for one of the following causes:
- SaaS API could have changed in the meantime (should be detected automatically)
- SaaS production vs. live system potentially can have subtle differences in the json API description (for api generation the production system is used)
- The version of python used changed
- The version of the generator openapi-python-client changed
In any of those cases, generating the api might give different results than in previous commits. These changes in the
generated api need to be commited to your GitHub branch for the check to pass in the CI.
This should be done automatically by the Pre-Commit Hooks (check if they are installed correctly),
but can also be done manually by calling the nox task api:generate, and commiting the results.
Before commiting, you might want to run the nox task api:check-outdated locally to see if it passed or if there are further problems:
poetry run -- nox -s api:check-outdatedanother cause for the check failing might be a python-toolbox update changing the linting/code formating. This can result in formatting tools like black or isort can modifying the generated code and causing artificial changes.
If you want to retrieve the JSON definition for the API model from a different source then just edit file noxfile.py.
Use CLI option --path to read the JSON definition from a local file instead of a URL:
"--path", "/path/to/openapi.json",openapi-python-client reads the JSON specification of the SaaS API and generates a python client. The generated client code requires transitive dependencies, though, which need to be added to file pyproject.toml to make them available for dependents of SAPIPY.
The easiest way is to make openapi-python-client create a dedicated file pyproject.toml and copy the transitive dependencies from there to SAPIPY's file pyproject.toml.
In order to create file pyproject.toml
- In file
noxfile.py, functiongenerate_apiyou need to replace modeupdatebygenerate. - Additionally, in file
openapi_config.ymlyou need to specify a non-existing top-level directory asproject_name_overrideand a package that does not contain slashes, e.g.
project_name_override: "generate"
package_name_override: saas.client.openapi
post_hooks: []After generating the API,
- Copy the dependencies from file
generate/pyproject.tomland - Remove directory
generate.
Executing the integration tests requires the following environment variables to be set:
| Variable | Description |
|---|---|
SAAS_HOST |
Host to use for requests to REST API |
SAAS_ACCOUNT_ID |
ID of the Exasol SAAS account to be used by the tests |
SAAS_PAT |
Personal access token to access the SAAS API |
Some of the test cases verify connecting to a SaaS database instance and execution will take about 20 minutes.
The regular CI build will ask for a confirmation (aka. "review) before executing these tests.
There are two scenarios for preparing a release:
In both scenarios the SAPIPY relies on Exasol's python-toolbox for preparing a release.
The invocation depends on your setup:
- When working in a poetry shell, you need to add one double-dash
--argument to separate arguments to the nox-sessionprepare-release. - When calling
poetrydirectly for one-time usage, then you need to add two double-dashes-- --to terminate arguments to poetry and nox before arguments to the nox-session.
poetry run -- nox -s release:prepare -- <version>Note that this scenario requires all your changes to be merged to branch main and no uncommited changes to be present in your local file tree.
Nox session prepare-release will
- Create a branch, e.g.
prepare-release/1.2.3starting frommain - Checkout this new branch
- Update the version in files
pyproject.tomlandversion.py - Update changes documentation
- Rename file
doc/unreleased.mdtodoc/changes_<version>.mdand add the current date as date of the release - Create a new file
doc/unreleased.md - Update the file
doc/changelog.md
- Rename file
- Commit and push the changes
- Create a pull request on GitHub
Please note that creating a pull request on GitHub requires
- Executable
ghto be installed and in your$PATHvariable - You must be authenticated towards GitHub via gh, use
gh authfor that - In case you are using a GitHub token, the token must have permission
org:read
If you prefer to create the pull request manually or cannot provide one of the prerequisites, you can add command line option --no-pr:
poetry run -- nox -s release:prepare -- <version> --no-prIn case you currently are already working on a branch other than main, please ensure to have all changes commited and add command line option --no-branch:
poetry run -- nox -s release:prepare -- <version> --no-pr --no-branchWhen all workflows triggered by merging the pull request to main have succeeded, you can create a new release by
- Switching to branch
main - Creating a git tag and
- Pushing it to
origin
TAG="${1}"
git tag "${TAG}"
git push origin "${TAG}"This will trigger additional GitHub workflows
- Running some checks
- Creating a GitHub release on https://github.com/exasol/saas-api-python/releases and
- Publishing the release on pypi