Skip to content

build!: require FOCA 0.17 and Python 3.13 - #245

Merged
uniqueg merged 9 commits into
devfrom
build/foca-0-17-python-3-13
Oct 23, 2026
Merged

uniqueg merged 9 commits into
devfrom
build/foca-0-17-python-3-13

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

proTES now targets FOCA 0.17 and one Python version, 3.13 (the base image's). FOCA 0.17.0 isn't on PyPI yet, so this PR builds and tests against a pinned FOCA dev commit, as cloud-registry did in elixir-cloud-aai/cloud-registry#184. A follow-up switches to the release.

  • Temporary FOCA pins
    • pyproject.toml pins foca @ git+https://github.com/elixir-cloud-aai/foca@29af8a64a2b0aae21845fa37a4a54076811f62bf (FOCA dev, including the 0.17.0 pre-release fixes), marked TEMPORARY.

    • The Dockerfile builds FROM elixircloud/foca:20261023-py3.13@sha256:1e1275f7…, FOCA's development image of that commit (FOCA 0.16.1.dev16+g29af8a64a). The comment ## FOCA commit: <sha> records the commit.

    • scripts/image_requirements.py (ported from cloud-registry) leaves the Git pin out of the image's requirements, because the image has no Git. It fails the build unless the base image's FOCA is that commit.

    • scripts/check_release_pins.py (ported) fails while any of these is left: a direct reference, a pre-release dependency, a non-release base image tag or a non-release chart dependency. proTES has no release workflow yet (ci: release from signed version tags #44, PR ci!: release from signed version tags #230 is still a draft), so the check runs in two places:

      • the new workflow release-pins.yaml, on every pushed v* tag, before the GitHub release is published (Zenodo archives at that point);
      • tests/test_check_release_pins.py::test_release_checkout, for checkouts of release tags.

      ci: release from signed version tags #44 has a comment saying that the release workflow must run the check.

    • Dependabot ignores the base image for now.

    • tests/test_build.py checks two things: the base image matches the foca pin (release or commit), and the Python version is the same everywhere.

  • Python 3.13 only
    • requires-python = ">=3.13", with only 3.13 in the classifiers. ruff and mypy target 3.13. tomli and the 3.10 code paths are gone, and ruff's UP017 fixes are applied.
    • CI runs one Run tests (mongomock) job (no matrix, no Python version in the name) and Run tests (MongoDB 7.0), with the aggregate required check Run tests, as in cloud-registry. Linting and docs run on 3.13, and so does Read the Docs.
    • The build stage that compiled typed-ast is gone. The image is single-stage again, as in cloud-registry.
  • ip2geotools replaced
    • build!: require FOCA 0.17 and Python 3.13 #214 named no specific replacement. ip2geotools has had no release since 2021 and requires typed-ast, which doesn't build on 3.13.
    • DbIpCity.get() called DB-IP's free API for the city, region and country, then OpenStreetMap's Nominatim, through the unmaintained geocoder package, for the coordinates.
    • The middleware now makes these two calls itself (locate_ip() in distance.py), with the same queries and the same fallback without the region:
      • DB-IP over HTTPS (it was HTTP), with the address URL-escaped;
      • Nominatim through geopy, which is maintained (2.5.0) and already a dependency, with a user agent naming the app, as Nominatim's usage policy requires.
    • No new dependency is added; requests is now declared, because proTES uses it directly. The timeout is 10 s (it was 62 s), and each IP address is looked up once per task. Every failure raises MiddlewareException, so the random middleware takes over as before.
    • Found in review and fixed: addresses that are not global (private, loopback, reserved) are no longer sent to the services, and places without a city or country (DB-IP's ZZ) are no longer geocoded. Before, Nominatim matched such queries to an arbitrary place, as it already did with ip2geotools.
    • Storing geolocations and a configurable provider stay in perf: store geolocations of TES instances #130.
  • FOCA features that replace proTES code
    • The 401 WWW-Authenticate shim from feat(auth)!: require tokens for task operations #212 is removed: FOCA ≥ 0.16 sends the Bearer challenge itself (with an error_description).
    • api.specs (tes) and security.access_control.policies (users-create-list-tasks, users-get-cancel-tasks) are named entries. Overlays can change single rules or specs by name, and overlays that give lists still replace them.
  • Auth
    • The config sets verify_token_type: True explicitly and documents the clients allowlist with a generic placeholder (no default).
    • New tests: ID tokens (typ: JWT) get 401; with clients, tokens of other clients or without a client get 401, while client_id and azp matches pass; a named-policy overlay removes one rule.
  • Docs: upgrade notes (FOCA 0.17/Python 3.13, token types and clients, named entries, atomic configured policies and rolling updates, geolocation), access control, middlewares (DB-IP and Nominatim and what they learn), development (temporary pins) and contributing (one Python version).

Out of scope, as decided: TES 1.1 (#241), service tokens (#213), task ownership (#215), chart (#216), middlewares (#217).

Closes #214

How it was verified

  • coverage run -m pytest (Python 3.13.15, FOCA 0.16.1.dev16+g29af8a64a): 305 passed, 1 skipped (test_release_checkout, not a release checkout); coverage report 100%.
  • MONGODB_TEST_URI=… pytest against mongo:7.0: 294 passed, 1 skipped.
  • pre-commit run --all-files and --hook-stage manual gitleaks-all: passed.
  • mkdocs build --strict: passed.
  • Docker Compose smoke test (docker-compose.yaml:tests/smoke/compose.yaml, up --build --wait, tests/smoke/check.sh): passed. The image runs Python 3.13.17 and FOCA 0.16.1.dev16+g29af8a64a, and has neither ip2geotools nor typed-ast.
  • In the built image, locate_ip() worked against the live services: 8.8.8.8 gave Mountain View and 193.166.3.2 gave Espoo.
  • CI: all checks passed (Static code analysis, Run tests (mongomock), Run tests (MongoDB 7.0), Run tests, Build documentation, Run app with Docker Compose, which builds the image on the dev base image).

Sourcery review

Sourcery opened 2 threads. Both are answered and resolved:

  • Fixed in d91d175: the release pin check now also rejects PEP 440 local versions (e.g., ==0.17.0+gabc1234).
  • Declined, not in scope: "rate-limit and cache geolocation lookups across tasks". This is unchanged from ip2geotools and is the scope of perf: store geolocations of TES instances #130; until then, a failed lookup falls back to the random middleware.

Declined review findings

  • Reference a follow-up issue for the release swap in the TEMPORARY comments (quality, low). cloud-registry cites feat: update TES models to v1.1 #179. For proTES I have not opened an issue without approval. The follow-up is listed below and tracked by the comment on build!: require FOCA 0.17 and Python 3.13 #214, and the release-pin check makes a forgotten swap fail.
  • release-pins.yaml only reports and can't block publishing a release from the tag (adversarial and quality, round 2, low). Accepted until the release workflow of ci: release from signed version tags #44 runs the check before publishing; docs/development.md says to check the result first, and ci: release from signed version tags #44 has a comment about it.
  • test_rank_same_address doesn't test ordering (quality, round 2, low). Intended: it tests deduplication; the order of lookups depends on set() upstream anyway.
  • Name Nominatim's user agent in the docs (quality, low). Left out to keep the docs short; it is in the code (USER_AGENT).

Open questions

None.

Follow-up once FOCA 0.17.0 is released

  • pyproject.toml: foca>=0.17.0,<0.18 instead of the Git pin; remove the TEMPORARY comment.
  • Dockerfile: FROM elixircloud/foca:0.17.0-py3.13@sha256:<digest>; remove the ## FOCA commit line and the TEMPORARY comment.
  • .github/dependabot.yml: remove the temporary elixircloud/foca ignore, keeping the minor/major one.
  • docs/upgrading.md stays as it is. The release guard keeps failing on release checkouts until then.

🤖 Generated with Claude Code

uniqueg and others added 8 commits October 23, 2026 05:19
ip2geotools (last release 2021) is unmaintained and requires typed-ast,
which doesn't build on Python 3.13. The distance-based middleware now
calls the services that ip2geotools used directly: DB-IP's free API
for the place of an IP address (over HTTPS instead of HTTP), and
Nominatim, via geopy (already a dependency), for its coordinates, with
the same fallback query without the region.

Requests time out after 10 seconds (was 62), and each IP address is
located once per task. requests is declared, as proTES uses it directly.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
proTES targets one Python version, that of the base image: 3.13. CI
runs one mongomock test job (no Python version in its name) besides
the MongoDB job, with the aggregate check "Run tests"; linting, docs
and Read the Docs use 3.13, too. tests/test_build.py checks that the
versions match.

Until FOCA 0.17.0 is released, proTES is built and tested against a
FOCA dev commit, with FOCA's dev image of that commit as base image,
pinned by digest (as in cloud-registry): scripts/image_requirements.py
leaves the pin out of the image's requirements and fails unless the
base image has that commit; scripts/check_release_pins.py, run by the
tests for release checkouts, fails while dev pins are left. Dependabot
ignores the base image meanwhile. The build stage that compiled
typed-ast is no longer needed.

BREAKING CHANGE: Python 3.10 to 3.12 are no longer supported. With
FOCA 0.16 and 0.17, only access tokens (typ header at+jwt) are
accepted, and configured policy rules are replaced atomically on
startup (removed if no rules are configured); see docs/upgrading.md.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.16 adds the WWW-Authenticate challenge to 401 responses, so the
after_request function that proTES added for FOCA 0.15 is removed.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The base config sets verify_token_type explicitly and documents the
new clients allowlist (no default); the docs describe both, and the
tests check that ID tokens and tokens of clients that aren't listed
are rejected with 401.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.17's named entries let overlays change, add or remove single
specs or policy rules by name, instead of restating the lists. Lists
in overlays still replace them.

Closes #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses that are not global (e.g., private ones of hosts in the same
cluster) are no longer sent to the geolocation services, and places
without city or country (DB-IP's answer for reserved addresses) are
not geocoded: Nominatim matched such near-empty queries to arbitrary
places, by which tasks were distributed. The middleware falls back to
the next one for them. Each address is located once per task.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
proTES has no release workflow yet (#44), and the tests skip the pin
check in CI, whose checkouts have no tags. A workflow for pushed
release tags runs scripts/check_release_pins.py, so that a tag with
development pins fails before its GitHub release is published.

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR upgrades proTES to FOCA 0.17 and Python 3.13 using a digest-pinned FOCA development image, adds automated safeguards for build/release pin consistency, replaces the incompatible geolocation dependency with direct DB-IP/Nominatim integration, and adopts FOCA's authentication and named-configuration features.

Sequence diagram for IP geolocation during distance-based task distribution

sequenceDiagram
    participant Middleware
    participant DBIP
    participant Nominatim

    Middleware->>Middleware: ip_address_info(ip_address)
    alt address is not global
        Middleware-->>Middleware: MiddlewareException
    else address is global
        Middleware->>DBIP: requests.get(DB_IP_URL, timeout=TIMEOUT)
        DBIP-->>Middleware: city, region, country
        alt city or country unavailable
            Middleware-->>Middleware: MiddlewareException
        else place is available
            Middleware->>Nominatim: geocode(query)
            alt region query not found
                Middleware->>Nominatim: geocode(city, country)
            end
            Nominatim-->>Middleware: latitude, longitude
            Middleware-->>Middleware: Location
        end
    end
Loading

Flow diagram for release pin safeguards

flowchart TD
    Tag[Push v* tag] --> Workflow[release-pins.yaml]
    Workflow --> Check[check_release_pins.py]
    Check --> Dependencies[Check project dependencies]
    Check --> Base[Check FOCA base image tag]
    Check --> Chart[Check Helm chart versions]
    Dependencies --> Result{All are releases?}
    Base --> Result
    Chart --> Result
    Result -->|yes| Publish[Release may be published]
    Result -->|no| Fail[Fail with release-pin errors]
Loading

File-Level Changes

Change Details Files
Upgrade the supported runtime and FOCA integration to Python 3.13 and a pinned FOCA 0.17 development commit, while adding consistency and release-safety checks.
  • Pin FOCA in packaging and the matching development base image by digest.
  • Remove the multi-stage typed-ast build and install image requirements without Git.
  • Add checks for matching FOCA/base-image commits, consistent Python versions, and release-only dependency pins.
  • Update CI, documentation builds, Dependabot, and release-tag validation for the single Python version.
.github/dependabot.yml
.github/workflows/checks.yaml
.github/workflows/release-pins.yaml
.readthedocs.yaml
Dockerfile
pyproject.toml
scripts/image_requirements.py
scripts/check_release_pins.py
tests/test_build.py
tests/test_check_release_pins.py
tests/test_image_requirements.py
docs/contributing.md
docs/development.md
Replace ip2geotools-based distance geolocation with explicit DB-IP and Nominatim lookups and safer failure handling.
  • Call DB-IP over HTTPS and geocode returned city/region/country through geopy's Nominatim with timeouts and a policy-compliant user agent.
  • Reject invalid, non-global, unknown, or incomplete locations and deduplicate IP lookups per task.
  • Preserve fallback lookup behavior and raise MiddlewareException so downstream middleware can take over.
  • Add focused tests for successful lookups, fallback queries, service failures, filtering, and deduplication.
pro_tes/plugins/middlewares/task_distribution/distance.py
pyproject.toml
docs/middlewares.md
docs/upgrading.md
tests/plugins/middlewares/task_distribution/test_distance.py
Adopt FOCA 0.17 authentication, named configuration entries, and native Bearer challenge behavior.
  • Remove the local 401 Bearer challenge shim now provided by FOCA.
  • Enable token-type validation and document/configure optional client allowlisting.
  • Convert API specs and access-control policies to named entries supporting targeted overlay changes and removals.
  • Add tests for ID-token rejection, client claims, named policy overlays, and updated challenges.
pro_tes/app.py
pro_tes/config.yaml
pro_tes/security.py
docs/access-control.md
docs/upgrading.md
tests/ga4gh/tes/test_access_control.py
tests/conftest.py
Modernize Python 3.13-specific code and documentation throughout the project.
  • Replace compatibility paths such as tomli and older datetime APIs with Python 3.13-native implementations.
  • Update Ruff, mypy, classifiers, requirements, tests, and development guidance to target only Python 3.13.
  • Document FOCA/Python upgrade requirements, authentication changes, named configuration semantics, geolocation behavior, and rolling-update considerations.
pyproject.toml
scripts/citation.py
pro_tes/utils/misc.py
tests/test_version.py
tests/ga4gh/tes/test_models.py
tests/ga4gh/tes/test_server.py
tests/test_citation.py
docs/access-control.md
docs/contributing.md
docs/development.md
docs/upgrading.md

Assessment against linked issues

Issue Objective Addressed Explanation
#214 Target Python 3.13 only and migrate to FOCA 0.17, including replacing ip2geotools so the application builds and runs on the Python 3.13 base image. ✅
#214 Enforce access-token type validation and optionally restrict accepted tokens to deployment-configured clients, with tests confirming invalid token types and unlisted or missing clients receive 401 responses. ✅
#214 Apply the FOCA migration changes needed by the upgrade and document the resulting configuration and deployment behavior using generic, deployment-supplied identity settings rather than ELIXIR-specific defaults. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6b84763) to head (d91d175).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #245    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           20        22     +2     
  Lines          987      1097   +110     
==========================================
+ Hits           987      1097   +110     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 23, 2026 10:32

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pro_tes/plugins/middlewares/task_distribution/distance.py" line_range="93" />
<code_context>
+    if region:
+        queries.insert(0, f"{city}, {region} {country}")
+    geocoder = Nominatim(user_agent=USER_AGENT, timeout=TIMEOUT)
+    for query in queries:
+        try:
+            point = geocoder.geocode(query)
</code_context>
<issue_to_address>
**Distance routing falls back**

When multiple addresses or concurrent and repeated tasks generate geocoding requests, `locate_ip` sends each query immediately, while `_get_ip_locations` deduplicates only within one task. Nominatim rejects over-limit calls, and repeated lookups consume DB-IP’s daily allowance; the resulting errors raise `MiddlewareException` and send placement to random routing.

Apply an application-wide rate limit and reuse IP-location results across tasks to stay within Nominatim’s one-request-per-second limit and avoid exhausting DB-IP’s daily allowance.

Also at `pro_tes/plugins/middlewares/task_distribution/distance.py:95`, `pro_tes/plugins/middlewares/task_distribution/distance.py:313`.
</issue_to_address>

### Comment 2
<location path="scripts/check_release_pins.py" line_range="108" />
<code_context>
+            pins.append(
+                f"pyproject.toml: dependency '{requirement}' is a direct reference"
+            )
+        elif PRE_RELEASE.search(re.sub(NAME, "", requirement).split(";")[0]):
+            pins.append(
+                f"pyproject.toml: dependency '{requirement}' names a pre-release"
</code_context>
<issue_to_address>
**Custom builds pass the release check**

When a dependency is pinned to a PEP 440 local version such as `==1.2.3+gabc`, `PRE_RELEASE` does not recognize local version labels, so `find_dev_pins` accepts the requirement and a release can include a dependency build that is not a released version.

Recognize and reject PEP 440 local version labels in the release-pin check.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and the FOCA upgrade changes token validation and how named access-control rules are applied and persisted at startup. If those rules admit unintended requests, reverting will not undo data accessed while the change was live; the new geolocation flow also sends derived place information to Nominatim.

Blocking findings: pro_tes/plugins/middlewares/task_distribution/distance.py:93, scripts/check_release_pins.py:108


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/check_release_pins.py Resolved
PEP 440 local versions (e.g., ==0.17.0+gabc1234) are builds, not
releases, so the release pin check reports them, too (Sourcery).

Refs #214

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit ec95fec into dev Oct 23, 2026
13 checks passed
@uniqueg
uniqueg deleted the build/foca-0-17-python-3-13 branch October 23, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build!: require FOCA 0.17 and Python 3.13

1 participant