Example #1
0
 def test_metadata(self):
     self.maxDiff = None
     extensions_dir = tempfile.mkdtemp()
     for ext_name, exts in self.index['extensions'].items():
         for item in exts:
             ext_dir = tempfile.mkdtemp(dir=extensions_dir)
             ext_file = get_whl_from_url(item['downloadUrl'], item['filename'],
                                         self.whl_cache_dir, self.whl_cache)
             metadata = get_ext_metadata(ext_dir, ext_file, ext_name)
             # Due to https://github.com/pypa/wheel/issues/195 we prevent whls built with 0.31.0 or greater.
             # 0.29.0, 0.30.0 are the two previous versions before that release.
             supported_generators = ['bdist_wheel (0.29.0)', 'bdist_wheel (0.30.0)']
             self.assertIn(metadata.get('generator'), supported_generators,
                           "{}: 'generator' should be one of {}. "
                           "Build the extension with a different version of the 'wheel' package "
                           "(e.g. `pip install wheel==0.30.0`). "
                           "This is due to https://github.com/pypa/wheel/issues/195".format(ext_name,
                                                                                            supported_generators))
             self.assertDictEqual(metadata, item['metadata'],
                                  "Metadata for {} in index doesn't match the expected of: \n"
                                  "{}".format(item['filename'], json.dumps(metadata, indent=2, sort_keys=True,
                                                                           separators=(',', ': '))))
             run_requires = metadata.get('run_requires')
             if run_requires:
                 deps = run_requires[0]['requires']
                 self.assertTrue(
                     all(verify_dependency(dep) for dep in deps),
                     "Dependencies of {} use disallowed extension dependencies. "
                     "Remove these dependencies: {}".format(item['filename'], deps))
     shutil.rmtree(extensions_dir)
 def test_metadata(self):
     self.maxDiff = None
     extensions_dir = tempfile.mkdtemp()
     for ext_name, exts in self.index['extensions'].items():
         for item in exts:
             ext_dir = tempfile.mkdtemp(dir=extensions_dir)
             ext_file = get_whl_from_url(item['downloadUrl'], item['filename'],
                                         self.whl_cache_dir, self.whl_cache)
             metadata = get_ext_metadata(ext_dir, ext_file, ext_name)
             # Due to https://github.com/pypa/wheel/issues/195 we prevent whls built with 0.31.0 or greater.
             # 0.29.0, 0.30.0 are the two previous versions before that release.
             supported_generators = ['bdist_wheel (0.29.0)', 'bdist_wheel (0.30.0)']
             self.assertIn(metadata.get('generator'), supported_generators,
                           "{}: 'generator' should be one of {}. "
                           "Build the extension with a different version of the 'wheel' package "
                           "(e.g. `pip install wheel==0.30.0`). "
                           "This is due to https://github.com/pypa/wheel/issues/195".format(ext_name,
                                                                                            supported_generators))
             self.assertDictEqual(metadata, item['metadata'],
                                  "Metadata for {} in index doesn't match the expected of: \n"
                                  "{}".format(item['filename'], json.dumps(metadata, indent=2, sort_keys=True,
                                                                           separators=(',', ': '))))
             run_requires = metadata.get('run_requires')
             if run_requires:
                 deps = run_requires[0]['requires']
                 self.assertTrue(
                     all(verify_dependency(dep) for dep in deps),
                     "Dependencies of {} use disallowed extension dependencies. "
                     "Remove these dependencies: {}".format(item['filename'], deps))
     shutil.rmtree(extensions_dir)
 def test_source_wheels(self):
     # Test we can build all sources into wheels and that metadata from the wheel is valid
     built_whl_dir = tempfile.mkdtemp()
     source_extensions = [
         os.path.join(SRC_PATH, n) for n in os.listdir(SRC_PATH)
         if os.path.isdir(os.path.join(SRC_PATH, n))
     ]
     for s in source_extensions:
         if not os.path.isfile(os.path.join(s, 'setup.py')):
             continue
         try:
             check_output([
                 'python', 'setup.py', 'bdist_wheel', '-q', '-d',
                 built_whl_dir
             ],
                          cwd=s)
         except CalledProcessError as err:
             self.fail("Unable to build extension {} : {}".format(s, err))
     for filename in os.listdir(built_whl_dir):
         ext_file = os.path.join(built_whl_dir, filename)
         ext_dir = tempfile.mkdtemp(dir=built_whl_dir)
         ext_name = WHEEL_INFO_RE(filename).groupdict().get('name')
         metadata = get_ext_metadata(ext_dir, ext_file, ext_name)
         run_requires = metadata.get('run_requires')
         if run_requires:
             deps = run_requires[0]['requires']
             self.assertTrue(
                 all(verify_dependency(dep) for dep in deps),
                 "Dependencies of {} use disallowed extension dependencies. "
                 "Remove these dependencies: {}".format(filename, deps))
     shutil.rmtree(built_whl_dir)
 def test_source_wheels(self):
     # Test we can build all sources into wheels and that metadata from the wheel is valid
     built_whl_dir = tempfile.mkdtemp()
     source_extensions = [os.path.join(SRC_PATH, n) for n in os.listdir(SRC_PATH)
                          if os.path.isdir(os.path.join(SRC_PATH, n))]
     for s in source_extensions:
         if not os.path.isfile(os.path.join(s, 'setup.py')):
             continue
         try:
             check_output(['python', 'setup.py', 'bdist_wheel', '-q', '-d', built_whl_dir], cwd=s)
         except CalledProcessError as err:
             self.fail("Unable to build extension {} : {}".format(s, err))
     for filename in os.listdir(built_whl_dir):
         ext_file = os.path.join(built_whl_dir, filename)
         ext_dir = tempfile.mkdtemp(dir=built_whl_dir)
         ext_name = WHEEL_INFO_RE(filename).groupdict().get('name')
         metadata = get_ext_metadata(ext_dir, ext_file, ext_name)
         run_requires = metadata.get('run_requires')
         if run_requires:
             deps = run_requires[0]['requires']
             self.assertTrue(all(verify_dependency(dep) for dep in deps),
                             "Dependencies of {} use disallowed extension dependencies. "
                             "Remove these dependencies: {}".format(filename, deps))
     shutil.rmtree(built_whl_dir)
