Exemplo n.º 1
0
  def finalize_options(self):
    if self.test_dir is None:
      if self.distribution.google_test_dir:
        self.test_dir = self.distribution.google_test_dir
      else:
        raise errors.DistutilsOptionError('No test directory specified')

    self.test_module_pattern = re.compile(self.test_module_pattern)
    self.test_args = shlex.split(self.test_args)
Exemplo n.º 2
0
 def _ensure_stringlike(self, option, what, default=None):
     # type: (typing.unicode, typing.unicode, typing.Any) -> typing.Any
     val = getattr(self, option)
     if val is None:
         setattr(self, option, default)
         return default
     elif not isinstance(val, str):
         raise errors.DistutilsOptionError("'%s' must be a %s (got `%s`)"
                                           % (option, what, val))
     return val
Exemplo n.º 3
0
 def finalize_options(self):
     if not self.msdeploy_bdists:
         raise errors.DistutilsOptionError(
             'The msdeploy_bdists option is required')
     else:
         self.msdeploy_bdists = shlex.split(self.msdeploy_bdists)
     self.distributions = []
     self.ensure_filename('template')
     if self.template is None:
         self.template = 'WebPIList.pt'
     from zope.pagetemplate import pagetemplatefile
     self.template = pagetemplatefile.PageTemplateFile(self.template)
     if self.dist_dir is None:
         self.dist_dir = "dist"
     if self.msdeploy_url_template is None:
         self.msdeploy_url_template = msdeploy_url_template
     options.ensure_verbosity(self)
Exemplo n.º 4
0
def run_command_hooks(cmd_obj, hook_kind):
    """Run hooks registered for that command and phase.

    *cmd_obj* is a finalized command object; *hook_kind* is either
    'pre_hook' or 'post_hook'.
    """

    if hook_kind not in ('pre_hook', 'post_hook'):
        raise ValueError('invalid hook kind: %r' % hook_kind)

    hooks = getattr(cmd_obj, hook_kind, None)

    if hooks is None:
        return

    for hook in hooks.values():
        if isinstance(hook, str):
            try:
                hook_obj = resolve_name(hook)
            except ImportError:
                err = sys.exc_info()[1]  # For py3k
                raise errors.DistutilsModuleError('cannot find hook %s: %s' %
                                                  (hook, err))
        else:
            hook_obj = hook

        if not hasattr(hook_obj, '__call__'):
            raise errors.DistutilsOptionError('hook %r is not callable' % hook)

        log.info('running %s %s for command %s', hook_kind, hook,
                 cmd_obj.get_command_name())

        try:
            hook_obj(cmd_obj)
        except:
            e = sys.exc_info()[1]
            log.error('hook %s raised exception: %s\n' % (hook, e))
            log.error(traceback.format_exc())
            sys.exit(1)
Exemplo n.º 5
0
 def finalize_options(self):
     if self.identity and not self.sign:
         raise errors.DistutilsOptionError(
             "Must use --sign for --identity to have meaning")
     if 'HOME' in os.environ:
         rc = os.path.join(os.environ['HOME'], '.pypirc')
         if os.path.exists(rc):
             self.announce('Using PyPI login from %s' % rc)
             config = ConfigParser.ConfigParser({
                 'username': '',
                 'password': '',
                 'repository': ''
             })
             config.read(rc)
             if not self.repository:
                 self.repository = config.get('server-login', 'repository')
             if not self.username:
                 self.username = config.get('server-login', 'username')
             if not self.password:
                 self.password = config.get('server-login', 'password')
     if not self.repository:
         self.repository = self.DEFAULT_REPOSITORY
