Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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/
2 changes: 1 addition & 1 deletion eng/tox/create_package_and_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def discover_packages(setuppy_path, args):

def discover_prebuilt_package(dist_directory, setuppy_path, package_type):
packages = []
pkg_name, _, version = get_package_details(setuppy_path)
pkg_name, _, version, _ = get_package_details(setuppy_path)
if package_type == "wheel":
prebuilt_package = find_whl(dist_directory, pkg_name, version)
else:
Expand Down
2 changes: 1 addition & 1 deletion eng/tox/import_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def should_run_import_all(package_name):

# get target package name from target package path
pkg_dir = os.path.abspath(args.target_package)
package_name, namespace, _ = get_package_details(os.path.join(pkg_dir, 'setup.py'))
package_name, namespace, _, _ = get_package_details(os.path.join(pkg_dir, 'setup.py'))

if should_run_import_all(package_name):
# import all modules from current package
Expand Down
2 changes: 1 addition & 1 deletion eng/tox/prep_sphinx_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def write_version(site_folder, version):
args = parser.parse_args()

package_path = os.path.abspath(args.target_package)
package_name, namespace, package_version = get_package_details(
package_name, namespace, package_version, _ = get_package_details(
os.path.join(package_path, "setup.py")
)

Expand Down
2 changes: 1 addition & 1 deletion eng/tox/run_apistubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def get_package_wheel_path(pkg_root):
# parse setup.py to get package name and version
pkg_name, _, version = get_package_details(os.path.join(pkg_root, "setup.py"))
pkg_name, _, version, _ = get_package_details(os.path.join(pkg_root, "setup.py"))
# Check if wheel is already built and available for current package
prebuilt_dir = os.getenv("PREBUILT_WHEEL_DIR")
if prebuilt_dir:
Expand Down
2 changes: 1 addition & 1 deletion eng/tox/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


pkg_dir = os.path.abspath(args.target_package)
package_name, namespace, ver = get_package_details(os.path.join(pkg_dir, "setup.py"))
package_name, namespace, ver, _ = get_package_details(os.path.join(pkg_dir, "setup.py"))

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

Expand Down
2 changes: 1 addition & 1 deletion eng/tox/run_sphinx_apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def mgmt_apidoc(working_directory, namespace):
package_dir = os.path.abspath(args.package_root)
output_directory = os.path.join(target_dir, "unzipped/docgen")

pkg_name, namespace, pkg_version = get_package_details(os.path.join(package_dir, 'setup.py'))
pkg_name, namespace, pkg_version, _ = get_package_details(os.path.join(package_dir, 'setup.py'))

if should_build_docs(pkg_name):
if is_mgmt_package(pkg_name):
Expand Down
2 changes: 1 addition & 1 deletion eng/tox/run_sphinx_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def sphinx_build(target_dir, output_dir):
target_dir = os.path.abspath(args.working_directory)
package_dir = os.path.abspath(args.package_root)

package_name, _, pkg_version = get_package_details(os.path.join(package_dir, 'setup.py'))
package_name, _, pkg_version, _ = get_package_details(os.path.join(package_dir, 'setup.py'))

if should_build_docs(package_name):
sphinx_build(target_dir, output_dir)
Expand Down
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
2 changes: 1 addition & 1 deletion eng/tox/verify_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def verify_sdist(package_dir, dist_dir, version):

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

if should_verify_package(pkg_name):
logging.info("Verifying sdist for package [%s]", pkg_name)
Expand Down
52 changes: 35 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,35 @@ 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]
top_level_module = namespace.split(".")[0]
wheel_location = get_wheel(args.dist_dir, ver)

if not os.getenv("IGNORE_WHEEL_PYVERSION_CHECK"):
error_details_string = "For more information, visit https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/packaging.md."

if not python_requires:
logging.info("Your package must define a setup argument for 'python_requires'. {}".format(error_details_string))
exit(1)
else:
if not parse_version(trim_spec(python_requires)) >= parse_version("3.6"):
logging.info(
"The python_requires value of '{}' should instead be at least '>=3.0'. {}".format(python_requires, error_details_string)
)
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 or remove the `setup.cfg` entirely. {}".format(
pkg_name, python_requires, error_details_string
)
)
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)