Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit fb5c1c3

Browse files
committed
use generated async-rest constraints files
1 parent a9f35e7 commit fb5c1c3

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% set rest_async_io_enabled = api.all_library_settings[api.naming.proto_package].python_settings.experimental_features.rest_async_io_enabled %}
2+
{% if rest_async_io_enabled %}
3+
# -*- coding: utf-8 -*-
4+
{% from '_pypi_packages.j2' import pypi_packages %}
5+
# This constraints file is used to check that lower bounds
6+
# are correct in setup.py
7+
# List all library dependencies and extras in this file,
8+
# pinning their versions to their lower bounds.
9+
# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0",
10+
# then this file should have google-cloud-foo==1.14.0
11+
google-api-core==2.21.0
12+
google-auth==2.35.0
13+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453)
14+
# Add the minimum supported version of grpcio to constraints files
15+
proto-plus==1.22.3
16+
protobuf==4.25.8
17+
{% for package_tuple, package_info in pypi_packages.items() %}
18+
{# Quick check to make sure `package_info.package_name` is not the package being generated so we don't circularly include this package in its own constraints file. #}
19+
{% if api.naming.warehouse_package_name != package_info.package_name %}
20+
{% if api.requires_package(package_tuple) %}
21+
{{ package_info.package_name }}=={{ package_info.lower_bound }}
22+
{% endif %}
23+
{% endif %}
24+
{% endfor %}
25+
{% endif %}

noxfile.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -357,35 +357,21 @@ def showcase_library(
357357
constraints_path = str(
358358
f"{tmp_dir}/testing/constraints-{session.python}.txt"
359359
)
360-
if not rest_async_io_enabled:
361-
# Install the library with a constraints file.
362-
session.install("-e", tmp_dir, "-r", constraints_path)
363-
else:
364-
# Modify constraints file to support async_rest min constraints.
365-
# TODO: Move into own contraints-async-rest.txt file once
366-
# async-rest is fully supported
367-
async_rest_constraints = {
368-
"google-auth": "2.35.0",
369-
"google-api-core": "2.21.0",
370-
}
371-
with open(constraints_path) as f:
372-
constraints_lines = [
373-
line.strip()
374-
for line in f
375-
if line.strip() and not line.startswith("#")
376-
]
377-
# Only modify dependencies in the original constraints file.
378-
replace_keys = {
379-
key for key in async_rest_constraints
380-
if any(line.startswith(key) for line in constraints_lines)
381-
}
382-
# Replace async_rest constraints in final output.
383-
constraints = [
384-
line for line in constraints_lines
385-
if not any(line.startswith(key) for key in replace_keys)
386-
] + [f"{k}=={async_rest_constraints[k]}" for k in replace_keys]
387-
388-
session.install("-e", f"{tmp_dir}[async_rest]", *constraints)
360+
extras = ""
361+
if rest_async_io_enabled:
362+
async_rest_constraints_path = str(
363+
f"{tmp_dir}/testing/constraints-3.9-async-rest.txt"
364+
)
365+
if os.path.exists(async_rest_constraints_path):
366+
# use async-rest constraints if available
367+
constraints_path = async_rest_constraints_path
368+
else:
369+
session.log(
370+
f"{async_rest_constraints_path} not found. Using base constraints file"
371+
)
372+
extras = "[async_rest]"
373+
374+
session.install("-e", f"{tmp_dir}{extras}", "-r", constraints_path)
389375
else:
390376
# The ads templates do not have constraints files.
391377
# See https://github.com/googleapis/gapic-generator-python/issues/1788
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
# This constraints file is used to check that lower bounds
3+
# are correct in setup.py
4+
# List all library dependencies and extras in this file,
5+
# pinning their versions to their lower bounds.
6+
# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0",
7+
# then this file should have google-cloud-foo==1.14.0
8+
google-api-core==2.21.0
9+
google-auth==2.35.0
10+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453)
11+
# Add the minimum supported version of grpcio to constraints files
12+
proto-plus==1.22.3
13+
protobuf==4.25.8
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
# This constraints file is used to check that lower bounds
3+
# are correct in setup.py
4+
# List all library dependencies and extras in this file,
5+
# pinning their versions to their lower bounds.
6+
# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0",
7+
# then this file should have google-cloud-foo==1.14.0
8+
google-api-core==2.21.0
9+
google-auth==2.35.0
10+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453)
11+
# Add the minimum supported version of grpcio to constraints files
12+
proto-plus==1.22.3
13+
protobuf==4.25.8

0 commit comments

Comments
 (0)