Example #1
0
    def generate_manifest_content(self):
        manifest = {
            'abi': self.abi,
            'arch': self.arch,
            'categories': self.categories,
            'comment': self.comment,
            'deps': self.deps,
            'desc': self.desc,
            'directories': {},
            'files': {},
            'flatsize': 0,
            'groups': self.groups,
            'licenselogic': 'single',
            'licenses': [self.license] if self.license else [],
            'maintainer': self.maintainer,
            'name': self.name,
            'options': self.options,
            'origin': self.origin,
            'prefix': self.prefix,
            'provides': self.provides,
            'requires': self.requires,
            'scripts': self.scripts,
            'users': self.users,
            'version': self.version,
            'www': self.www,
        }

        mdirs = manifest['directories']
        mfiles = manifest['files']
        for real_file_path, install_path in self.iter_install_files():
            with open(real_file_path, 'rb') as fh:
                data = fh.read()
                manifest['flatsize'] += len(data)
                mdirs[os.path.dirname(install_path)] = {
                    'gname': 'wheel',
                    'perm': '0755',
                    'uname': 'root',
                }
                mfiles[install_path] = {
                    'gname': 'wheel',
                    'perm': '0644',
                    'sum': hashlib.sha256(data).hexdigest(),
                    'uname': 'root',
                }

        # TODO: Should we keep UNKNOWN values?
        manifest = {
            key: value
            for key, value in manifest.items() if value and value != 'UNKNOWN'
        }

        if 'name' not in manifest:
            raise DistutilsOptionError('Project must have name defined')

        if 'version' not in manifest:
            raise DistutilsOptionError('Project must have version defined')

        if 'comment' not in manifest:
            raise DistutilsOptionError('Project must have description defined')

        if 'desc' not in manifest:
            raise DistutilsOptionError('Project must have long_description'
                                       ' defined')

        if 'maintainer' not in manifest:
            raise DistutilsOptionError('Project must have author or maintainer'
                                       ' defined')

        return manifest
Example #2
0
 def finalize_options(self):
     option_base.finalize_options(self)
     if self.command is None or self.option is None:
         raise DistutilsOptionError("Must specify --command *and* --option")
     if self.set_value is None and not self.remove:
         raise DistutilsOptionError("Must specify --set-value or --remove")
 def finalize_options(self):
     if self.test_suite is None and self.test_module is None:
         self.test_module = 'test'
     elif self.test_module is not None and self.test_suite is not None:
         raise DistutilsOptionError(
             "You may specify a module or suite, but not both")
    def add_files(self):
        db = self.db
        cab = msilib.CAB("distfiles")
        rootdir = os.path.abspath(self.bdist_dir)

        root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir")
        f = Feature(db,
                    "Python",
                    "Python",
                    "Everything",
                    0,
                    1,
                    directory="TARGETDIR")

        items = [(f, root, "")]
        for version in self.versions + [self.other_version]:
            target = "TARGETDIR" + version
            name = default = "Python" + version
            desc = "Everything"
            if version is self.other_version:
                title = "Python from another location"
                level = 2
            else:
                title = "Python %s from registry" % version
                level = 1
            f = Feature(db, name, title, desc, 1, level, directory=target)
            dir = Directory(db, cab, root, rootdir, target, default)
            items.append((f, dir, version))
        db.Commit()

        seen = {}
        for feature, dir, version in items:
            todo = [dir]
            while todo:
                dir = todo.pop()
                for file in os.listdir(dir.absolute):
                    afile = os.path.join(dir.absolute, file)
                    if os.path.isdir(afile):
                        short = "%s|%s" % (dir.make_short(file), file)
                        default = file + version
                        newdir = Directory(db, cab, dir, file, default, short)
                        todo.append(newdir)
                    else:
                        if not dir.component:
                            dir.start_component(dir.logical, feature, 0)
                        if afile not in seen:
                            key = seen[afile] = dir.add_file(file)
                            if file == self.install_script:
                                if self.install_script_key:
                                    raise DistutilsOptionError(
                                        "Multiple files with name %s" % file)
                                self.install_script_key = "[#%s]" % key
                        else:
                            key = seen[afile]
                            add_data(
                                self.db,
                                "DuplicateFile",
                                [(
                                    key + version,
                                    dir.component,
                                    key,
                                    None,
                                    dir.logical,
                                )],
                            )
            db.Commit()
        cab.commit(db)
Example #5
0
 def finalize_options(self):
     if self.riak_admin is None:
         raise DistutilsOptionError("riak-admin option not set")
Example #6
0
    def finalize_options(self):
        if not self.directory:
            raise DistutilsOptionError('you must specify the base directory')

        if not self.output_dir:
            self.output_dir = self.directory
