-
Notifications
You must be signed in to change notification settings - Fork 569
[1] Add tox generation script, but don't use it yet #3971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4f0b90c
Add tox generation script, but don't use it yet
sentrivana c2c6450
add missing file
sentrivana 6b9417f
capitalization
sentrivana c971981
comment
sentrivana c2d59ae
explicit none check
sentrivana 65cc78c
Merge branch 'master' into ivana/tox-script-1
sentrivana efaa55f
Apply suggestions from code review
sentrivana 474c679
better readme structure
sentrivana 8904a1b
remove test suite config
sentrivana 8572489
dont require deps
sentrivana 3e1c28d
remove fail-on-changes
sentrivana c96bf0c
put more stuff into functions
sentrivana 2d27260
fix numbering, env name
sentrivana 286e76f
rename var
sentrivana 0ccb443
Apply suggestions from code review
sentrivana 42d6bba
Update scripts/populate_tox/README.md
sentrivana 82de68c
docstring fix
sentrivana de3ccef
add comment to path extension
sentrivana cda7417
add some docstrings
sentrivana c94deb6
Apply suggestions from code review
sentrivana a21073d
change non-major version picking
sentrivana f601d54
link issue
sentrivana 6485c32
wording
sentrivana 9c64a82
Merge branch 'master' into ivana/tox-script-1
sentrivana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/sh | ||
|
|
||
| # This script generates tox.ini and CI YAML files in one go. | ||
|
|
||
| set -xe | ||
|
|
||
| cd "$(dirname "$0")" | ||
|
|
||
| python -m venv .venv | ||
| . .venv/bin/activate | ||
|
|
||
| pip install -e .. | ||
| pip install -r populate_tox/requirements.txt | ||
| pip install -r split_tox_gh_actions/requirements.txt | ||
|
|
||
| python populate_tox/populate_tox.py | ||
| python split_tox_gh_actions/split_tox_gh_actions.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| # Populate Tox | ||
|
|
||
| We integrate with a number of frameworks and libraries and have a test suite for | ||
| each. The tests run against different versions of the framework/library to make | ||
| sure we support everything we claim to. | ||
|
|
||
| This `populate_tox.py` script is responsible for picking reasonable versions to | ||
| test automatically and generating parts of `tox.ini` to capture this. | ||
|
|
||
| ## How it works | ||
|
|
||
| There is a template in this directory called `tox.jinja` which contains a | ||
| combination of hardcoded and generated entries. | ||
|
|
||
| The `populate_tox.py` script fills out the auto-generated part of that template. | ||
| It does this by querying PyPI for each framework's package and its metadata and | ||
| then determining which versions make sense to test to get good coverage. | ||
|
|
||
| The lowest supported and latest version of a framework are always tested, with | ||
| a number of releases in between: | ||
| - If the package has majors, we pick the highest version of each major. For the | ||
| latest major, we also pick the lowest version in that major. | ||
| - If the package doesn't have multiple majors, we pick two versions in between | ||
| lowest and highest. | ||
|
|
||
| #### Caveats | ||
|
|
||
| - Make sure the integration name is the same everywhere. If it consists of | ||
| multiple words, use an underscore instead of a hyphen. | ||
|
|
||
| ## Defining constraints | ||
|
|
||
| The `TEST_SUITE_CONFIG` dictionary defines, for each integration test suite, | ||
| the main package (framework, library) to test with; any additional test | ||
| dependencies, optionally gated behind specific conditions; and optionally | ||
| the Python versions to test on. | ||
|
|
||
| The format is: | ||
sentrivana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
sentrivana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| integration_name: { | ||
| "package": name_of_main_package_on_pypi, | ||
| "deps": { | ||
| rule1: [package1, package2, ...], | ||
| rule2: [package3, package4, ...], | ||
| }, | ||
| "python": python_version_specifier, | ||
| } | ||
| ``` | ||
|
|
||
| The following can be set as a rule: | ||
| - `*`: packages will be always installed | ||
| - a version specifier on the main package (e.g. `<=0.32`): packages will only | ||
| be installed if the main package falls into the version bounds specified | ||
| - specific Python version(s) in the form `py3.8,py3.9`: packages will only be | ||
| installed if the Python version matches one from the list | ||
szokeasaurusrex marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Rules can be used to specify version bounds on older versions of the main | ||
| package's dependencies, for example. If e.g. Flask tests generally need | ||
| Werkzeug and don't care about its version, but Flask older than 3.0 needs | ||
| a specific Werkzeug version to work, you can say: | ||
|
|
||
| ``` | ||
| "flask": { | ||
| "deps": { | ||
| "*": ["Werkzeug"], | ||
| "<3.0": ["Werkzeug<2.1.0"], | ||
szokeasaurusrex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Sometimes, things depend on the Python version installed. If the integration | ||
| test should only run on specific Python version, e.g. if you want AIOHTTP | ||
| tests to only run on Python 3.7+, you can say: | ||
|
|
||
| ``` | ||
| "aiohttp": { | ||
| ... | ||
| "python": ">=3.7", | ||
| } | ||
| ``` | ||
szokeasaurusrex marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If, on the other hand, you need to install a specific version of a secondary | ||
| dependency on specific Python versions (so the test suite should still run on | ||
| said Python versions, just with different dependency-of-a-dependency bounds), | ||
| you can say: | ||
|
|
||
| ``` | ||
| "celery": { | ||
| ... | ||
| "deps": { | ||
| "*": ["newrelic", "redis"], | ||
| "py3.7": ["importlib-metadata<5.0"], | ||
| }, | ||
| }, | ||
| ``` | ||
|
|
||
| ## How-Tos | ||
|
|
||
| ### Add a new test suite | ||
|
|
||
| 1. Add the minimum supported version of the framework/library to `_MIN_VERSIONS` | ||
| in `integrations/__init__.py`. This should be the lowest version of the | ||
| framework that we can guarantee works with the SDK. If you've just added the | ||
| integration, it's fine to set this to the latest version of the framework | ||
sentrivana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| at the time. | ||
| 2. Add the integration and any constraints to `TEST_SUITE_CONFIG`. See the | ||
| "Defining constraints" section for the format (or copy-paste one | ||
| of the existing entries). | ||
sentrivana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 3. Add the integration to one of the groups in the `GROUPS` dictionary in | ||
| `scripts/split_tox_gh_actions/split_tox_gh_actions.py`. | ||
| 4. Add the `TESTPATH` for the test suite in `tox.jinja`'s `setenv` section. | ||
| 5. Run `scripts/generate-test-files.sh` and commit the changes. | ||
|
|
||
| ### Migrate a test suite to populate_tox.py | ||
|
|
||
| A handful of integration test suites are still hardcoded. The goal is to migrate | ||
| them all to `populate_tox.py` over time. | ||
sentrivana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 1. Remove the integration from the `IGNORE` list in `populate_tox.py`. | ||
| 2. Remove the hardcoded entries for the integration from the `envlist` and `deps` sections of `tox.jinja`. | ||
| 2. Run `scripts/generate-test-files.sh`. | ||
sentrivana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 3. Run the test suite, either locally or by creating a PR. | ||
| 4. Address any test failures that happen. | ||
|
|
||
| You might have to introduce additional version bounds on the dependencies of the | ||
| package. Try to determine the source of the failure and address it. | ||
|
|
||
| Common scenarios: | ||
| - An old version of the tested package installs a dependency without defining | ||
| an upper version bound on it. A new version of the dependency is installed that | ||
| is incompatible with the package. In this case you need to determine which | ||
| versions of the dependency don't contain the breaking change and restrict this | ||
| in `TEST_SUITE_CONFIG`. | ||
| - Tests are failing on an old Python version. In this case first double-check | ||
| whether we were even testing them on that version in the original `tox.ini`. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.