Example #5
0
    def test_metadata(self):
        skipable_extension_thresholds = {
            'ip-group': '0.1.2',
            'vm-repair': '0.3.1',
            'mixed-reality': '0.0.2',
            'subscription': '0.1.4',
            'managementpartner': '0.1.3',
            'log-analytics': '0.2.1'
        }

        historical_extensios = {
            'keyvault-preview': '0.1.3',
            'log-analytics': '0.2.1'
        }

        extensions_dir = tempfile.mkdtemp()
        for ext_name, exts in self.index['extensions'].items():
            for item in exts:
                ext_dir = tempfile.mkdtemp(dir=extensions_dir)
                ext_file = get_whl_from_url(item['downloadUrl'],
                                            item['filename'],
                                            self.whl_cache_dir, self.whl_cache)

                print(ext_file)

                ext_version = item['metadata']['version']
                try:
                    metadata = get_ext_metadata(ext_dir, ext_file,
                                                ext_name)  # check file exists
                except ValueError as ex:
                    if ext_name in skipable_extension_thresholds:
                        threshold_version = skipable_extension_thresholds[
                            ext_name]

                        if LooseVersion(ext_version) <= LooseVersion(
                                threshold_version):
                            continue
                        else:
                            raise ex
                    else:
                        raise ex

                try:
                    self.assertIn('azext.minCliCoreVersion',
                                  metadata)  # check key properties exists
                except AssertionError as ex:
                    if ext_name in historical_extensios:
                        threshold_version = historical_extensios[ext_name]

                        if LooseVersion(ext_version) <= LooseVersion(
                                threshold_version):
                            continue
                        else:
                            raise ex
                    else:
                        raise ex

                # Due to https://github.com/pypa/wheel/issues/195 we prevent whls built with 0.31.0 or greater.
                # 0.29.0, 0.30.0 are the two previous versions before that release.
                supported_generators = [
                    'bdist_wheel (0.29.0)', 'bdist_wheel (0.30.0)'
                ]
                self.assertIn(
                    metadata.get('generator'), supported_generators,
                    "{}: 'generator' should be one of {}. "
                    "Build the extension with a different version of the 'wheel' package "
                    "(e.g. `pip install wheel==0.30.0`). "
                    "This is due to https://github.com/pypa/wheel/issues/195".
                    format(ext_name, supported_generators))
                self.assertDictEqual(
                    metadata, item['metadata'],
                    "Metadata for {} in index doesn't match the expected of: \n"
                    "{}".format(
                        item['filename'],
                        json.dumps(metadata,
                                   indent=2,
                                   sort_keys=True,
                                   separators=(',', ': '))))
                run_requires = metadata.get('run_requires')
                if run_requires:
                    deps = run_requires[0]['requires']
                    self.assertTrue(
                        all(verify_dependency(dep) for dep in deps),
                        "Dependencies of {} use disallowed extension dependencies. "
                        "Remove these dependencies: {}".format(
                            item['filename'], deps))
        shutil.rmtree(extensions_dir)