Example #7
0
    def finalize_options(self):
        """Finalizes options."""
        # This method (and its pliant slaves, like 'finalize_unix()',
        # 'finalize_other()', and 'select_scheme()') is where the default
        # installation directories for modules, extension modules, and
        # anything else we care to install from a Python module
        # distribution.  Thus, this code makes a pretty important policy
        # statement about how third-party stuff is added to a Python
        # installation!  Note that the actual work of installation is done
        # by the relatively simple 'install_*' commands; they just take
        # their orders from the installation directory options determined
        # here.

        # Check for errors/inconsistencies in the options; first, stuff
        # that's wrong on any platform.

        if ((self.prefix or self.exec_prefix or self.home)
                and (self.install_base or self.install_platbase)):
            raise DistutilsOptionError(
                "must supply either prefix/exec-prefix/home or " +
                "install-base/install-platbase -- not both")

        if self.home and (self.prefix or self.exec_prefix):
            raise DistutilsOptionError(
                "must supply either home or prefix/exec-prefix -- not both")

        if self.user and (self.prefix or self.exec_prefix or self.home
                          or self.install_base or self.install_platbase):
            raise DistutilsOptionError(
                "can't combine user with prefix, "
                "exec_prefix/home, or install_(plat)base")

        # Next, stuff that's wrong (or dubious) only on certain platforms.
        if os.name != "posix":
            if self.exec_prefix:
                self.warn("exec-prefix option ignored on this platform")
                self.exec_prefix = None

        # Now the interesting logic -- so interesting that we farm it out
        # to other methods.  The goal of these methods is to set the final
        # values for the install_{Lib,scripts,data,...}  options, using as
        # input a heady brew of prefix, exec_prefix, home, install_base,
        # install_platbase, user-supplied versions of
        # install_{purelib,platlib,Lib,scripts,data,...}, and the
        # INSTALL_SCHEME dictionary above.  Phew!

        self.dump_dirs("pre-finalize_{unix,other}")

        if os.name == 'posix':
            self.finalize_unix()
        else:
            self.finalize_other()

        self.dump_dirs("post-finalize_{unix,other}()")

        # Expand configuration variables, tilde, etc. in self.install_base
        # and self.install_platbase -- that way, we can use $base or
        # $platbase in the other installation directories and not worry
        # about needing recursive variable expansion (shudder).

        py_version = sys.version.split()[0]
        (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
        try:
            abiflags = sys.abiflags
        except AttributeError:
            # sys.abiflags may not be defined on all platforms.
            abiflags = ''
        self.config_vars = {
            'dist_name': self.distribution.get_name(),
            'dist_version': self.distribution.get_version(),
            'dist_fullname': self.distribution.get_fullname(),
            'py_version': py_version,
            'py_version_short': '%d.%d' % sys.version_info[:2],
            'py_version_nodot': '%d%d' % sys.version_info[:2],
            'sys_prefix': prefix,
            'prefix': prefix,
            'sys_exec_prefix': exec_prefix,
            'exec_prefix': exec_prefix,
            'abiflags': abiflags,
        }

        if HAS_USER_SITE:
            self.config_vars['userbase'] = self.install_userbase
            self.config_vars['usersite'] = self.install_usersite

        self.expand_basedirs()

        self.dump_dirs("post-expand_basedirs()")

        # Now define config vars for the base directories so we can expand
        # everything else.
        self.config_vars['base'] = self.install_base
        self.config_vars['platbase'] = self.install_platbase

        if DEBUG:
            from pprint import pprint
            print("config vars:")
            pprint(self.config_vars)

        # Expand "~" and configuration variables in the installation
        # directories.
        self.expand_dirs()

        self.dump_dirs("post-expand_dirs()")

        # Create directories in the home dir:
        if self.user:
            self.create_home_path()

        # Pick the actual directory to install all modules to: either
        # install_purelib or install_platlib, depending on whether this
        # module distribution is pure or not.  Of course, if the user
        # already specified install_lib, use their selection.
        if self.install_lib is None:
            if self.distribution.ext_modules:  # has extensions: non-pure
                self.install_lib = self.install_platlib
            else:
                self.install_lib = self.install_purelib

        # Convert directories from Unix /-separated syntax to the local
        # convention.
        self.convert_paths('Lib', 'purelib', 'platlib', 'scripts', 'data',
                           'headers', 'userbase', 'usersite')

        # Deprecated
        # Well, we're not actually fully completely finalized yet: we still
        # have to deal with 'extra_path', which is the hack for allowing
        # non-packagized module distributions (hello, Numerical Python!) to
        # get their own directories.
        self.handle_extra_path()
        self.install_libbase = self.install_lib  # needed for .pth file
        self.install_lib = os.path.join(self.install_lib, self.extra_dirs)

        # If a new root directory was supplied, make all the installation
        # dirs relative to it.
        if self.root is not None:
            self.change_roots('libbase', 'Lib', 'purelib', 'platlib',
                              'scripts', 'data', 'headers')

        self.dump_dirs("after prepending root")

        # Find out the build directories, ie. where to install from.
        self.set_undefined_options('build', ('build_base', 'build_base'),
                                   ('build_lib', 'build_lib'))
Example #8
0
            path_to_setup = '../' * (path_to_setup.count('/') + 1)
        resolved = normalize_path(os.path.join(install_dir, egg_path, path_to_setup))
        if resolved != normalize_path(os.curdir):
            raise DistutilsOptionError(
                "Can't get a consistent path to setup script from"
                " installation directory", resolved, normalize_path(os.curdir))
        return path_to_setup
=======
        p = self.egg_base.replace(os.sep, '/')
        if p != os.curdir:
            p = '../' * (p.count('/') + 1)
        self.setup_path = p
        p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
        if p != normalize_path(os.curdir):
            raise DistutilsOptionError(
                "Can't get a consistent path to setup script from"
                " installation directory", p, normalize_path(os.curdir))
>>>>>>> 2f581e39b6af1df0ce14b10b2b421d90ca31ff2c

    def install_for_development(self):
        if six.PY3 and getattr(self.distribution, 'use_2to3', False):
            # If we run 2to3 we can not do this inplace:

            # Ensure metadata is up-to-date
            self.reinitialize_command('build_py', inplace=0)
            self.run_command('build_py')
            bpy_cmd = self.get_finalized_command("build_py")
            build_path = normalize_path(bpy_cmd.build_lib)

            # Build extensions
            self.reinitialize_command('egg_info', egg_base=build_path)
Example #9
0
 def finalize_options(self):
     if not self.input_file and not self.input_dir:
         raise DistutilsOptionError('you must specify either the input '
                                    'file or directory')
Example #10
0
    def finalize_options(self):
        if self.input_dirs:
            if not self.input_paths:
                self.input_paths = self.input_dirs
            else:
                raise DistutilsOptionError(
                    'input-dirs and input-paths are mutually exclusive')

        if self.no_default_keywords:
            keywords = {}
        else:
            keywords = DEFAULT_KEYWORDS.copy()

        keywords.update(parse_keywords(listify_value(self.keywords)))

        self.keywords = keywords

        if not self.keywords:
            raise DistutilsOptionError('you must specify new keywords if you '
                                       'disable the default ones')

        if not self.output_file:
            raise DistutilsOptionError('no output file specified')
        if self.no_wrap and self.width:
            raise DistutilsOptionError(
                "'--no-wrap' and '--width' are mutually "
                "exclusive")
        if not self.no_wrap and not self.width:
            self.width = 76
        elif self.width is not None:
            self.width = int(self.width)

        if self.sort_output and self.sort_by_file:
            raise DistutilsOptionError("'--sort-output' and '--sort-by-file' "
                                       "are mutually exclusive")

        if self.input_paths:
            if isinstance(self.input_paths, string_types):
                self.input_paths = re.split(r',\s*', self.input_paths)
        elif self.distribution is not None:
            self.input_paths = dict.fromkeys([
                k.split('.', 1)[0] for k in (self.distribution.packages or ())
            ]).keys()
        else:
            self.input_paths = []

        if not self.input_paths:
            raise DistutilsOptionError(
                "no input files or directories specified")

        for path in self.input_paths:
            if not os.path.exists(path):
                raise DistutilsOptionError("Input path: %s does not exist" %
                                           path)

        self.add_comments = listify_value(self.add_comments or (), ",")

        if self.distribution:
            if not self.project:
                self.project = self.distribution.get_name()
            if not self.version:
                self.version = self.distribution.get_version()

        if self.add_location == 'never':
            self.no_location = True
        elif self.add_location == 'file':
            self.include_lineno = False
Example #11
0
    def run(self):
        po_files = []
        if not self.output_file:
            if self.locale:
                po_files.append(
                    (self.locale,
                     os.path.join(self.output_dir, self.locale, 'LC_MESSAGES',
                                  self.domain + '.po')))
            else:
                for locale in os.listdir(self.output_dir):
                    po_file = os.path.join(self.output_dir, locale,
                                           'LC_MESSAGES', self.domain + '.po')
                    if os.path.exists(po_file):
                        po_files.append((locale, po_file))
        else:
            po_files.append((self.locale, self.output_file))

        if not po_files:
            raise DistutilsOptionError('no message catalogs found')

        domain = self.domain
        if not domain:
            domain = os.path.splitext(os.path.basename(self.input_file))[0]

        with open(self.input_file, 'rb') as infile:
            template = read_po(infile)

        for locale, filename in po_files:
            self.log.info('updating catalog %s based on %s', filename,
                          self.input_file)
            with open(filename, 'rb') as infile:
                catalog = read_po(infile, locale=locale, domain=domain)

            catalog.update(template,
                           self.no_fuzzy_matching,
                           update_header_comment=self.update_header_comment)

            tmpname = os.path.join(
                os.path.dirname(filename),
                tempfile.gettempprefix() + os.path.basename(filename))
            try:
                with open(tmpname, 'wb') as tmpfile:
                    write_po(tmpfile,
                             catalog,
                             omit_header=self.omit_header,
                             ignore_obsolete=self.ignore_obsolete,
                             include_previous=self.previous,
                             width=self.width)
            except:
                os.remove(tmpname)
                raise

            try:
                os.rename(tmpname, filename)
            except OSError:
                # We're probably on Windows, which doesn't support atomic
                # renames, at least not through Python
                # If the error is in fact due to a permissions problem, that
                # same error is going to be raised from one of the following
                # operations
                os.remove(filename)
                shutil.copy(tmpname, filename)
                os.remove(tmpname)
Example #12
0
    def _run_domain(self, domain):
        po_files = []
        mo_files = []

        if not self.input_file:
            if self.locale:
                po_files.append((self.locale,
                                 os.path.join(self.directory, self.locale,
                                              'LC_MESSAGES', domain + '.po')))
                mo_files.append(
                    os.path.join(self.directory, self.locale, 'LC_MESSAGES',
                                 domain + '.mo'))
            else:
                for locale in os.listdir(self.directory):
                    po_file = os.path.join(self.directory, locale,
                                           'LC_MESSAGES', domain + '.po')
                    if os.path.exists(po_file):
                        po_files.append((locale, po_file))
                        mo_files.append(
                            os.path.join(self.directory, locale, 'LC_MESSAGES',
                                         domain + '.mo'))
        else:
            po_files.append((self.locale, self.input_file))
            if self.output_file:
                mo_files.append(self.output_file)
            else:
                mo_files.append(
                    os.path.join(self.directory, self.locale, 'LC_MESSAGES',
                                 domain + '.mo'))

        if not po_files:
            raise DistutilsOptionError('no message catalogs found')

        catalogs_and_errors = {}

        for idx, (locale, po_file) in enumerate(po_files):
            mo_file = mo_files[idx]
            with open(po_file, 'rb') as infile:
                catalog = read_po(infile, locale)

            if self.statistics:
                translated = 0
                for message in list(catalog)[1:]:
                    if message.string:
                        translated += 1
                percentage = 0
                if len(catalog):
                    percentage = translated * 100 // len(catalog)
                self.log.info('%d of %d messages (%d%%) translated in %s',
                              translated, len(catalog), percentage, po_file)

            if catalog.fuzzy and not self.use_fuzzy:
                self.log.info('catalog %s is marked as fuzzy, skipping',
                              po_file)
                continue

            catalogs_and_errors[catalog] = catalog_errors = list(
                catalog.check())
            for message, errors in catalog_errors:
                for error in errors:
                    self.log.error('error: %s:%d: %s', po_file, message.lineno,
                                   error)

            self.log.info('compiling catalog %s to %s', po_file, mo_file)

            with open(mo_file, 'wb') as outfile:
                write_mo(outfile, catalog, use_fuzzy=self.use_fuzzy)

        return catalogs_and_errors
Example #13
0
 def finalize_options(self):
     build.finalize_options(self)
     if self.hdfs_core_impl not in hdfsimpl.SUPPORTED:
         raise DistutilsOptionError('%r not supported' %
                                    (self.hdfs_core_impl, ))
Example #14
0
 def finalize_options(self):
     option_base.finalize_options(self)
     if self.remove and len(self.args) != 1:
         raise DistutilsOptionError(
             "Must specify exactly one argument (the alias name) when "
             "using --remove")
Example #15
0
    def parse_config_files(self, filenames=None):
        from configparser import ConfigParser

        # Ignore install directory options if we have a venv
        if sys.prefix != sys.base_prefix:
            ignore_options = [
                "install-base",
                "install-platbase",
                "install-lib",
                "install-platlib",
                "install-purelib",
                "install-headers",
                "install-scripts",
                "install-data",
                "prefix",
                "exec-prefix",
                "home",
                "user",
                "root",
            ]
        else:
            ignore_options = []

        ignore_options = frozenset(ignore_options)

        if filenames is None:
            filenames = self.find_config_files()

        if DEBUG:
            self.announce("Distribution.parse_config_files():")

        parser = ConfigParser(interpolation=None)
        for filename in filenames:
            if DEBUG:
                self.announce("  reading %s" % filename)
            parser.read(filename)
            for section in parser.sections():
                options = parser.options(section)
                opt_dict = self.get_option_dict(section)

                for opt in options:
                    if opt != "__name__" and opt not in ignore_options:
                        val = parser.get(section, opt)
                        opt = opt.replace("-", "_")
                        opt_dict[opt] = (filename, val)

            # Make the ConfigParser forget everything (so we retain
            # the original filenames that options come from)
            parser.__init__()

        # If there was a "global" section in the config file, use it
        # to set Distribution options.

        if "global" in self.command_options:
            for (opt, (src, val)) in self.command_options["global"].items():
                alias = self.negative_opt.get(opt)
                try:
                    if alias:
                        setattr(self, alias, not strtobool(val))
                    elif opt in ("verbose", "dry_run"):  # ugh!
                        setattr(self, opt, strtobool(val))
                    else:
                        setattr(self, opt, val)
                except ValueError as msg:
                    raise DistutilsOptionError(msg)
Example #16
0
 def finalize_options(self):
     if self.level not in self.levels.keys():
         raise DistutilsOptionError("Invalid test level: {0}".format(
             self.level))
     self.suite_name = self.levels[self.level]
     super().finalize_options()
Example #17
0
    def finalize_options(self):
        self.extensions = self.distribution.ext_modules

        # Let Cython generate its files in the "cythonized"
        # subdirectory of the build_base directory.
        self.set_undefined_options('build', ('build_base', 'build_base'))
        self.build_dir = os.path.join(self.build_base, "cythonized")

        # Inherit some options from the 'build_ext' command if possible
        # (this in turn implies inheritance from the 'build' command)
        inherit_opts = [('build_lib', 'build_lib'), ('debug', 'debug'),
                        ('force', 'force')]

        # Python 3.5 now has a parallel option as well
        if sys.version_info[:2] >= (3, 5):
            inherit_opts.append(('parallel', 'parallel'))

        self.set_undefined_options('build_ext', *inherit_opts)

        # Always produce debugging output unless SAGE_DEBUG=no is given
        # explicitly
        self.debug = os.environ.get('SAGE_DEBUG', None) != 'no'

        if self.debug:
            log.info('Enabling Cython debugging support')

        if self.profile is None:
            self.profile = os.environ.get('SAGE_PROFILE') == 'yes'

        if self.profile:
            log.info('Enabling Cython profiling support')

        if self.parallel is None:
            self.parallel = os.environ.get('SAGE_NUM_THREADS', '0')

        try:
            self.parallel = int(self.parallel)
        except ValueError:
            raise DistutilsOptionError("parallel should be an integer")

        try:
            import Cython
        except ImportError:
            raise DistutilsModuleError(
                "Cython must be installed and importable in order to run "
                "the cythonize command")

        # Cython compiler directives
        self.cython_directives = dict(
            auto_pickle=False,
            autotestdict=False,
            cdivision=True,
            embedsignature=True,
            fast_getattr=True,
            language_level="2",
            preliminary_late_includes_cy28=True,
            profile=self.profile,
        )
        self.compile_time_env = dict(
            PY_VERSION_HEX=sys.hexversion,
            PY_MAJOR_VERSION=sys.version_info[0],
        )

        # We check the Cython version and some relevant configuration
        # options from the earlier build to see if we need to force a
        # recythonization. If the version or options have changed, we
        # must recythonize all files.
        self._version_file = os.path.join(self.build_dir, '.cython_version')
        self._version_stamp = json.dumps(
            {
                'version': Cython.__version__,
                'debug': self.debug,
                'directives': self.cython_directives,
                'compile_time_env': self.compile_time_env,
            },
            sort_keys=True)

        # Read an already written version file if it exists and compare to the
        # current version stamp
        try:
            if open(self._version_file).read() == self._version_stamp:
                force = False
            else:
                # version_file exists but its contents are not what we
                # want => recythonize all Cython code.
                force = True
                # In case this cythonization is interrupted, we end up
                # in an inconsistent state with C code generated by
                # different Cython versions or with different options.
                # To ensure that this inconsistent state will be fixed,
                # we remove the version_file now to force a
                # recythonization the next time we build Sage.
                os.unlink(self._version_file)
        except IOError:
            # Most likely, the version_file does not exist
            # => (re)cythonize all Cython code.
            force = True

        # If the --force flag was given at the command line, always force;
        # otherwise use what we determined from reading the version file
        if self.force is None:
            self.force = force
Example #18
0
 def finalize_options(self):
     if self.rstpath is None:
         raise DistutilsOptionError('\'rstpath\' option is required')
     self.rstpath = _path_rel2file(self.rstpath)
     self.announce('Generating configuration documentation')
Example #19
0
 def finalize_options(self):
     if not self.input_files:
         raise DistutilsOptionError('you must specify input files')
     if not self.output_dir:
         raise DistutilsOptionError('you must specify the output directory')
Example #20
0
 def finalize_options(self):
     if self.path is None:
         raise DistutilsOptionError('\'path\' option is required')
     self.path = _path_rel2file(self.path)
     self.announce('Generating JSON-LD schema file')
Example #21
0
def setup_cfg_to_setup_kwargs(config):
    """Processes the setup.cfg options and converts them to arguments accepted
    by setuptools' setup() function.
    """

    kwargs = {}

    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 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
                ]
            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 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 = list(data_files.items())
                in_cfg_value = data_files
            elif arg == 'cmdclass':
                cmdclass = {}
                dist = Distribution()
                for cls in in_cfg_value:
                    cls = resolve_name(cls)
                    cmd = cls(dist)
                    cmdclass[cmd.get_command_name()] = cls
                in_cfg_value = cmdclass

        kwargs[arg] = in_cfg_value

    return kwargs
