Skip to content

Commit

Permalink
Verify command packages have the wheel extension applied (#3230)
Browse files Browse the repository at this point in the history
* Verify wheels

* Use os.path.join
  • Loading branch information
derekbekoe authored May 8, 2017
1 parent 3e18e4a commit d82c616
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/automation/tests/verify_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@
import pip
import imp
import fileinput
import glob
import zipfile

import automation.utilities.path as automation_path
from automation.utilities.display import print_heading
from automation.utilities.const import COMMAND_MODULE_PREFIX

VALID_WHEEL_HELP = """
A valid command module .whl for the CLI should:
- Not contain any __init__.py files in directories above azure.cli.command_modules.
Does the package have a azure_bdist_wheel.py file?
Does the package have a setup.cfg file?
Does setup.py include 'cmdclass=cmdclass'?
"""


def exec_command(command, cwd=None, stdout=None, env=None):
"""Returns True in the command was executed successfully"""
Expand Down Expand Up @@ -64,6 +75,17 @@ def install_package(path_to_package, package_name, dist_dir):
print_heading('Installed {}'.format(path_to_package))


def _valid_wheel(wheel_path):
# these files shouldn't exist in the wheel
print('Verifying {}'.format(wheel_path))
bad_files = ['azure/__init__.py', 'azure/cli/__init__.py', 'azure/cli/command_modules/__init__.py']
wheel_zip=zipfile.ZipFile(wheel_path)
whl_file_list = wheel_zip.namelist()
if any(f in whl_file_list for f in bad_files):
return False
return True


def verify_packages():
# tmp dir to store all the built packages
built_packages_dir = tempfile.mkdtemp()
Expand Down Expand Up @@ -112,6 +134,20 @@ def verify_packages():
print(missing_modules, file=sys.stderr)
sys.exit(1)

# STEP 4:: Verify the wheels that get produced
print_heading('Verifying wheels...')
invalid_wheels = []
for wheel_path in glob.glob(os.path.join(built_packages_dir, '*.whl')):
# Verify all non-nspkg wheels
if 'nspkg' not in wheel_path and not _valid_wheel(wheel_path):
invalid_wheels.append(wheel_path)
if invalid_wheels:
print_heading('Error: The following wheels are invalid', f=sys.stderr)
print(invalid_wheels, file=sys.stderr)
print(VALID_WHEEL_HELP, file=sys.stderr)
sys.exit(1)
print_heading('Verified wheels successfully.')

print_heading('OK')


Expand Down

0 comments on commit d82c616

Please sign in to comment.