Skip to content

Commit 126ab05

Browse files
scbeddl0lawrence
authored andcommitted
Remove unnecessary variable defaults (Azure#37604)
* apply black and prepare for parsing the ci.yml so that we can understand if testproxy is enabled or disabled * The language specific cert trust in Language-Settings has been updated to no longer globally set environment variables SSL_CERT_DIR, SSL_CERT_FILE, and REQUEST_CA_BUNDLE. These are dynamically set in proxy_startup.py
1 parent 8fe2475 commit 126ab05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+608
-284
lines changed

.vscode/cspell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@
470470
"dicom",
471471
"WINDOWSVMIMAGE",
472472
"LINUXVMIMAGE",
473-
"MACVMIMAGE"
473+
"MACVMIMAGE",
474+
"myuseragent"
474475
],
475476
"overrides": [
476477
{

eng/pipelines/templates/variables/globals.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ variables:
1111
REPOROOT: $(Build.SourcesDirectory)
1212
WINDOWS_OUTPUTROOT: $(REPOROOT)\out
1313
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest'
14+
GDN_SUPPRESS_FORKED_BUILD_WARNING: true

eng/scripts/Language-Settings.ps1

+2-5
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,8 @@ function Get-python-DocsMsMetadataForPackage($PackageInfo) {
391391

392392
function Import-Dev-Cert-python
393393
{
394-
Write-Host "Python Trust Methodology"
395-
396-
$pathToScript = Resolve-Path (Join-Path -Path $PSScriptRoot -ChildPath "../../scripts/devops_tasks/trust_proxy_cert.py")
397-
python -m pip install requests
398-
python $pathToScript
394+
Write-Host "Python no longer requires an out of proc trust methodology." `
395+
"The variables SSL_CERT_DIR, SSL_CERT_FILE, and REQUESTS_CA_BUNDLE are now dynamically set in proxy_startup.py"
399396
}
400397

401398
# Defined in common.ps1 as:

scripts/devops_tasks/tox_harness.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ def prep_and_run_tox(targeted_packages: List[str], parsed_args: Namespace) -> No
354354
"setup_execute_tests.py -> tox_harness.py::prep_and_run_tox",
355355
)
356356

357-
return_code = execute_tox_serial(tox_command_tuples)
357+
return_result = execute_tox_serial(tox_command_tuples)
358358

359359
if not parsed_args.disablecov:
360360
collect_tox_coverage_files(targeted_packages)
361361

362-
sys.exit(return_code)
362+
sys.exit(return_result) #type: ignore

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ci_tools.versioning.version_shared import set_version_py, set_dev_classifier
1010
from ci_tools.versioning.version_set_dev import get_dev_version, format_build_id
1111

12+
1213
def build() -> None:
1314
parser = argparse.ArgumentParser(
1415
description="""This is the primary entrypoint for the "build" action. This command is used to build any package within the azure-sdk-for-python repository.""",
@@ -102,7 +103,9 @@ def build() -> None:
102103
else:
103104
target_dir = repo_root
104105

105-
logging.debug(f"Searching for packages starting from {target_dir} with glob string {args.glob_string} and package filter {args.package_filter_string}")
106+
logging.debug(
107+
f"Searching for packages starting from {target_dir} with glob string {args.glob_string} and package filter {args.package_filter_string}"
108+
)
106109

107110
targeted_packages = discover_targeted_packages(
108111
args.glob_string,

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

+45-14
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ def create_setup_files(
239239
with open(cfg_location, "w") as f:
240240
f.write(SETUP_CFG)
241241

242+
242243
def tolerant_match(pkg_name, input_string):
243-
pattern = pkg_name.replace('-', '[-_]')
244+
pattern = pkg_name.replace("-", "[-_]")
244245
return fnmatch.fnmatch(input_string, f"*{pattern}*")
245246

247+
246248
def create_combined_sdist(
247249
conda_build: CondaConfiguration, config_assembly_folder: str, config_assembled_folder: str
248250
) -> str:
@@ -276,7 +278,8 @@ def create_combined_sdist(
276278
[
277279
os.path.join(config_assembled_folder, a)
278280
for a in os.listdir(config_assembled_folder)
279-
if os.path.isfile(os.path.join(config_assembled_folder, a)) and tolerant_match(conda_build.name, a)
281+
if os.path.isfile(os.path.join(config_assembled_folder, a))
282+
and tolerant_match(conda_build.name, a)
280283
]
281284
)
282285
)
@@ -526,15 +529,22 @@ def prep_and_create_environment(environment_dir: str) -> None:
526529

527530
subprocess.run(["conda", "env", "create", "--prefix", environment_dir], cwd=environment_dir, check=True)
528531
subprocess.run(
529-
["conda", "install", "--yes", "--quiet", "--prefix", environment_dir, "conda-build", "conda-verify", "typing-extensions", "conda-index"],
530-
cwd=environment_dir,
531-
check=True
532-
)
533-
subprocess.run(
534-
["conda", "run", "--prefix", environment_dir, "conda", "list"],
532+
[
533+
"conda",
534+
"install",
535+
"--yes",
536+
"--quiet",
537+
"--prefix",
538+
environment_dir,
539+
"conda-build",
540+
"conda-verify",
541+
"typing-extensions",
542+
"conda-index",
543+
],
535544
cwd=environment_dir,
536-
check=True
545+
check=True,
537546
)
547+
subprocess.run(["conda", "run", "--prefix", environment_dir, "conda", "list"], cwd=environment_dir, check=True)
538548

539549

540550
def copy_channel_files(coalescing_channel_dir: str, additional_channel_dir: str) -> None:
@@ -573,9 +583,17 @@ def build_conda_packages(
573583
if additional_channel_folders:
574584
for channel in additional_channel_folders:
575585
copy_channel_files(conda_output_dir, channel)
576-
subprocess.run(["conda", "run", "--prefix", conda_env_dir, "python", "-m", "conda_index", conda_output_dir], cwd=repo_root, check=True)
586+
subprocess.run(
587+
["conda", "run", "--prefix", conda_env_dir, "python", "-m", "conda_index", conda_output_dir],
588+
cwd=repo_root,
589+
check=True,
590+
)
577591
else:
578-
subprocess.run(["conda", "run", "--prefix", conda_env_dir, "python", "-m", "conda_index", conda_output_dir], cwd=repo_root, check=True)
592+
subprocess.run(
593+
["conda", "run", "--prefix", conda_env_dir, "python", "-m", "conda_index", conda_output_dir],
594+
cwd=repo_root,
595+
check=True,
596+
)
579597

580598
for conda_build in conda_configurations:
581599
conda_build_folder = os.path.join(conda_sdist_dir, conda_build.name).replace("\\", "/")
@@ -595,7 +613,18 @@ def invoke_conda_build(
595613
channels: List[str] = [],
596614
) -> None:
597615

598-
command = ["conda", "run", "--prefix", conda_env_dir, "conda-build", ".", "--output-folder", conda_output_dir, "-c", conda_output_dir]
616+
command = [
617+
"conda",
618+
"run",
619+
"--prefix",
620+
conda_env_dir,
621+
"conda-build",
622+
".",
623+
"--output-folder",
624+
conda_output_dir,
625+
"-c",
626+
conda_output_dir,
627+
]
599628
for channel in channels:
600629
command.extend(["-c", channel])
601630

@@ -641,8 +670,10 @@ def entrypoint():
641670

642671
args = parser.parse_args()
643672

644-
if (not args.config and not args.config_file):
645-
raise argparse.ArgumentError("config arg", "One of either -c (--config) or -f (--file) argument must be provided.")
673+
if not args.config and not args.config_file:
674+
raise argparse.ArgumentError(
675+
"config arg", "One of either -c (--config) or -f (--file) argument must be provided."
676+
)
646677

647678
if args.config_file:
648679
with open(args.config_file, "r") as f:

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

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
import textwrap
1313
from typing import List, Set, Dict, Tuple, Any
14+
1415
try:
1516
from collections import Sized
1617
except:

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
]
4343

4444
TEST_COMPATIBILITY_MAP = {}
45-
TEST_PYTHON_DISTRO_INCOMPATIBILITY_MAP = {
46-
"azure-storage-blob": "pypy",
47-
"azure-eventhub": "pypy"
48-
}
45+
TEST_PYTHON_DISTRO_INCOMPATIBILITY_MAP = {"azure-storage-blob": "pypy", "azure-eventhub": "pypy"}
4946

5047
omit_regression = (
5148
lambda x: "nspkg" not in x
@@ -196,11 +193,13 @@ def discover_targeted_packages(
196193

197194
# glob the starting package set
198195
collected_packages = glob_packages(glob_string, target_root_dir)
199-
logging.info(f"Results for glob_string \"{glob_string}\" and root directory \"{target_root_dir}\" are: {collected_packages}")
196+
logging.info(
197+
f'Results for glob_string "{glob_string}" and root directory "{target_root_dir}" are: {collected_packages}'
198+
)
200199

201200
# apply the additional contains filter
202201
collected_packages = [pkg for pkg in collected_packages if additional_contains_filter in pkg]
203-
logging.info(f"Results after additional contains filter: \"{additional_contains_filter}\" {collected_packages}")
202+
logging.info(f'Results after additional contains filter: "{additional_contains_filter}" {collected_packages}')
204203

205204
# filter for compatibility, this means excluding a package that doesn't support py36 when we are running a py36 executable
206205
if compatibility_filter:
@@ -406,9 +405,7 @@ def find_sdist(dist_dir: str, pkg_name: str, pkg_version: str) -> str:
406405
packages = [os.path.relpath(w, dist_dir) for w in packages]
407406

408407
if not packages:
409-
logging.error(
410-
f"No sdist is found in directory {dist_dir} with package name format {pkg_format}."
411-
)
408+
logging.error(f"No sdist is found in directory {dist_dir} with package name format {pkg_format}.")
412409
return
413410
return packages[0]
414411

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Pure git tools for managing local folder Git.
22
"""
3+
34
import logging
45

56
from git import Repo, GitCommandError

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Github tools.
22
"""
3+
34
from contextlib import contextmanager
45
import logging
56
import os

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
parse_require,
44
get_name_from_specifier,
55
ParsedSetup,
6-
parse_freeze_output,
76
read_setup_py_content,
87
get_build_config,
98
get_config_setting,
109
update_build_config,
11-
compare_string_to_glob_array
10+
compare_string_to_glob_array,
11+
get_ci_config,
1212
)
1313

1414
__all__ = [
1515
"parse_setup",
1616
"parse_require",
1717
"get_name_from_specifier",
1818
"ParsedSetup",
19-
"parse_freeze_output",
2019
"read_setup_py_content",
2120
"get_build_config",
2221
"get_config_setting",
2322
"update_build_config",
24-
"compare_string_to_glob_array"
23+
"compare_string_to_glob_array",
24+
"get_ci_config",
2525
]

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

+44-30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import textwrap
44
import re
55
import fnmatch
6+
import logging
67

78
try:
89
# py 311 adds this library natively
@@ -11,7 +12,7 @@
1112
# otherwise fall back to pypi package tomli
1213
import tomli as toml
1314

14-
from typing import Dict, List, Tuple, Any
15+
from typing import Dict, List, Tuple, Any, Optional
1516

1617
# Assumes the presence of setuptools
1718
from pkg_resources import (
@@ -102,7 +103,7 @@ def from_path(cls, parse_directory_or_file: str):
102103
ext_modules,
103104
)
104105

105-
def get_build_config(self) -> Dict[str, Any]:
106+
def get_build_config(self) -> Optional[Dict[str, Any]]:
106107
return get_build_config(self.folder)
107108

108109
def get_config_setting(self, setting: str, default: Any = True) -> Any:
@@ -162,7 +163,7 @@ def get_config_setting(package_path: str, setting: str, default: Any = True) ->
162163
return default
163164

164165

165-
def get_build_config(package_path: str) -> Dict[str, Any]:
166+
def get_build_config(package_path: str) -> Optional[Dict[str, Any]]:
166167
"""
167168
Attempts to retrieve all values within [tools.azure-sdk-build] section of a pyproject.toml.
168169
@@ -185,6 +186,29 @@ def get_build_config(package_path: str) -> Dict[str, Any]:
185186
return {}
186187

187188

189+
def get_ci_config(package_path: str) -> Optional[Dict[str, Any]]:
190+
"""
191+
Attempts to retrieve the parsed toml content of a CI.yml associated with this package.
192+
"""
193+
if os.path.isfile(package_path):
194+
package_path = os.path.dirname(package_path)
195+
196+
# this checks exactly one directory up
197+
# for sdk/core/azure-core
198+
# sdk/core/ci.yml is checked only
199+
ci_file = os.path.join(os.path.dirname(package_path), "ci.yml")
200+
201+
if os.path.exists(ci_file):
202+
import yaml
203+
try:
204+
with open(ci_file, "r") as f:
205+
return yaml.safe_load(f)
206+
except Exception as e:
207+
logging.error(f"Failed to load ci.yml at {ci_file} due to exception {e}")
208+
209+
return None
210+
211+
188212
def read_setup_py_content(setup_filename: str) -> str:
189213
"""
190214
Get setup.py content, returns a string.
@@ -193,10 +217,9 @@ def read_setup_py_content(setup_filename: str) -> str:
193217
content = setup_file.read()
194218
return content
195219

196-
197220
def parse_setup(
198221
setup_filename: str,
199-
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], str, List[Extension]]:
222+
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension]]:
200223
"""
201224
Used to evaluate a setup.py (or a directory containing a setup.py) and return a tuple containing:
202225
(
@@ -234,7 +257,7 @@ def setup(*args, **kwargs):
234257
not isinstance(node, ast.Expr)
235258
or not isinstance(node.value, ast.Call)
236259
or not hasattr(node.value.func, "id")
237-
or node.value.func.id != "setup"
260+
or node.value.func.id != "setup" # type: ignore
238261
):
239262
continue
240263
parsed.body[index:index] = parsed_mock_setup.body
@@ -279,22 +302,23 @@ def setup(*args, **kwargs):
279302
ext_package = kwargs.get("ext_package", None)
280303
ext_modules = kwargs.get("ext_modules", [])
281304

305+
# fmt: off
282306
return (
283-
name,
284-
version,
285-
python_requires,
286-
requires,
287-
is_new_sdk,
288-
setup_filename,
289-
name_space,
290-
package_data,
291-
include_package_data,
292-
classifiers,
293-
keywords,
294-
ext_package,
295-
ext_modules,
307+
name, # str
308+
version, # str
309+
python_requires, # str
310+
requires, # List[str]
311+
is_new_sdk, # bool
312+
setup_filename, # str
313+
name_space, # str,
314+
package_data, # Dict[str, Any],
315+
include_package_data, # bool,
316+
classifiers, # List[str],
317+
keywords, # List[str] ADJUSTED
318+
ext_package, # str
319+
ext_modules, # List[Extension]
296320
)
297-
321+
# fmt: on
298322

299323
def get_install_requires(setup_path: str) -> List[str]:
300324
"""
@@ -312,16 +336,6 @@ def parse_require(req: str) -> Requirement:
312336
return Requirement.parse(req)
313337

314338

315-
def parse_freeze_output(file_location: str) -> Dict[str, str]:
316-
"""
317-
Takes a python requirements file and returns a dictionary representing the contents.
318-
"""
319-
with open(file_location, "r") as f:
320-
reqs = f.read()
321-
322-
return dict((req.name, req) for req in parse_requirements(reqs))
323-
324-
325339
def get_name_from_specifier(version: str) -> str:
326340
"""
327341
Given a specifier string of format of <package-name><comparison><versionNumber>, returns the package name.

0 commit comments

Comments
 (0)