Example #22
0
 def _ensure_tested_string(self, option, tester, what, error_fmt,
                           default=None):
     val = self._ensure_stringlike(option, what, default)
     if val is not None and not tester(val):
         raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
                                    % (option, val))
Example #23
0
def finalize_compiler_options(cmd):
    """Finalize compiler options for a command

    If compiler options (fcompiler, compiler, f2py) have not been
    specified for a command, check if they were specified for other
    commands on the command line--if so, grab from there. If not,
    set reasonable defaults.

    cmd: the command to finalize the options for
    """
    dist = cmd.distribution
    defaults = {
        'fcompiler': 'gnu95',
        'f2py': default_f2py(),
        'compiler': None,
        'f77exec': None,
        'f90exec': None,
    }
    optdict = dist.get_option_dict(cmd.get_command_name())
    #Check all options on all other commands, reverting to default
    #as necessary
    for option in defaults:
        if getattr(cmd, option) == None:
            for c in dist.commands:
                other_cmd = dist.get_command_obj(c)
                if other_cmd == cmd or not hasattr(other_cmd, option):
                    continue
                if getattr(other_cmd, option) != None:
                    setattr(cmd, option, getattr(other_cmd, option))
                    break
            if getattr(cmd, option) == None:
                setattr(cmd, option, defaults[option])
        #Also explicitly carry over command line option, needed for config_fc
        if not option in optdict:
            for c in dist.commands:
                otheroptdict = dist.get_option_dict(c)
                if option in otheroptdict:
                    optdict[option] = otheroptdict[option]
                    break
    #Special-case defaults, checks
    if not cmd.fcompiler in ('pg', 'gnu', 'gnu95', 'intelem', 'intel', 'none',
                             'None'):
        raise DistutilsOptionError(
            '--fcompiler={0} unknown'.format(cmd.fcompiler) +
            ', options: pg, gnu, gnu95, intelem, intel, None')
    if len('%x' % sys.maxsize) * 4 == 32 and cmd.fcompiler == 'intelem':
        raise DistutilsOptionError(
            '--fcompiler=intelem requires a 64-bit architecture')
    if cmd.compiler == None and sys.platform == 'win32':
        cmd.compiler = 'mingw32'
    #Add interpreter to f2py if it needs it (usually on Windows)
    #If it's a list, it's already been patched up
    if sys.platform == 'win32' and isinstance(cmd.f2py, str) \
       and not is_win_exec(cmd.f2py):
        f2py = cmd.f2py
        if not os.path.isfile(f2py):  #Not a file, and didn't exec
            f2pydir = next((d for d in os.environ['PATH'].split(os.pathsep)
                            if os.path.isfile(os.path.join(d, f2py))), None)
            if f2pydir:  #Found the file, try it
                f2py = os.path.join(f2pydir, f2py)
                if not is_win_exec(f2py):  #Try the interpreter
                    if is_win_exec(sys.executable, f2py):
                        cmd.f2py = [sys.executable, f2py]
                    else:  #Nothing to be done
                        raise RuntimeError(
                            'f2py {0} found but not executable'.format(
                                cmd.f2py))
                else:  #Found and executable (unlikely, since would have worked)
                    cmd.f2py = [f2py]
            else:  #Couldn't find the file, just try the interpreter
                if is_win_exec(sys.executable, f2py):
                    cmd.f2py = [sys.executable, f2py]
                else:  #Nothing to be done
                    raise RuntimeError(
                        'f2py {0} not found and not executable'.format(
                            cmd.f2py))
        else:  #Not executable, but IS a file
            if is_win_exec(sys.executable, f2py):
                cmd.f2py = [sys.executable, f2py]
            else:  #Nothing to be done
                raise RuntimeError('f2py {0} exists but not executable'.format(
                    cmd.f2py))
    else:
        cmd.f2py = [cmd.f2py]
