Skip to content

Commit bd29568

Browse files
authored
Fix installation issues occurring during new checks (#43086)
* fix an issue in create_package_and_install to properly pass --python <python executable> when running with `uv` * add debug `pip freeze` to `pylint` * swap run_pylint.yml back to the new implementation
1 parent 3afa84f commit bd29568

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
parameters:
22
ServiceDirectory: ''
33
TestMarkArgument: ''
4-
EnvVars: {}
54
AdditionalTestArgs: ''
65

76
# Please use `$(TargetingString)` to refer to the python packages glob string. This variable is set from resolve-package-targeting.yml.
@@ -11,14 +10,13 @@ steps:
1110
- task: PythonScript@0
1211
displayName: 'Run Pylint'
1312
inputs:
14-
scriptPath: 'scripts/devops_tasks/dispatch_tox.py'
13+
scriptPath: 'eng/scripts/dispatch_checks.py'
1514
arguments: >-
1615
"$(TargetingString)"
17-
--mark_arg="${{ parameters.TestMarkArgument }}"
1816
--service="${{ parameters.ServiceDirectory }}"
19-
--toxenv="pylint"
20-
--disablecov
17+
--checks="pylint"
2118
--filter-type="Omit_management"
2219
${{ parameters.AdditionalTestArgs }}
23-
env: ${{ parameters.EnvVars }}
20+
env:
21+
TOX_PIP_IMPL: "uv"
2422
condition: and(succeededOrFailed(), ne(variables['Skip.Pylint'],'true'))

eng/scripts/dispatch_checks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ def handler(signum, frame):
299299

300300
logger.info(f"Beginning discovery for {args.service} and root dir {root_dir}. Resolving to {target_dir}.")
301301

302+
# ensure that recursive virtual envs aren't messed with by this call
303+
os.environ.pop("VIRTUAL_ENV", None)
304+
os.environ.pop("PYTHON_HOME", None)
305+
302306
if args.filter_type == "None":
303307
args.filter_type = "Build"
304308
compatibility_filter = False

eng/tools/azure-sdk-tools/azpysdk/pylint.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import sys
44

55
from typing import Optional, List
6+
import subprocess
67
from subprocess import CalledProcessError, check_call
78

89
from .Check import Check
9-
from ci_tools.functions import install_into_venv
10+
from ci_tools.functions import install_into_venv, get_pip_command
1011
from ci_tools.scenario.generation import create_package_and_install
1112
from ci_tools.variables import discover_repo_root, in_ci, set_envvar_defaults
1213
from ci_tools.environment_exclusions import is_check_enabled
13-
from ci_tools.logging import logger
14+
from ci_tools.logging import logger, run_logged
1415

1516
REPO_ROOT = discover_repo_root()
1617
PYLINT_VERSION = "3.2.7"
@@ -48,6 +49,7 @@ def run(self, args: argparse.Namespace) -> int:
4849
package_name = parsed.name
4950
executable, staging_directory = self.get_executable(args.isolate, args.command, sys.executable, package_dir)
5051
logger.info(f"Processing {package_name} for pylint check")
52+
pip_cmd = get_pip_command(executable)
5153

5254
# install dependencies
5355
self.install_dev_reqs(executable, args, package_dir)
@@ -64,7 +66,7 @@ def run(self, args: argparse.Namespace) -> int:
6466
cache_dir=None,
6567
work_dir=staging_directory,
6668
force_create=False,
67-
package_type="wheel",
69+
package_type="sdist",
6870
pre_download_disabled=False,
6971
python_executable=executable,
7072
)
@@ -80,6 +82,19 @@ def run(self, args: argparse.Namespace) -> int:
8082
logger.error(f"Failed to install pylint: {e}")
8183
return e.returncode
8284

85+
# debug a pip freeze result
86+
cmd = pip_cmd + ["freeze"]
87+
freeze_result = subprocess.run(
88+
cmd,
89+
cwd=package_dir,
90+
check=False,
91+
text=True,
92+
stdout=subprocess.PIPE,
93+
stderr=subprocess.STDOUT
94+
)
95+
logger.debug(f"Running pip freeze with {cmd}")
96+
logger.debug(freeze_result.stdout)
97+
8398
top_level_module = parsed.namespace.split(".")[0]
8499

85100
if in_ci():
@@ -92,6 +107,15 @@ def run(self, args: argparse.Namespace) -> int:
92107
rcFileLocation = os.path.join(REPO_ROOT, "eng/pylintrc") if args.next else os.path.join(REPO_ROOT, "pylintrc")
93108

94109
try:
110+
logger.info([
111+
executable,
112+
"-m",
113+
"pylint",
114+
"--rcfile={}".format(rcFileLocation),
115+
"--output-format=parseable",
116+
os.path.join(package_dir, top_level_module),
117+
])
118+
95119
results.append(check_call(
96120
[
97121
executable,

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tarfile
66
import stat
77
from ast import Not
8+
from packaging import tags
89
from packaging.specifiers import SpecifierSet
910
from packaging.version import Version, parse, InvalidVersion
1011
from packaging.requirements import Requirement
@@ -612,24 +613,7 @@ def get_interpreter_compatible_tags() -> List[str]:
612613
This function invokes pip from the invoking interpreter and discovers which tags the interpreter is compatible with.
613614
"""
614615

615-
commands = [sys.executable, "-m", "pip", "debug", "--verbose"]
616-
617-
output = subprocess.run(
618-
commands,
619-
check=True,
620-
capture_output=True,
621-
).stdout.decode(encoding="utf-8")
622-
623-
tag_strings = output.split(os.linesep)
624-
625-
index = 0
626-
for index, value in enumerate(tag_strings):
627-
if "Compatible tags" in value:
628-
break
629-
630-
tags = tag_strings[index + 1 :]
631-
632-
return [tag.strip() for tag in tags if tag]
616+
return [str(t) for t in tags.sys_tags()]
633617

634618

635619
def check_whl_against_tags(whl_name: str, tags: List[str]) -> bool:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,13 @@ def create_package_and_install(
177177

178178
pip_cmd = get_pip_command(python_exe)
179179
commands = pip_cmd + ["install", built_pkg_path]
180+
180181
commands.extend(additional_downloaded_reqs)
181182
commands.extend(commands_options)
182183

184+
if pip_cmd[0] == "uv":
185+
commands += ["--python", python_exe]
186+
183187
if work_dir and os.path.exists(work_dir):
184188
logger.info("Executing command from {0}:{1}".format(work_dir, commands))
185189
subprocess.check_call(commands, cwd=work_dir)

0 commit comments

Comments
 (0)