Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion eng/pipelines/templates/variables/globals.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variables:
PythonVersion: '3.6'
PythonVersion: '3.9'
skipComponentGovernanceDetection: true
AzureSDKCondaChannel: https://azuresdkconda.blob.core.windows.net/channel1/
30 changes: 29 additions & 1 deletion eng/tox/tox_helper_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def setup(*args, **kwargs):
name_space = packages[0]
logging.info("Namespaces found for package {0}: {1}".format(package_name, packages))

return package_name, name_space, kwargs["version"]
try:
python_requires = kwargs["python_requires"]
# most do not define this, fall back to what we define as universal
except KeyError as e:
python_requires = None

return package_name, name_space, kwargs["version"], python_requires


def parse_req(req):
Expand Down Expand Up @@ -148,6 +154,28 @@ def find_sdist(dist_dir, pkg_name, pkg_version):
return packages[0]


def trim_spec(incoming_spec):
"""
Parses a valid specification. returns the version part of the text.
EG: ">=2.1.1" -> "2.1.1"
"==3.0.0" -> "3.0.0"
"1.0.0" -> "1.0.0"
"""
idx = 0
excluded_chars = ['<', '>', '=', '~', '!']


for char in incoming_spec:
# reserved chars pulled form https://www.python.org/dev/peps/pep-0508/#grammar
if char not in excluded_chars:
break
else:
idx += 1

return incoming_spec[idx:len(excluded_chars)]



def find_whl(whl_dir, pkg_name, pkg_version):
# This function will find a whl for given package name
if not os.path.exists(whl_dir):
Expand Down
50 changes: 33 additions & 17 deletions eng/tox/verify_whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
unzip_sdist_to_directory,
move_and_rename,
unzip_file_to_directory,
trim_spec,
)

from pkg_resources import parse_version

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

# Excluding auto generated applicationinsights and loganalytics
Expand All @@ -30,9 +33,13 @@
]


def get_wheel(dist_dir, version):
return glob.glob(os.path.join(dist_dir, "*{}*.whl".format(version)))[0]


def extract_whl(dist_dir, version):
# Find whl for the package
path_to_whl = glob.glob(os.path.join(dist_dir, "*{}*.whl".format(version)))[0]
path_to_whl = get_wheel(dist_dir, version)

# Cleanup any existing stale files if any and rename whl file to tar.gz
zip_file = path_to_whl.replace(".whl", ".tar.gz")
Expand All @@ -52,9 +59,7 @@ def verify_whl_root_directory(dist_dir, expected_top_level_module, version):
root_folders = os.listdir(extract_location)

# check for non 'azure' folder as root folder
non_azure_folders = [
d for d in root_folders if d != expected_top_level_module and not d.endswith(".dist-info")
]
non_azure_folders = [d for d in root_folders if d != expected_top_level_module and not d.endswith(".dist-info")]
if non_azure_folders:
logging.error(
"whl has following incorrect directory at root level [%s]",
Expand All @@ -75,17 +80,11 @@ def cleanup(path):


def should_verify_package(package_name):
return (
package_name not in EXCLUDED_PACKAGES
and "nspkg" not in package_name
and "-mgmt" not in package_name
)
return package_name not in EXCLUDED_PACKAGES and "nspkg" not in package_name and "-mgmt" not in package_name


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Verify directories included in whl and contents in manifest file"
)
parser = argparse.ArgumentParser(description="Verify directories included in whl and contents in manifest file")

parser.add_argument(
"-t",
Expand All @@ -107,16 +106,33 @@ def should_verify_package(package_name):

# get target package name from target package path
pkg_dir = os.path.abspath(args.target_package)
pkg_name, namespace, ver = get_package_details(os.path.join(pkg_dir, "setup.py"))
pkg_name, namespace, ver, python_requires = get_package_details(os.path.join(pkg_dir, "setup.py"))

top_level_module = namespace.split(".")[0]
wheel_location = get_wheel(args.dist_dir, ver)

top_level_module = namespace.split('.')[0]
if not os.getenv("IGNORE_WHEEL_PYVERSION_CHECK"):
if not python_requires:
logging.info("Your package must define a setup argument for 'python_requires'.")
Comment thread
scbedd marked this conversation as resolved.
Outdated
exit(1)
else:
if not parse_version(trim_spec(python_requires)) >= parse_version("3.0"):
logging.info(
"The python_requires value of '{}' should instead be at least '>=3.0'.".format(python_requires)
Comment thread
scbedd marked this conversation as resolved.
Outdated
)
exit(1)
if "py2" in wheel_location:
logging.info(
"The package {} is marked with 'python_requires{}', but a universal package was generated. Check your setup.cfg and ensure that 'universal=1' configuration is not present.".format(
Comment thread
scbedd marked this conversation as resolved.
Outdated
pkg_name, python_requires
)
)
exit(1)

if should_verify_package(pkg_name):
logging.info("Verifying root directory in whl for package: [%s]", pkg_name)
if verify_whl_root_directory(args.dist_dir, top_level_module, ver):
logging.info("Verified root directory in whl for package: [%s]", pkg_name)
else:
logging.info(
"Failed to verify root directory in whl for package: [%s]", pkg_name
)
logging.info("Failed to verify root directory in whl for package: [%s]", pkg_name)
exit(1)