Example #24
0
    def validate_options(self):
        # Validate apr
        if not self.apr:
            self.apr = find_in_path('apr-1-config')

            if not self.apr:
                self.apr = find_in_path('apr-config')

            if self.apr:
                log.info("Found %s" % self.apr)
            else:
                raise DistutilsOptionError("Could not find apr-1-config or " \
                                           "apr-config.  Please rerun with the " \
                                           "--apr option.")

        if os.path.exists(self.apr):
            if os.path.isdir(self.apr):
                if os.path.exists(os.path.join(self.apr, "bin",
                                               "apr-1-config")):
                    self.apr_config = os.path.join(self.apr, "bin",
                                                   "apr-1-config")
                elif os.path.exists(os.path.join(self.apr, "bin",
                                                 "apr-config")):
                    self.apr_config = os.path.join(self.apr, "bin",
                                                   "apr-config")
                else:
                    self.apr_config = None
            elif os.path.basename(self.apr) in ("apr-1-config", "apr-config"):
                self.apr_config = self.apr
            else:
                self.apr_config = None
        else:
            self.apr_config = None

        if not self.apr_config:
            raise DistutilsOptionError("The --apr option is not valid.  It must " \
                                       "point to a valid apr installation or " \
                                       "to either the apr-1-config file or the " \
                                       "apr-config file")

        # Validate apr-util
        if not self.apr_util:
            self.apr_util = find_in_path('apu-1-config')

            if not self.apr_util:
                self.apr_util = find_in_path('apu-config')

            if self.apr_util:
                log.info("Found %s" % self.apr_util)
            else:
                raise DistutilsOptionError("Could not find apu-1-config or " \
                                           "apu-config.  Please rerun with the " \
                                           "--apr-util option.")

        if os.path.exists(self.apr_util):
            if os.path.isdir(self.apr_util):
                if os.path.exists(
                        os.path.join(self.apr_util, "bin", "apu-1-config")):
                    self.apu_config = os.path.join(self.apr_util, "bin",
                                                   "apu-1-config")
                elif os.path.exists(
                        os.path.join(self.apr_util, "bin", "apu-config")):
                    self.apu_config = os.path.join(self.apr_util, "bin",
                                                   "apu-config")
                else:
                    self.apu_config = None
            elif os.path.basename(self.apr_util) in ("apu-1-config",
                                                     "apu-config"):
                self.apu_config = self.apr_util
            else:
                self.apu_config = None
        else:
            self.apu_config = None

        if not self.apu_config:
            raise DistutilsOptionError("The --apr-util option is not valid.  It " \
                                       "must point to a valid apr-util " \
                                       "installation or to either the apu-1-config " \
                                       "file or the apu-config file")

        # Validate subversion
        if not self.subversion:
            self.subversion = find_in_path('svn')

            if self.subversion:
                log.info("Found %s" % self.subversion)
                # Get the installation root instead of path to 'svn'
                self.subversion = os.path.normpath(
                    os.path.join(self.subversion, "..", ".."))
            else:
                raise DistutilsOptionError("Could not find Subversion.  Please rerun " \
                                           "with the --subversion option.")

        # Validate svn-headers, if present
        if self.svn_headers:
            if os.path.isdir(self.svn_headers):
                if os.path.exists(
                        os.path.join(self.svn_headers, "svn_client.h")):
                    self.svn_include_dir = self.svn_headers
                elif os.path.exists(
                        os.path.join(self.svn_headers, "subversion-1",
                                     "svn_client.h")):
                    self.svn_include_dir = os.path.join(
                        self.svn_headers, "subversion-1")
                else:
                    self.svn_include_dir = None
            else:
                self.svn_include_dir = None
        elif os.path.exists(
                os.path.join(self.subversion, "include", "subversion-1")):
            self.svn_include_dir = "%s/include/subversion-1" % self.subversion
        else:
            self.svn_include_dir = None

        if not self.svn_include_dir:
            msg = ""

            if self.svn_headers:
                msg = "The --svn-headers options is not valid.  It must point to " \
                      "either a Subversion include directory or the Subversion " \
                      "include/subversion-1 directory."
            else:
                msg = "The --subversion option is not valid. " \
                      "Could not locate %s/include/" \
                      "subversion-1/svn_client.h" % self.subversion

            raise DistutilsOptionError(msg)

        # Validate ctypesgen
        if not self.ctypesgen:
            self.ctypesgen = find_in_path('ctypesgen.py')

            if self.ctypesgen:
                log.info("Found %s" % self.ctypesgen)
            else:
                raise DistutilsOptionError("Could not find ctypesgen.  Please rerun " \
                                           "with the --ctypesgen option.")

        if os.path.exists(self.ctypesgen):
            if os.path.isdir(self.ctypesgen):
                if os.path.exists(os.path.join(self.ctypesgen,
                                               "ctypesgen.py")):
                    self.ctypesgen_py = os.path.join(self.ctypesgen,
                                                     "ctypesgen.py")
                elif os.path.exists(
                        os.path.join(self.ctypesgen, "bin", "ctypesgen.py")):
                    self.ctypesgen_py = os.path.join(self.ctypesgen, "bin",
                                                     "ctypesgen.py")
                else:
                    self.ctypesgen_py = None
            elif os.path.basename(self.ctypesgen) == "ctypesgen.py":
                self.ctypesgen_py = self.ctypesgen
            else:
                self.ctypesgen_py = None
        else:
            self.ctypesgen_py = None

        if not self.ctypesgen_py:
            raise DistutilsOptionError("The --ctypesgen option is not valid.  It " \
                                       "must point to a valid ctypesgen " \
                                       "installation, a ctypesgen source tree or " \
                                       "to the ctypesgen.py script")
