Skip to content

Commit

Permalink
ci: update which packages to select for update (#10612)
Browse files Browse the repository at this point in the history
Skip over pinned modules when checking for outdated packages. 

Since the modules are pinned, we won't actually update the latest that
we use from the riotfile, so it is not necessary to include them in the
list of candidates for updating a package version.

Future items:
- Figure out a more robust solution for mapping the suite name to the
integration name (currently hardcoded in a `dict`)



## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -

---------

Co-authored-by: Emmett Butler <723615+emmettbutler@users.noreply.github.com>
  • Loading branch information
quinna-h and emmettbutler authored Sep 24, 2024
1 parent cf6f007 commit 3ef1c30
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions scripts/freshvenvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@
import pathlib
import sys
import typing
from typing import Optional

from packaging.version import Version
from pip import _internal


sys.path.append(str(pathlib.Path(__file__).parent.parent.resolve()))
import riotfile # noqa: E402

CONTRIB_ROOT = pathlib.Path("ddtrace/contrib")

CONTRIB_ROOT = pathlib.Path("ddtrace/contrib")
LATEST = ""

suite_to_package = {
"consul": "python-consul",
"snowflake": "snowflake-connector-python",
"flask_cache": "flask-caching",
"graphql": "graphql-core",
"mysql": "mysql-connector-python",
"asyncio": "pytest-asyncio",
"sqlite3": "pysqlite3-binary",
"grpc": "grpcio",
"psycopg2": "psycopg2-binary",
"cassandra": "cassandra-driver",
"rediscluster": "redis-py-cluster",
}

class Capturing(list):
def __enter__(self):
Expand Down Expand Up @@ -66,11 +83,22 @@ def _get_riot_envs_including_any(modules: typing.Set[str]) -> typing.Set[str]:
return envs


def _get_packages_implementing(modules: typing.Set[str]) -> typing.Set[str]:
return {m for m in modules if "." not in m}
def _get_updatable_packages_implementing(modules: typing.Set[str]) -> typing.Set[str]:
"""Return all packages that can be updated and have contribs implemented for them"""
all_venvs = riotfile.venv.venvs

for v in all_venvs:
package = v.name
if package not in modules:
continue
if not _venv_sets_latest_for_package(v, package):
modules.remove(package)

packages = {m for m in modules if "." not in m}
return packages


def _get_version_extremes(package_name: str) -> typing.Tuple[str, str]:
def _get_version_extremes(package_name: str) -> typing.Tuple[Optional[str], Optional[str]]:
"""Return the (earliest, latest) supported versions of a given package"""
with Capturing() as output:
_internal.main(["index", "versions", package_name])
Expand Down Expand Up @@ -124,9 +152,30 @@ def _versions_fully_cover_bounds(bounds: typing.Tuple[str, str], versions: typin
return versions[0] >= Version(upper_bound)


def _venv_sets_latest_for_package(venv: riotfile.Venv, suite_name: str) -> bool:
"""
Returns whether the Venv for the package uses `latest` or not.
DFS traverse through the Venv, as it may have nested Venvs.
If the suite name is in suite_to_package, remap it.
"""
package = suite_to_package.get(suite_name, suite_name)

if package in venv.pkgs:
if LATEST in venv.pkgs[package]:
return True

if venv.venvs:
for child_venv in venv.venvs:
if _venv_sets_latest_for_package(child_venv, package):
return True

return False


def main():
all_required_modules = _get_integrated_modules()
all_required_packages = _get_packages_implementing(all_required_modules)
all_required_packages = _get_updatable_packages_implementing(all_required_modules)
envs = _get_riot_envs_including_any(all_required_modules)

bounds = dict()
Expand Down

0 comments on commit 3ef1c30

Please sign in to comment.