Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/azure-sdk-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,60 @@ jobs:
black --check --config eng/black-pyproject.toml eng/tools/azure-sdk-tools --exclude 'templates'
shell: bash

verify-azpysdk-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.13
uses: actions/setup-python@v4
with:
python-version: 3.13

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
shell: bash

- name: Install azure-sdk-tools on in global uv, discover azpysdk checks
run: |
uv pip install --system eng/tools/azure-sdk-tools[build,ghtools,conda]

# Discover available azpysdk commands from the {command1,command2,...} line in help output
CHECKS=$(azpysdk -h 2>&1 | \
grep -oP '\{[^}]+\}' | \
tail -1 | \
tr -d '{}' | \
tr ',' '\n' | \
grep -v '^next-' | \
sort | \
paste -sd,)

if [ -z "$CHECKS" ]; then
echo "No azpysdk check modules discovered from azpysdk -h" >&2
exit 1
fi
echo "Discovered azpysdk checks: $CHECKS"
echo "AZPYSDK_CHECKS=$CHECKS" >> "$GITHUB_ENV"
shell: bash

- name: Run all discovered checks against azure-template using uv as package manager
run: |
python eng/scripts/dispatch_checks.py --checks "$AZPYSDK_CHECKS" azure-template
shell: bash
env:
TOX_PIP_IMPL: "uv"

- name: Install azure-sdk-tools on global pip env
run: |
python -m pip install -e eng/tools/azure-sdk-tools[build,ghtools,conda]
shell: bash

- name: Run all discovered checks against azure-template using pip as package manager
run: |
python eng/scripts/dispatch_checks.py --checks "$AZPYSDK_CHECKS" azure-template
shell: bash

dev-setup-and-import:
runs-on: ubuntu-latest
steps:
Expand Down
29 changes: 28 additions & 1 deletion eng/tools/azure-sdk-tools/azpysdk/Check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
import subprocess

from ci_tools.parsing import ParsedSetup
from ci_tools.functions import discover_targeted_packages, get_venv_call, install_into_venv, get_venv_python
from ci_tools.functions import (
discover_targeted_packages,
get_venv_call,
install_into_venv,
get_venv_python,
get_pip_command,
)
from ci_tools.variables import discover_repo_root
from ci_tools.logging import logger

Expand Down Expand Up @@ -180,3 +186,24 @@ def install_dev_reqs(self, executable: str, args: argparse.Namespace, package_di
os.remove(temp_req_file.name)
except Exception as cleanup_error:
logger.warning(f"Failed to remove temporary requirements file: {cleanup_error}")

def pip_freeze(self, executable: str) -> None:
"""Run pip freeze in the given virtual environment and log the output. This function handles both isolated and non-isolated
environments, as well as calling the proper `uv` executable with additional --python argument if needed."""
try:
# to uv pip install or freeze to a target environment, we have to add `--python <path to python exe>`
# to tell uv which environment to target
command = get_pip_command(executable)

if command[0] == "uv":
command += ["freeze", "--python", executable]
else:
command += ["freeze"]

result = subprocess.run(command, cwd=os.getcwd(), check=True, capture_output=True, text=True)
logger.info("Installed packages:")
logger.info(result.stdout)
except subprocess.CalledProcessError as e:
logger.error(f"Failed to run pip freeze: {e}")
logger.error(e.stdout)
logger.error(e.stderr)
8 changes: 1 addition & 7 deletions eng/tools/azure-sdk-tools/azpysdk/bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ def run(self, args: argparse.Namespace) -> int:
logger.error(f"Failed to install bandit: {e}")
return e.returncode

# debug a pip freeze result
cmd = get_pip_command(executable) + ["freeze"]
freeze_result = subprocess.run(
cmd, cwd=package_dir, check=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
logger.debug(f"Running pip freeze with {cmd}")
logger.debug(freeze_result.stdout)
self.pip_freeze(executable)

if in_ci():
if not is_check_enabled(package_dir, "bandit"):
Expand Down
3 changes: 0 additions & 3 deletions eng/tools/azure-sdk-tools/azpysdk/import_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def run(self, args: argparse.Namespace) -> int:

targeted = self.get_targeted_directories(args)

# {[tox]pip_command} freeze
# python {repository_root}/eng/tox/import_all.py -t {tox_root}

outcomes: List[int] = []

for parsed in targeted:
Expand Down
4 changes: 1 addition & 3 deletions eng/tools/azure-sdk-tools/azpysdk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
from typing import Sequence, Optional

from .whl import whl
from .import_all import import_all
from .mypy import mypy
from .next_mypy import next_mypy
Expand All @@ -25,8 +24,8 @@
from .next_pyright import next_pyright
from .ruff import ruff
from .verifytypes import verifytypes
from .verify_whl import verify_whl
from .verify_sdist import verify_sdist
from .verify_whl import verify_whl
from .bandit import bandit
from .verify_keywords import verify_keywords

Expand Down Expand Up @@ -72,7 +71,6 @@ def build_parser() -> argparse.ArgumentParser:
subparsers = parser.add_subparsers(title="commands", dest="command")

# register our checks with the common params as their parent
whl().register(subparsers, [common])
import_all().register(subparsers, [common])
mypy().register(subparsers, [common])
next_mypy().register(subparsers, [common])
Expand Down
9 changes: 1 addition & 8 deletions eng/tools/azure-sdk-tools/azpysdk/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def run(self, args: argparse.Namespace) -> int:
package_name = parsed.name
executable, staging_directory = self.get_executable(args.isolate, args.command, sys.executable, package_dir)
logger.info(f"Processing {package_name} for pylint check")
pip_cmd = get_pip_command(executable)

# install dependencies
self.install_dev_reqs(executable, args, package_dir)
Expand Down Expand Up @@ -91,13 +90,7 @@ def run(self, args: argparse.Namespace) -> int:
logger.error(f"Failed to install pylint: {e}")
return e.returncode

# debug a pip freeze result
cmd = pip_cmd + ["freeze"]
freeze_result = subprocess.run(
cmd, cwd=package_dir, check=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
logger.debug(f"Running pip freeze with {cmd}")
logger.debug(freeze_result.stdout)
self.pip_freeze(executable)

top_level_module = parsed.namespace.split(".")[0]

Expand Down
Loading