Example #25
0
 def finalize_options(self):
     if self.riak_conf is None:
         raise DistutilsOptionError("riak-conf option not set")
Example #26
0
    def _parse_config_files(self, filenames=None):  # noqa: C901
        """
        Adapted from distutils.dist.Distribution.parse_config_files,
        this method provides the same functionality in subtly-improved
        ways.
        """
        from configparser import ConfigParser

        # Ignore install directory options if we have a venv
        ignore_options = ([] if sys.prefix == sys.base_prefix else [
            'install-base',
            'install-platbase',
            'install-lib',
            'install-platlib',
            'install-purelib',
            'install-headers',
            'install-scripts',
            'install-data',
            'prefix',
            'exec-prefix',
            'home',
            'user',
            'root',
        ])

        ignore_options = frozenset(ignore_options)

        if filenames is None:
            filenames = self.find_config_files()

        if DEBUG:
            self.announce("Distribution.parse_config_files():")

        parser = ConfigParser()
        parser.optionxform = str
        for filename in filenames:
            with io.open(filename, encoding='utf-8') as reader:
                if DEBUG:
                    self.announce("  reading {filename}".format(**locals()))
                parser.read_file(reader)
            for section in parser.sections():
                options = parser.options(section)
                opt_dict = self.get_option_dict(section)

                for opt in options:
                    if opt == '__name__' or opt in ignore_options:
                        continue

                    val = parser.get(section, opt)
                    opt = self.warn_dash_deprecation(opt, section)
                    opt = self.make_option_lowercase(opt, section)
                    opt_dict[opt] = (filename, val)

            # Make the ConfigParser forget everything (so we retain
            # the original filenames that options come from)
            parser.__init__()

        if 'global' not in self.command_options:
            return

        # If there was a "global" section in the config file, use it
        # to set Distribution options.

        for (opt, (src, val)) in self.command_options['global'].items():
            alias = self.negative_opt.get(opt)
            if alias:
                val = not strtobool(val)
            elif opt in ('verbose', 'dry_run'):  # ugh!
                val = strtobool(val)

            try:
                setattr(self, alias or opt, val)
            except ValueError as e:
                raise DistutilsOptionError(e) from e
Example #27
0
	def finalize_options(self):
		if all([self.major, self.minor]):
			from distutils.errors import DistutilsOptionError
			raise DistutilsOptionError("--major/--minor are mutually exclusive")
		self.part = "major" if self.major else "minor" if self.minor else None
Example #28
0
 def run(self):
     if not self.distribution.dist_files:
         raise DistutilsOptionError(
             "No dist file created in earlier command")
     for command, pyversion, filename in self.distribution.dist_files:
         self.upload_file(command, pyversion, filename)
Example #29
0
 def _assert_local(filepath):
     if not filepath.startswith(os.getcwd()):
         raise DistutilsOptionError('`file:` directive can not access %s' %
                                    filepath)
Example #30
0
def setup_cfg_to_setup_kwargs(config):
    """Processes the setup.cfg options and converts them to arguments accepted
    by setuptools' setup() function.
    """

    kwargs = {}

    # Temporarily holds install_reqires 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 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>.*)$'
                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 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 = 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>.*)$'
        extras = config['extras']
        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)
            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