Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local tox checks do not skip #28612

Merged
merged 19 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
update to only apply the is_ignored_check when we are in CI
  • Loading branch information
scbedd committed Feb 2, 2023
commit ed0bb58e1915d04fc1b59a4cd917446f89e6f180
13 changes: 12 additions & 1 deletion eng/tox/run_bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import logging
import sys

from ci_tools.environment_exclusions import (
is_check_enabled
)
from ci_tools.variables import in_ci

logging.getLogger().setLevel(logging.INFO)

Expand All @@ -29,8 +33,15 @@
)

args = parser.parse_args()

package_name = os.path.basename(os.path.abspath(args.target_package))

if in_ci():
if not is_check_enabled(args.target_package, "bandit"):
logging.info(
f"Package {package_name} opts-out of bandit check."
)
exit(0)

try:
check_call(
[
Expand Down
48 changes: 25 additions & 23 deletions eng/tox/run_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import sys

from ci_tools.environment_exclusions import (
is_ignored_package,
is_check_enabled
is_check_enabled, is_typing_ignored
)
from ci_tools.variables import in_ci

logging.getLogger().setLevel(logging.INFO)

Expand All @@ -35,11 +35,12 @@

args = parser.parse_args()
package_name = os.path.basename(os.path.abspath(args.target_package))
if not is_check_enabled(args.target_package, "mypy", True) or is_ignored_package(package_name):
logging.info(
f"Package {package_name} opts-out of mypy check. See https://aka.ms/python/typing-guide for information."
)
exit(0)
if in_ci():
if not is_check_enabled(args.target_package, "mypy", True) or is_typing_ignored(package_name):
logging.info(
f"Package {package_name} opts-out of mypy check. See https://aka.ms/python/typing-guide for information."
)
exit(0)

commands = [
sys.executable,
Expand All @@ -61,24 +62,25 @@
except CalledProcessError as src_err:
src_code_error = src_err

if not is_check_enabled(args.target_package, "type_check_samples", True):
logging.info(
f"Package {package_name} opts-out of mypy check on samples."
)
else:
sample_code = [
*commands,
"--check-untyped-defs",
"--follow-imports=silent",
os.path.join(args.target_package, "samples")
]
try:
if in_ci():
if not is_check_enabled(args.target_package, "type_check_samples", True):
logging.info(
f"Running mypy commands on sample code: {sample_code}"
f"Package {package_name} opts-out of mypy check on samples."
)
check_call(sample_code)
except CalledProcessError as sample_err:
sample_code_error = sample_err
else:
scbedd marked this conversation as resolved.
Show resolved Hide resolved
sample_code = [
*commands,
"--check-untyped-defs",
"--follow-imports=silent",
os.path.join(args.target_package, "samples")
]
try:
logging.info(
f"Running mypy commands on sample code: {sample_code}"
)
check_call(sample_code)
except CalledProcessError as sample_err:
sample_code_error = sample_err

print("See https://aka.ms/python/typing-guide for information.\n\n")
if src_code_error and sample_code_error:
Expand Down
40 changes: 23 additions & 17 deletions eng/tox/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ci_tools.environment_exclusions import is_check_enabled
from ci_tools.parsing import ParsedSetup
from ci_tools.variables import in_ci

logging.getLogger().setLevel(logging.INFO)

Expand All @@ -40,23 +41,28 @@

pkg_dir = os.path.abspath(args.target_package)
pkg_details = ParsedSetup.from_path(pkg_dir)

top_level_module = pkg_details.namespace.split('.')[0]

if is_check_enabled(args.target_package, "pylint"):
try:
check_call(
[
sys.executable,
"-m",
"pylint",
"--rcfile={}".format(rcFileLocation),
"--output-format=parseable",
os.path.join(args.target_package, top_level_module),
]
)
except CalledProcessError as e:
logging.error(
"{} exited with linting error {}".format(pkg_details.name, e.returncode)
if in_ci():
if not is_check_enabled(args.target_package, "pylint"):
logging.info(
f"Package {pkg_details.name} opts-out of pylint check."
)
exit(1)
exit(0)

try:
check_call(
[
sys.executable,
"-m",
"pylint",
"--rcfile={}".format(rcFileLocation),
"--output-format=parseable",
os.path.join(args.target_package, top_level_module),
]
)
except CalledProcessError as e:
logging.error(
"{} exited with linting error {}".format(pkg_details.name, e.returncode)
)
exit(1)
28 changes: 16 additions & 12 deletions eng/tox/run_pyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import sys

from ci_tools.environment_exclusions import (
is_ignored_package,
is_check_enabled,
is_check_enabled, is_typing_ignored
)
from ci_tools.variables import in_ci

logging.getLogger().setLevel(logging.INFO)

Expand All @@ -35,21 +35,25 @@

args = parser.parse_args()
package_name = os.path.basename(os.path.abspath(args.target_package))
if not is_check_enabled(args.target_package, "pyright") or is_ignored_package(package_name):
logging.info(
f"Package {package_name} opts-out of pyright check. See https://aka.ms/python/typing-guide for information."
)
exit(0)

if in_ci():
if not is_check_enabled(args.target_package, "pyright") or is_typing_ignored(package_name):
logging.info(
f"Package {package_name} opts-out of pyright check. See https://aka.ms/python/typing-guide for information."
)
exit(0)

paths = [
os.path.join(args.target_package, "azure"),
os.path.join(args.target_package, "samples"),
]
if not is_check_enabled(args.target_package, "type_check_samples"):
logging.info(
f"Package {package_name} opts-out of pyright check on samples."
)
paths = paths[:-1]

if in_ci():
if not is_check_enabled(args.target_package, "type_check_samples"):
logging.info(
f"Package {package_name} opts-out of pyright check on samples."
)
paths = paths[:-1]

commands = [
sys.executable,
Expand Down
14 changes: 8 additions & 6 deletions eng/tox/run_verifytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import logging
import sys

from ci_tools.environment_exclusions import is_ignored_package, is_check_enabled
from ci_tools.environment_exclusions import is_check_enabled, is_typing_ignored
from ci_tools.variables import in_ci

logging.getLogger().setLevel(logging.INFO)

Expand Down Expand Up @@ -93,11 +94,12 @@ def get_type_complete_score(commands, check_pytyped=False):
module = package_name.replace("-", ".")
setup_path = os.path.abspath(args.target_package)

if not is_check_enabled(args.target_package, "verifytypes") or is_ignored_package(package_name):
logging.info(
f"{package_name} opts-out of verifytypes check. See https://aka.ms/python/typing-guide for information."
)
exit(0)
if in_ci():
if not is_check_enabled(args.target_package, "verifytypes") or is_typing_ignored(package_name):
logging.info(
f"{package_name} opts-out of verifytypes check. See https://aka.ms/python/typing-guide for information."
)
exit(0)

commands = [
sys.executable,
Expand Down
1 change: 1 addition & 0 deletions scripts/devops_tasks/tox_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def prep_and_run_tox(targeted_packages: List[str], parsed_args: Namespace, optio
f"All requested tox environments for package {package_name} have been excluded by the environment exclusion list."
+ " Check file /tools/azure-sdk-tools/ci_tools/environment_exclusions.py and the pyproject.toml."
)

continue

tox_execution_array.extend(["-e", filtered_tox_environment_set])
Expand Down
2 changes: 2 additions & 0 deletions sdk/template/azure-template/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.azure-sdk-build]
verifytypes = false
18 changes: 16 additions & 2 deletions tools/azure-sdk-tools/ci_tools/environment_exclusions.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@

# --------------------------------------------------------------------------------------------------------------------
# DO NOT add packages to the below lists. They are used to omit packages that will never run type checking.
#
# For CI exclusion of type checks, look into adding a pyproject.toml, as indicated in the `The pyproject.toml` section
# of `.doc/eng_sys_checks.md`.

IGNORE_FILTER = ["nspkg", "mgmt", "cognitiveservices"]
FILTER_EXCLUSIONS = ["azure-mgmt-core"]
IGNORE_PACKAGES = [
Expand All @@ -344,7 +348,17 @@
]




def is_check_enabled(package_path: str, check: str, default: bool = True) -> bool:
"""
Single-use function to evaluate whether or not a given check should run against a package.

In order:
- Checks <CHECK>_OPT_OUT for package name.
- Honors override variable if one is present: <PACKAGE-NAME>_<CHECK>.
- Finally falls back to the pyproject.toml at package root (if one exists) for a tools setting enabling/disabling <check>.
scbedd marked this conversation as resolved.
Show resolved Hide resolved
"""
if package_path.endswith("setup.py"):
package_path = os.path.dirname(package_path)

Expand Down Expand Up @@ -395,9 +409,9 @@ def filter_tox_environment_string(namespace_argument: str, package_path: str) ->
return namespace_argument


def is_ignored_package(package_name: str) -> bool:
def is_typing_ignored(package_name: str) -> bool:
"""
Evaluates a package name and evaluates whether or not tox environments should run against it.
Evaluates a package name and evaluates whether or not typing should generally run against it.
"""
if package_name in IGNORE_PACKAGES:
return True
Expand Down
26 changes: 14 additions & 12 deletions tools/azure-sdk-tools/ci_tools/functions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from ast import Not
from packaging.specifiers import SpecifierSet
from packaging.version import Version, parse
from pkg_resources import Requirement

from ci_tools.variables import discover_repo_root, get_artifact_directory, DEV_BUILD_IDENTIFIER
import os, sys, platform, glob, re

from ci_tools.variables import discover_repo_root, DEV_BUILD_IDENTIFIER
from ci_tools.parsing import ParsedSetup, get_build_config
from pypi_tools.pypi import PyPIClient


import os, sys, platform, glob, re, logging
from typing import List, Any
import logging

INACTIVE_CLASSIFIER = "Development Status :: 7 - Inactive"

Expand Down Expand Up @@ -75,7 +71,7 @@ def apply_compatibility_filter(package_set: List[str]) -> List[str]:

for pkg in package_set:
try:
spec_set = SpecifierSet(ParsedSetup.from_path(pkg).python_requires)
spec_set = SpecifierSet(ParsedSetup.from_path(pkg).python_requires)
except RuntimeError as e:
logging.error(f"Unable to parse metadata for package {pkg}, omitting from build.")
continue
Expand All @@ -89,7 +85,9 @@ def apply_compatibility_filter(package_set: List[str]) -> List[str]:
collected_packages.append(pkg)

logging.debug("Target packages after applying compatibility filter: {}".format(collected_packages))
logging.debug("Package(s) omitted by compatibility filter: {}".format(generate_difference(package_set, collected_packages)))
logging.debug(
"Package(s) omitted by compatibility filter: {}".format(generate_difference(package_set, collected_packages))
)

return collected_packages

Expand All @@ -114,9 +112,11 @@ def str_to_bool(input_string: str) -> bool:
else:
return False


def generate_difference(original_packages: List[str], filtered_packages: List[str]):
return list(set(original_packages) - set(filtered_packages))


def glob_packages(glob_string: str, target_root_dir: str) -> List[str]:
if glob_string:
individual_globs = glob_string.split(",")
Expand All @@ -138,8 +138,10 @@ def apply_business_filter(collected_packages: List[str], filter_type: str) -> Li
pkg_set_ci_filtered = list(filter(omit_function_dict.get(filter_type, omit_build), collected_packages))

logging.debug("Target packages after applying business filter: {}".format(pkg_set_ci_filtered))
logging.debug("Package(s) omitted by business filter: {}".format(generate_difference(collected_packages, pkg_set_ci_filtered)))

logging.debug(
"Package(s) omitted by business filter: {}".format(generate_difference(collected_packages, pkg_set_ci_filtered))
)

return pkg_set_ci_filtered


Expand All @@ -149,7 +151,7 @@ def discover_targeted_packages(
additional_contains_filter: str = "",
filter_type: str = "Build",
compatibility_filter: bool = True,
include_inactive: bool = False
include_inactive: bool = False,
) -> List[str]:
"""
During build and test, the set of targeted packages may expand or contract depending on the needs of the invocation.
Expand Down Expand Up @@ -188,7 +190,7 @@ def get_config_setting(package_path: str, setting: str, default: Any = True) ->
override_value = os.getenv(f"{os.path.basename(package_path).upper()}_{setting.upper()}", None)
if override_value:
return override_value

# if no override, check for the config setting in the pyproject.toml
config = get_build_config(package_path)

Expand Down