Skip to content

Commit bebf8d2

Browse files
scbeddCopilot
andauthored
Resolve nightly core failure (#41655)
* scope the search for _version.py. the issue was that core was nondeterministically picking up a tests/**/_version.py file and THAT was why we were crashing 'randomly' on wrong package version errors --------- Co-authored-by: Copilot <[email protected]>
1 parent 17d094e commit bebf8d2

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
keywords: List[str],
5353
ext_package: str,
5454
ext_modules: List[Extension],
55-
metapackage: bool
55+
metapackage: bool,
5656
):
5757
self.name: str = name
5858
self.version: str = version
@@ -109,7 +109,7 @@ def from_path(cls, parse_directory_or_file: str):
109109
keywords,
110110
ext_package,
111111
ext_modules,
112-
metapackage
112+
metapackage,
113113
)
114114

115115
def get_build_config(self) -> Optional[Dict[str, Any]]:
@@ -230,7 +230,9 @@ def read_setup_py_content(setup_filename: str) -> str:
230230

231231
def parse_setup_py(
232232
setup_filename: str,
233-
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool]:
233+
) -> Tuple[
234+
str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool
235+
]:
234236
"""
235237
Used to evaluate a setup.py (or a directory containing a setup.py) and return a tuple containing:
236238
(
@@ -305,8 +307,6 @@ def setup(*args, **kwargs):
305307
else:
306308
metapackage = True
307309

308-
309-
310310
requires = kwargs.get("install_requires", [])
311311
package_data = kwargs.get("package_data", None)
312312
include_package_data = kwargs.get("include_package_data", None)
@@ -340,7 +340,9 @@ def setup(*args, **kwargs):
340340

341341
def parse_pyproject(
342342
pyproject_filename: str,
343-
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool]:
343+
) -> Tuple[
344+
str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool
345+
]:
344346
"""
345347
Used to evaluate a pyproject (or a directory containing a pyproject.toml) with a [project] configuration within.
346348
Returns a tuple containing:
@@ -383,7 +385,9 @@ def parse_pyproject(
383385
else:
384386
parsed_version = "0.0.0"
385387
else:
386-
raise ValueError(f"Unable to find a version value directly set in \"{pyproject_filename}\", nor is it available in a \"version.py\" or \"_version.py.\"")
388+
raise ValueError(
389+
f'Unable to find a version value directly set in "{pyproject_filename}", nor is it available in a "version.py" or "_version.py."'
390+
)
387391

388392
name = project_config.get("name")
389393
version = parsed_version
@@ -426,9 +430,32 @@ def get_version_py(setup_path: str) -> Optional[str]:
426430
"""
427431
Given the path to pyproject.toml or setup.py, attempts to find a (_)version.py file and return its location.
428432
"""
433+
# this list of directories will be excluded from the search for _version.py
434+
# this is to avoid finding _version.py in the wrong place, such as in tests
435+
# or in the venv directory or ANYWHERE ELSE that may mess with the parsing.
436+
EXCLUDE = {
437+
"venv",
438+
"__pycache__",
439+
"tests",
440+
"test",
441+
"generated_samples",
442+
"generated_tests",
443+
"samples",
444+
"swagger",
445+
"stress",
446+
"docs",
447+
"doc",
448+
"local",
449+
"scripts",
450+
"images",
451+
}
452+
429453
file_path, _ = os.path.split(setup_path)
454+
430455
# Find path to _version.py recursively
431-
for root, _, files in os.walk(file_path):
456+
for root, dirs, files in os.walk(file_path):
457+
dirs[:] = [d for d in dirs if d not in EXCLUDE and not d.endswith(".egg-info")]
458+
432459
if VERSION_PY in files:
433460
return os.path.join(root, VERSION_PY)
434461
elif OLD_VERSION_PY in files:

tools/azure-sdk-tools/ci_tools/scenario/generation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def create_package_and_install(
6868
if cache_dir:
6969
commands_options.extend(["--cache-dir", cache_dir])
7070

71+
target_package = ParsedSetup.from_path(setup_py_path)
72+
7173
discovered_packages = discover_packages(
7274
setup_py_path, distribution_directory, target_setup, package_type, force_create
7375
)
7476

75-
target_package = ParsedSetup.from_path(setup_py_path)
76-
7777
# ensure that discovered packages are always copied to the distribution directory regardless of other factors
7878
for built_package in discovered_packages:
7979
if os.getenv("PREBUILT_WHEEL_DIR") is not None:

tools/azure-sdk-tools/ci_tools/versioning/version_set_dev.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def version_set_dev_main() -> None:
9090
for target_package in target_packages:
9191
try:
9292
new_version = get_dev_version(target_package.version, build_id)
93-
print("{0}: {1} -> {2}".format(target_package.name, target_package.version, new_version))
94-
93+
print(f"Processing {target_package.name}.")
9594
process_requires(target_package.setup_filename, True)
9695
set_version_py(target_package.setup_filename, new_version)
9796
set_dev_classifier(target_package.setup_filename, new_version)
97+
print("{0}: {1} -> {2}".format(target_package.name, target_package.version, new_version))
9898
except:
9999
print("Could not set dev version for package: {0}".format(target_package.name))

tools/azure-sdk-tools/ci_tools/versioning/version_shared.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def get_packages(
7979
def set_version_py(setup_path, new_version):
8080
version_py_location = get_version_py(setup_path)
8181

82+
if not version_py_location:
83+
logging.error("No version.py file found in {}".format(setup_path))
84+
sys.exit(1)
85+
8286
version_contents = ""
8387
with open(version_py_location, "r") as version_py_file:
8488
version_contents = version_py_file.read()

0 commit comments

Comments
 (0)