Skip to content

Commit 22c2d80

Browse files
authored
Resolve Overrides (#37503)
* address an issue with not properly honoring the override variables which skip individual tox environments at runtime
1 parent 9d55b7f commit 22c2d80

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

scripts/devops_tasks/test_regression.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import logging
1717
from common_tasks import (
1818
run_check_call,
19-
parse_require,
2019
install_package_from_whl,
2120
filter_dev_requirements,
2221
find_packages_missing_on_pypi,
@@ -32,8 +31,9 @@
3231
clone_repo,
3332
)
3433

35-
from ci_tools.functions import discover_targeted_packages, str_to_bool, find_whl
36-
from ci_tools.parsing import ParsedSetup
34+
from ci_tools.functions import discover_targeted_packages, find_whl
35+
from ci_tools.parsing import ParsedSetup, parse_require
36+
from ci_tools.variables import str_to_bool
3737

3838
AZURE_GLOB_STRING = "azure*"
3939

@@ -407,7 +407,7 @@ def run_main(args):
407407
"--service",
408408
help=("Name of service directory (under sdk/) to test." "Example: --service applicationinsights"),
409409
)
410-
410+
411411
parser.add_argument(
412412
"--dependent-service",
413413
dest="dependent_service",

tools/azure-sdk-tools/ci_tools/build.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from subprocess import run
44

55
from typing import List
6-
from ci_tools.functions import discover_targeted_packages, str_to_bool, process_requires
6+
from ci_tools.functions import discover_targeted_packages, process_requires
77
from ci_tools.parsing import ParsedSetup
8-
from ci_tools.variables import DEFAULT_BUILD_ID
9-
from ci_tools.variables import discover_repo_root, get_artifact_directory
8+
from ci_tools.variables import DEFAULT_BUILD_ID, str_to_bool, discover_repo_root, get_artifact_directory
109
from ci_tools.versioning.version_shared import set_version_py, set_dev_classifier
1110
from ci_tools.versioning.version_set_dev import get_dev_version, format_build_id
1211
from ci_tools.logging import initialize_logger, run_logged

tools/azure-sdk-tools/ci_tools/conda/CondaConfiguration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import List, Any
1+
from typing import List, Any, Optional
22
import os
33
import bs4
44
import urllib3
5-
from ci_tools.functions import str_to_bool
5+
from ci_tools.variables import str_to_bool
66

77
http = urllib3.PoolManager()
88
# arguments: |
@@ -124,7 +124,7 @@ def __init__(
124124
common_root: str,
125125
in_batch: bool,
126126
checkout: List[CheckoutConfiguration],
127-
created_sdist_path: str = None,
127+
created_sdist_path: Optional[str] = None,
128128
service: str = "",
129129
conda_py_versions: List[str] = [],
130130
channels: List[str] = [],
@@ -133,17 +133,17 @@ def __init__(
133133
self.common_root: str = common_root
134134
self.in_batch: bool = in_batch
135135
self.checkout: List[CheckoutConfiguration] = checkout
136-
self.created_sdist_path: str = created_sdist_path
136+
self.created_sdist_path: Optional[str] = created_sdist_path
137137
self.service: str = service
138138
self.conda_py_versions = conda_py_versions
139139
self.channels = channels
140140

141141
@classmethod
142142
def from_json(cls, raw_json_blob: dict):
143-
name = raw_json_blob.get("name")
143+
name = raw_json_blob.get("name", None)
144144
common_root = raw_json_blob.get("common_root", None)
145145
in_batch = str_to_bool(raw_json_blob["in_batch"])
146-
checkout_config = parse_checkout_config(raw_json_blob.get("checkout"))
146+
checkout_config = parse_checkout_config(raw_json_blob.get("checkout", []))
147147
conda_py_versions = raw_json_blob.get("conda_py_versions", [])
148148
service = raw_json_blob.get("service", None)
149149
channels = raw_json_blob.get("channels", [])

tools/azure-sdk-tools/ci_tools/functions.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from packaging.version import Version, parse, InvalidVersion
1010
from pkg_resources import Requirement
1111

12-
from ci_tools.variables import discover_repo_root, DEV_BUILD_IDENTIFIER
12+
from ci_tools.variables import discover_repo_root, DEV_BUILD_IDENTIFIER, str_to_bool
1313
from ci_tools.parsing import ParsedSetup, get_config_setting
1414
from pypi_tools.pypi import PyPIClient
1515

@@ -134,20 +134,6 @@ def compare_python_version(version_spec: str) -> bool:
134134
return current_sys_version in spec_set
135135

136136

137-
def str_to_bool(input_string: str) -> bool:
138-
"""
139-
Takes a boolean string representation and returns a bool type value.
140-
"""
141-
if isinstance(input_string, bool):
142-
return input_string
143-
elif input_string.lower() in ("true", "t", "1"):
144-
return True
145-
elif input_string.lower() in ("false", "f", "0"):
146-
return False
147-
else:
148-
return False
149-
150-
151137
def generate_difference(original_packages: List[str], filtered_packages: List[str]):
152138
return list(set(original_packages) - set(filtered_packages))
153139

tools/azure-sdk-tools/ci_tools/parsing/parse_functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from packaging.specifiers import SpecifierSet
2727
from setuptools import Extension
2828

29+
from ci_tools.variables import str_to_bool
2930

3031
NEW_REQ_PACKAGES = ["azure-core", "azure-mgmt-core"]
3132

@@ -146,9 +147,10 @@ def get_config_setting(package_path: str, setting: str, default: Any = True) ->
146147
pyproject.toml. If the input 'setting' does NOT exist, the provided default value will be returned.
147148
"""
148149
# we should always take the override if one is present
149-
override_value = os.getenv(f"{os.path.basename(package_path).upper()}_{setting.upper()}", None)
150+
override_value = os.getenv(f"{os.path.basename(package_path).upper().replace('-','_')}_{setting.upper()}", None)
151+
150152
if override_value:
151-
return override_value
153+
return str_to_bool(override_value)
152154

153155
# if no override, check for the config setting in the pyproject.toml
154156
config = get_build_config(package_path)

tools/azure-sdk-tools/ci_tools/variables.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import os
22

3+
def str_to_bool(input_string: str) -> bool:
4+
"""
5+
Takes a boolean string representation and returns a bool type value.
6+
"""
7+
if isinstance(input_string, bool):
8+
return input_string
9+
elif input_string.lower() in ("true", "t", "1"):
10+
return True
11+
elif input_string.lower() in ("false", "f", "0"):
12+
return False
13+
else:
14+
return False
15+
316

417
def discover_repo_root(input_repo: str = None):
518
"""

tools/azure-sdk-tools/tests/test_pyproject_interactions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from ci_tools.parsing import update_build_config, get_build_config, get_config_setting
7+
from ci_tools.environment_exclusions import is_check_enabled
78

89
integration_folder = os.path.join(os.path.dirname(__file__), "integration")
910
pyproject_folder = os.path.join(integration_folder, "scenarios", "sample_pyprojects")
@@ -58,6 +59,22 @@ def test_nonpresent_pyproject_update():
5859
reloaded_build_config = get_build_config(new_path)
5960
assert reloaded_build_config == update_result
6061

62+
@pytest.mark.parametrize(
63+
"check_name, environment_value, expected_result",
64+
[
65+
("mindependency", "true", True),
66+
("mindependency", "false", False)
67+
]
68+
)
69+
def test_environment_override(check_name, environment_value, expected_result):
70+
with tempfile.TemporaryDirectory() as temp_dir:
71+
new_path = shutil.copy(pyproject_file, temp_dir)
72+
73+
os.environ[f"{os.path.basename(temp_dir).upper()}_{check_name.upper()}"] = environment_value
74+
result = is_check_enabled(temp_dir, check_name)
75+
76+
assert result == expected_result
77+
6178

6279
def test_pyproject_update_check_override():
6380
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)