Skip to content

Commit e9396e1

Browse files
authored
Check format on changes to azure-sdk-tools (#42912)
* code format eng/tools/azure-sdk-tools, add black enforcement to the package to prevent regression
1 parent bb1223e commit e9396e1

Some content is hidden

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

55 files changed

+493
-375
lines changed

.github/workflows/azure-sdk-tools.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ jobs:
3131
shell: bash
3232
working-directory: eng/tools/azure-sdk-tools
3333

34+
static-analysis:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
39+
- name: Set up Python 3.13
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: 3.13
43+
44+
- name: Install azure-sdk-tools
45+
run: |
46+
python -m pip install -e eng/tools/azure-sdk-tools[build,ghtools,conda]
47+
python -m pip install black==24.4.0
48+
python -m pip freeze
49+
shell: bash
50+
51+
- name: Run black
52+
run: |
53+
black --check --config eng/black-pyproject.toml eng/tools/azure-sdk-tools --exclude 'templates'
54+
shell: bash
55+
3456
dev-setup-and-import:
3557
runs-on: ubuntu-latest
3658
steps:

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,21 @@ def install_dev_reqs(self, executable: str, args: argparse.Namespace, package_di
120120
if os.path.exists(dev_requirements):
121121
requirements += ["-r", dev_requirements]
122122
else:
123-
logger.warning(f"No dev_requirements.txt found for {package_dir}, skipping installation of dev requirements.")
123+
logger.warning(
124+
f"No dev_requirements.txt found for {package_dir}, skipping installation of dev requirements."
125+
)
124126
return
125127

126128
temp_req_file = None
127129
if not getattr(args, "isolate", False):
128130
# don't install azure-sdk-tools when not isolated
129131
with open(dev_requirements, "r") as f:
130-
filtered_req_lines = [
131-
line.strip()
132-
for line in f
133-
if "eng/tools/azure-sdk-tools" not in line
134-
]
132+
filtered_req_lines = [line.strip() for line in f if "eng/tools/azure-sdk-tools" not in line]
135133
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_req_file:
136134
temp_req_file.write("\n".join(filtered_req_lines))
137135
if temp_req_file.name:
138136
requirements = ["-r", temp_req_file.name]
139-
try:
137+
try:
140138
logger.info(f"Installing dev requirements for {package_dir}")
141139
install_into_venv(executable, requirements, package_dir)
142140
except CalledProcessError as e:

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import tempfile
55

6-
from typing import Optional,List
6+
from typing import Optional, List
77
from subprocess import check_call
88

99
from .Check import Check
@@ -17,16 +17,20 @@
1717
excluded_packages = [
1818
"azure",
1919
"azure-mgmt",
20-
]
20+
]
21+
2122

2223
def should_run_import_all(package_name: str) -> bool:
2324
return not (package_name in excluded_packages or "nspkg" in package_name)
2425

26+
2527
class import_all(Check):
2628
def __init__(self) -> None:
2729
super().__init__()
2830

29-
def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None:
31+
def register(
32+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
33+
) -> None:
3034
"""Register the `import_all` check. The import_all check checks dependencies of a package
3135
by installing just the package + its dependencies, then attempts to import * from the base namespace.
3236
@@ -66,22 +70,14 @@ def run(self, args: argparse.Namespace) -> int:
6670
force_create=False,
6771
package_type="wheel",
6872
pre_download_disabled=False,
69-
python_executable=executable
73+
python_executable=executable,
7074
)
7175

7276
if should_run_import_all(parsed.name):
7377
# import all modules from current package
74-
logger.info(
75-
"Importing all modules from namespace [{0}] to verify dependency".format(
76-
parsed.namespace
77-
)
78-
)
78+
logger.info("Importing all modules from namespace [{0}] to verify dependency".format(parsed.namespace))
7979
import_script_all = "from {0} import *".format(parsed.namespace)
80-
commands = [
81-
executable,
82-
"-c",
83-
import_script_all
84-
]
80+
commands = [executable, "-c", import_script_all]
8581

8682
outcomes.append(check_call(commands))
8783
logger.info("Verified module dependency, no issues found")

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

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,38 @@
3131
__all__ = ["main", "build_parser"]
3232
__version__ = "0.0.0"
3333

34+
3435
def build_parser() -> argparse.ArgumentParser:
3536
"""Create and return the top-level ArgumentParser for the CLI."""
36-
parser = argparse.ArgumentParser(
37-
prog="azpysdk", description="Azure SDK Python tools (minimal CLI)"
38-
)
37+
parser = argparse.ArgumentParser(prog="azpysdk", description="Azure SDK Python tools (minimal CLI)")
3938
parser.add_argument("-V", "--version", action="version", version=__version__)
4039
# global flag: allow --isolate to appear before the subcommand as well
41-
parser.add_argument("--isolate", action="store_true", default=False,
42-
help="If set, run in an isolated virtual environment.")
40+
parser.add_argument(
41+
"--isolate", action="store_true", default=False, help="If set, run in an isolated virtual environment."
42+
)
4343

4444
# mutually exclusive logging options
4545
log_group = parser.add_mutually_exclusive_group()
4646
log_group.add_argument(
47-
"--quiet",
48-
action="store_true",
49-
default=False,
50-
help="Enable quiet mode (only shows ERROR logs)"
47+
"--quiet", action="store_true", default=False, help="Enable quiet mode (only shows ERROR logs)"
5148
)
5249
log_group.add_argument(
53-
"--verbose",
54-
action="store_true",
55-
default=False,
56-
help="Enable verbose mode (shows DEBUG logs)"
50+
"--verbose", action="store_true", default=False, help="Enable verbose mode (shows DEBUG logs)"
5751
)
5852
log_group.add_argument(
59-
"--log-level",
60-
choices=["DEBUG", "INFO", "WARN", "ERROR", "FATAL"],
61-
help="Set the logging level."
53+
"--log-level", choices=["DEBUG", "INFO", "WARN", "ERROR", "FATAL"], help="Set the logging level."
6254
)
6355

6456
common = argparse.ArgumentParser(add_help=False)
6557
common.add_argument(
6658
"target",
6759
nargs="?",
6860
default="**",
69-
help="Glob pattern for packages. Defaults to '**', but will match patterns below CWD if a value is provided."
61+
help="Glob pattern for packages. Defaults to '**', but will match patterns below CWD if a value is provided.",
7062
)
7163
# allow --isolate to be specified after the subcommand as well
7264
common.add_argument(
73-
"--isolate",
74-
action="store_true",
75-
default=False,
76-
help="If set, run in an isolated virtual environment."
65+
"--isolate", action="store_true", default=False, help="If set, run in an isolated virtual environment."
7766
)
7867

7968
subparsers = parser.add_subparsers(title="commands", dest="command")
@@ -92,9 +81,10 @@ def build_parser() -> argparse.ArgumentParser:
9281
next_pyright().register(subparsers, [common])
9382
ruff().register(subparsers, [common])
9483
verifytypes().register(subparsers, [common])
95-
84+
9685
return parser
9786

87+
9888
def main(argv: Optional[Sequence[str]] = None) -> int:
9989
"""CLI entrypoint.
10090
@@ -123,5 +113,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
123113
logger.error(f"Error: {exc}")
124114
return 2
125115

116+
126117
if __name__ == "__main__":
127118
raise SystemExit(main())

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
PYTHON_VERSION = "3.9"
1818
MYPY_VERSION = "1.14.1"
1919
ADDITIONAL_LOCKED_DEPENDENCIES = [
20-
"types-chardet==5.0.4.6",
21-
"types-requests==2.31.0.6",
22-
"types-six==1.16.21.9",
23-
"types-redis==4.6.0.7",
24-
"PyGitHub>=1.59.0"
20+
"types-chardet==5.0.4.6",
21+
"types-requests==2.31.0.6",
22+
"types-six==1.16.21.9",
23+
"types-redis==4.6.0.7",
24+
"PyGitHub>=1.59.0",
2525
]
2626

27+
2728
class mypy(Check):
2829
def __init__(self) -> None:
2930
super().__init__()

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
from .mypy import mypy
66

7+
78
class next_mypy(mypy):
89
def __init__(self):
910
super().__init__()
1011

11-
def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None:
12-
"""Register the next-mypy check. The next-mypy check installs the next version of mypy and runs mypy against the target package.
13-
"""
12+
def register(
13+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
14+
) -> None:
15+
"""Register the next-mypy check. The next-mypy check installs the next version of mypy and runs mypy against the target package."""
1416
parents = parent_parsers or []
1517
p = subparsers.add_parser("next-mypy", parents=parents, help="Run the mypy check with the next version of mypy")
1618
p.set_defaults(func=self.run)
@@ -19,4 +21,3 @@ def run(self, args: argparse.Namespace) -> int:
1921
"""Run the next-mypy check command."""
2022
args.next = True
2123
return super().run(args)
22-

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
from .pylint import pylint
66

7+
78
class next_pylint(pylint):
89
def __init__(self):
910
super().__init__()
1011

11-
def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None:
12-
"""Register the next-pylint check. The next-pylint check installs the next version of pylint and runs pylint against the target package.
13-
"""
12+
def register(
13+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
14+
) -> None:
15+
"""Register the next-pylint check. The next-pylint check installs the next version of pylint and runs pylint against the target package."""
1416
parents = parent_parsers or []
15-
p = subparsers.add_parser("next-pylint", parents=parents, help="Run the pylint check with the next version of pylint")
17+
p = subparsers.add_parser(
18+
"next-pylint", parents=parents, help="Run the pylint check with the next version of pylint"
19+
)
1620
p.set_defaults(func=self.run)
1721

1822
def run(self, args: argparse.Namespace) -> int:
1923
"""Run the next-pylint check command."""
2024
args.next = True
2125
return super().run(args)
22-

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
from .pyright import pyright
66

7+
78
class next_pyright(pyright):
89
def __init__(self):
910
super().__init__()
1011

11-
def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None:
12-
"""Register the next-pyright check. The next-pyright check installs the next version of pyright and runs pyright against the target package.
13-
"""
12+
def register(
13+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
14+
) -> None:
15+
"""Register the next-pyright check. The next-pyright check installs the next version of pyright and runs pyright against the target package."""
1416
parents = parent_parsers or []
15-
p = subparsers.add_parser("next-pyright", parents=parents, help="Run the pyright check with the next version of pyright")
17+
p = subparsers.add_parser(
18+
"next-pyright", parents=parents, help="Run the pyright check with the next version of pyright"
19+
)
1620
p.set_defaults(func=self.run)
1721

1822
def run(self, args: argparse.Namespace) -> int:
1923
"""Run the next-pyright check command."""
2024
args.next = True
2125
return super().run(args)
22-

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44

55
from .sphinx import sphinx
66

7+
78
class next_sphinx(sphinx):
89
def __init__(self):
910
super().__init__()
1011

11-
def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None:
12-
"""Register the next-sphinx check. The next-sphinx check installs the next version of sphinx and runs sphinx against the target package.
13-
"""
12+
def register(
13+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
14+
) -> None:
15+
"""Register the next-sphinx check. The next-sphinx check installs the next version of sphinx and runs sphinx against the target package."""
1416
parents = parent_parsers or []
15-
p = subparsers.add_parser("next-sphinx", parents=parents, help="Run the sphinx check with the next version of sphinx")
17+
p = subparsers.add_parser(
18+
"next-sphinx", parents=parents, help="Run the sphinx check with the next version of sphinx"
19+
)
1620
p.set_defaults(func=self.run)
1721

1822
p.add_argument("--inci", dest="in_ci", action="store_true", default=False)
1923

20-
2124
def run(self, args: argparse.Namespace) -> int:
2225
"""Run the next-sphinx check command."""
2326
args.next = True
2427
return super().run(args)
25-

0 commit comments

Comments
 (0)