Exemplo n.º 6
0
def setup_cfg_to_setup_kwargs(config, script_args=()):
    """Processes the setup.cfg options and converts them to arguments accepted
    by setuptools' setup() function.
    """

    kwargs = {}

    # Temporarily holds install_requires and extra_requires while we
    # parse env_markers.
    all_requirements = {}

    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            # The distutils field name is different than distutils2's.
            section, option = D1_D2_SETUP_ARGS[arg]

        elif len(D1_D2_SETUP_ARGS[arg]) == 1:
            # The distutils field name is the same thant distutils2's.
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg

        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            # There is no such option in the setup.cfg
            if arg == "long_description":
                in_cfg_value = has_get_option(config, section,
                                              "description_file")
                if in_cfg_value:
                    in_cfg_value = split_multiline(in_cfg_value)
                    value = ''
                    for filename in in_cfg_value:
                        description_file = open(filename)
                        try:
                            value += description_file.read().strip() + '\n\n'
                        finally:
                            description_file.close()
                    in_cfg_value = value
            else:
                continue

        if arg in CSV_FIELDS:
            in_cfg_value = split_csv(in_cfg_value)
        if arg in MULTI_FIELDS:
            in_cfg_value = split_multiline(in_cfg_value)
        elif arg in MAP_FIELDS:
            in_cfg_map = {}
            for i in split_multiline(in_cfg_value):
                k, v = i.split('=')
                in_cfg_map[k.strip()] = v.strip()
            in_cfg_value = in_cfg_map
        elif arg in BOOL_FIELDS:
            # Provide some flexibility here...
            if in_cfg_value.lower() in ('true', 't', '1', 'yes', 'y'):
                in_cfg_value = True
            else:
                in_cfg_value = False

        if in_cfg_value:
            if arg in ('install_requires', 'tests_require'):
                # Replaces PEP345-style version specs with the sort expected by
                # setuptools
                in_cfg_value = [
                    _VERSION_SPEC_RE.sub(r'\1\2', pred)
                    for pred in in_cfg_value
                ]
            if arg == 'install_requires':
                # Split install_requires into package,env_marker tuples
                # These will be re-assembled later
                install_requires = []
                requirement_pattern = '(?P<package>[^;]*);?(?P<env_marker>[^#]*?)(?:\s*#.*)?$'
                for requirement in in_cfg_value:
                    m = re.match(requirement_pattern, requirement)
                    requirement_package = m.group('package').strip()
                    env_marker = m.group('env_marker').strip()
                    install_requires.append((requirement_package, env_marker))
                all_requirements[''] = install_requires
            elif arg == 'package_dir':
                in_cfg_value = {'': in_cfg_value}
            elif arg in ('package_data', 'data_files'):
                data_files = {}
                firstline = True
                prev = None
                for line in in_cfg_value:
                    if '=' in line:
                        key, value = line.split('=', 1)
                        key, value = (key.strip(), value.strip())
                        if key in data_files:
                            # Multiple duplicates of the same package name;
                            # this is for backwards compatibility of the old
                            # format prior to d2to1 0.2.6.
                            prev = data_files[key]
                            prev.extend(value.split())
                        else:
                            prev = data_files[key.strip()] = value.split()
                    elif firstline:
                        raise errors.DistutilsOptionError(
                            'malformed package_data first line %r (misses '
                            '"=")' % line)
                    else:
                        prev.extend(line.strip().split())
                    firstline = False
                if arg == 'data_files':
                    # the data_files value is a pointlessly different structure
                    # from the package_data value
                    data_files = data_files.items()
                in_cfg_value = data_files
            elif arg == 'cmdclass':
                cmdclass = {}
                dist = st_dist.Distribution()
                for cls_name in in_cfg_value:
                    cls = resolve_name(cls_name)
                    cmd = cls(dist)
                    cmdclass[cmd.get_command_name()] = cls
                in_cfg_value = cmdclass

        kwargs[arg] = in_cfg_value

    # Transform requirements with embedded environment markers to
    # setuptools' supported marker-per-requirement format.
    #
    # install_requires are treated as a special case of extras, before
    # being put back in the expected place
    #
    # fred =
    #     foo:marker
    #     bar
    # -> {'fred': ['bar'], 'fred:marker':['foo']}

    if 'extras' in config:
        requirement_pattern = '(?P<package>[^:]*):?(?P<env_marker>[^#]*?)(?:\s*#.*)?$'
        extras = config['extras']
        # Add contents of test-requirements, if any, into an extra named
        # 'test' if one does not already exist.
        if 'test' not in extras:
            from pbr import packaging
            extras['test'] = "\n".join(
                packaging.parse_requirements(
                    packaging.TEST_REQUIREMENTS_FILES)).replace(';', ':')

        for extra in extras:
            extra_requirements = []
            requirements = split_multiline(extras[extra])
            for requirement in requirements:
                m = re.match(requirement_pattern, requirement)
                extras_value = m.group('package').strip()
                env_marker = m.group('env_marker')
                extra_requirements.append((extras_value, env_marker))
            all_requirements[extra] = extra_requirements

    # Transform the full list of requirements into:
    # - install_requires, for those that have no extra and no
    #   env_marker
    # - named extras, for those with an extra name (which may include
    #   an env_marker)
    # - and as a special case, install_requires with an env_marker are
    #   treated as named extras where the name is the empty string

    extras_require = {}
    for req_group in all_requirements:
        for requirement, env_marker in all_requirements[req_group]:
            if env_marker:
                extras_key = '%s:(%s)' % (req_group, env_marker)
                # We do not want to poison wheel creation with locally
                # evaluated markers.  sdists always re-create the egg_info
                # and as such do not need guarded, and pip will never call
                # multiple setup.py commands at once.
                if 'bdist_wheel' not in script_args:
                    try:
                        if pkg_resources.evaluate_marker('(%s)' % env_marker):
                            extras_key = req_group
                    except SyntaxError:
                        log.error(
                            "Marker evaluation failed, see the following "
                            "error.  For more information see: "
                            "http://docs.openstack.org/"
                            "developer/pbr/compatibility.html#evaluate-marker")
                        raise
            else:
                extras_key = req_group
            extras_require.setdefault(extras_key, []).append(requirement)

    kwargs['install_requires'] = extras_require.pop('', [])
    kwargs['extras_require'] = extras_require

    return kwargs
Exemplo n.º 7
0
 def finalize_options(self):
     if self.client and self.server:
         raise _errors.DistutilsOptionError(
             'you may only specify one of client or server')
Exemplo n.º 8
0
 def run(self):
     if not self.distribution.dist_files:
         raise errors.DistutilsOptionError(
             "No dist file created in earlier command")
     for command, pyversion, filename in self.distribution.dist_files:
         self.upload_file(command, pyversion, filename)
Exemplo n.º 9
0
def assert_list(dist, attr, value):
    if not isinstance(value, list):
        raise errors.DistutilsOptionError(
            'The {0} option must be a list: {1}'.format(attr, value))
Exemplo n.º 10
0
def assert_string(dist, attr, value):
    if not isinstance(value, str):
        raise errors.DistutilsOptionError(
            'The {0} option must be a string: {1}'.format(attr, value))