Пример #1
0
def _build_check_info(app_dir, logger):
    """Get info about packages scheduled for (un)install/update"""
    handler = _AppHandler(app_dir, logger)
    messages = handler.build_check(fast=True)
    # Decode the messages into a dict:
    status = {'install': [], 'uninstall': [], 'update': []}
    for msg in messages:
        for key, pattern in _message_map.items():
            match = pattern.match(msg)
            if match:
                status[key].append(match.group('name'))
    return status
Пример #2
0
    def _latest_compatible_package_versions(self, names):
        """Get the latest compatible version of a list of packages.

        This is a variant of similar code in lab app, but optimized
        for checking several packages in one go.
        """
        handler = _AppHandler(self.app_dir, self.log)
        core_data = handler.info['core_data']

        keys = []
        for name in names:
            try:
                metadata = _fetch_package_metadata(handler.registry, name, self.log)
            except URLError:
                continue
            versions = metadata.get('versions', [])

            # Sort pre-release first, as we will reverse the sort:
            def sort_key(key_value):
                return _semver_key(key_value[0], prerelease_first=True)

            for version, data in sorted(versions.items(),
                                        key=sort_key,
                                        reverse=True):
                deps = data.get('dependencies', {})
                errors = _validate_compatibility(name, deps, core_data)
                if not errors:
                    # Found a compatible version
                    keys.append('%s@%s' % (name, version))
                    break  # break inner for


        versions = {}
        if not keys:
            return versions
        with TemporaryDirectory() as tempdir:
            ret = handler._run([which('npm'), 'pack'] + keys, cwd=tempdir, quiet=True)
            if ret != 0:
                msg = '"%s" is not a valid npm package'
                raise ValueError(msg % keys)

            for key in keys:
                fname = key[0].replace('@', '') + key[1:].replace('@', '-').replace('/', '-') + '.tgz'
                data = _read_package(os.path.join(tempdir, fname))
                # Verify that the version is a valid extension.
                if not _validate_extension(data):
                    # Valid
                    versions[key] = data['version']
        return versions
Пример #3
0
    def test_populate_staging(self):
        with patch("subprocess.check_output") as check_output:
            yarn_registry = "https://private.yarn/manager"
            check_output.return_value = b'\n'.join([
                b'{"type":"info","data":"yarn config"}',
                b'{"type":"inspect","data":{"registry":"' + bytes(yarn_registry, 'utf-8') + b'"}}',
                b'{"type":"info","data":"npm config"}',
                b'{"type":"inspect","data":{"registry":"' + bytes(yarn_registry, 'utf-8') + b'"}}'
            ])

            staging = pjoin(self.app_dir, 'staging')
            handler = commands._AppHandler(commands.AppOptions())
            handler._populate_staging()

            lock_path = pjoin(staging, 'yarn.lock')
            with open(lock_path) as f:
                lock = f.read()

            self.assertNotIn(commands.YARN_DEFAULT_REGISTRY, lock)
            self.assertIn(yarn_registry, lock)
Пример #4
0
def _ensure_compat_errors(info, app_dir, logger):
    """Ensure that the app info has compat_errors field"""
    handler = _AppHandler(app_dir, logger)
    info['compat_errors'] = handler._get_extension_compat()