Skip to content

Commit 4839685

Browse files
authored
Add Verify Keywords Check Without Tox (#43335)
* initial * update * update * docs * black and refactor
1 parent c87d16a commit 4839685

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

doc/tool_usage_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This repo is currently migrating all checks from a slower `tox`-based framework,
2424
|`ruff`| Runs `ruff` checks. | `azpysdk ruff .` |
2525
|`verifywhl`| Verifies that the root directory in whl is azure, and verifies manifest so that all directories in source are included in sdist. | `azpysdk verifywhl .` |
2626
|`verifysdist`| Verify directories included in sdist and contents in manifest file. Also ensures that py.typed configuration is correct within the setup.py. | `azpysdk verifysdist .` |
27+
|`verify_keywords`| Verify that the keyword 'azure sdk' is present in the targeted package's keywords. | `azpysdk verify_keywords .` |
2728
|`import_all`| Installs the package w/ default dependencies, then attempts to `import *` from the base namespace. Ensures that all imports will resolve after a base install and import. | `azpysdk import_all .` |
2829

2930
## Common arguments

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .verifytypes import verifytypes
2828
from .verify_whl import verify_whl
2929
from .verify_sdist import verify_sdist
30+
from .verify_keywords import verify_keywords
3031

3132
from ci_tools.logging import configure_logging, logger
3233

@@ -85,6 +86,7 @@ def build_parser() -> argparse.ArgumentParser:
8586
verifytypes().register(subparsers, [common])
8687
verify_sdist().register(subparsers, [common])
8788
verify_whl().register(subparsers, [common])
89+
verify_keywords().register(subparsers, [common])
8890

8991
return parser
9092

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
3+
from typing import Optional, List
4+
5+
from ci_tools.variables import in_ci, set_envvar_defaults
6+
from ci_tools.environment_exclusions import is_check_enabled
7+
from ci_tools.logging import logger
8+
9+
from .Check import Check
10+
11+
KEYWORD = "azure sdk"
12+
13+
14+
class verify_keywords(Check):
15+
def __init__(self) -> None:
16+
super().__init__()
17+
18+
def register(
19+
self,
20+
subparsers: "argparse._SubParsersAction",
21+
parent_parsers: Optional[List[argparse.ArgumentParser]] = None,
22+
) -> None:
23+
"""Register the `verify_keywords` check. The verify_keywords check checks the keywords of a targeted python package. If the keyword 'azure sdk' is not present, error."""
24+
parents = parent_parsers or []
25+
p = subparsers.add_parser(
26+
"verify_keywords",
27+
parents=parents,
28+
help="Run the keyword verification check",
29+
)
30+
p.set_defaults(func=self.run)
31+
32+
def run(self, args: argparse.Namespace) -> int:
33+
"""Run the verify_keywords check command."""
34+
logger.info("Running verify_keywords check...")
35+
36+
set_envvar_defaults()
37+
38+
targeted = self.get_targeted_directories(args)
39+
40+
results: List[int] = []
41+
42+
for parsed in targeted:
43+
package_name = parsed.name
44+
45+
if in_ci():
46+
if not is_check_enabled(args.target, "verify_keywords"):
47+
logger.info(f"Package {package_name} opts-out of keyword verification check.")
48+
continue
49+
50+
if KEYWORD not in parsed.keywords:
51+
logger.error(
52+
f"Keyword '{KEYWORD}' not present in keywords for {package_name}. Before attempting publishing, ensure that package {package_name} has keyword '{KEYWORD}' present in the keyword array."
53+
)
54+
results.append(1)
55+
else:
56+
logger.info(f"Package {package_name} has keyword '{KEYWORD}' present in the keyword array.")
57+
58+
return max(results) if results else 0

0 commit comments

Comments
 (0)