コード例 #1
0
def package_install_site(name='', user=False, plat_specific=False):
    """pip-inspired, distutils-based method for fetching the
    default install location (site-packages path).

    Returns virtual environment or system site-packages, unless
    `user=True` in which case returns user-site (typ. under `~/.local/
    on linux).

    If there's a distinction (on a particular system) between platform
    specific and pure python package locations, set `plat_specific=True`
    to retrieve the former.
    """

    dist = Distribution({'name': name})
    dist.parse_config_files()
    inst = dist.get_command_obj('install', create=True)
    # NOTE: specifying user=True will create user-site
    if user:
        inst.user = user
        inst.prefix = ""
    inst.finalize_options()

    # platform-specific site vs. purelib (platform-independent) site
    if plat_specific:
        loc = inst.install_platlib
    else:
        loc = inst.install_purelib

    # install_lib specified in setup.cfg has highest precedence
    if 'install_lib' in dist.get_option_dict('install'):
        loc = inst.install_lib

    return loc
コード例 #2
0
ファイル: setup.py プロジェクト: makkus/frkl-name
def get_extra_requires(add_all=True, add_all_dev=True):

    from distutils.dist import Distribution

    dist = Distribution()
    dist.parse_config_files()
    dist.parse_command_line()

    extras = {}
    extra_deps = dist.get_option_dict("options.extras_require")

    for extra_name, data in extra_deps.items():

        _, dep_string = data
        deps = []
        d = dep_string.split("\n")
        for line in d:
            if not line:
                continue
            deps.append(line)
        extras[extra_name] = deps

    if add_all:
        all = set()
        for e_n, deps in extras.items():
            if e_n not in ["docs", "develop", "testing"]:
                all.update(deps)
        extras["all"] = all

    # add tag `all` at the end
    if add_all_dev:
        extras["all-dev"] = set(vv for v in extras.values() for vv in v)

    return extras
コード例 #3
0
ファイル: base.py プロジェクト: pysmt/pysmt
def package_install_site(name='', user=False, plat_specific=False):
    """pip-inspired, distutils-based method for fetching the
    default install location (site-packages path).

    Returns virtual environment or system site-packages, unless
    `user=True` in which case returns user-site (typ. under `~/.local/
    on linux).

    If there's a distinction (on a particular system) between platform
    specific and pure python package locations, set `plat_specific=True`
    to retrieve the former.
    """

    dist = Distribution({'name': name})
    dist.parse_config_files()
    inst = dist.get_command_obj('install', create=True)
    # NOTE: specifying user=True will create user-site
    if user:
        inst.user = user
        inst.prefix = ""
    inst.finalize_options()

    # platform-specific site vs. purelib (platform-independent) site
    if plat_specific:
        loc = inst.install_platlib
    else:
        loc = inst.install_purelib

    # install_lib specified in setup.cfg has highest precedence
    if 'install_lib' in dist.get_option_dict('install'):
        loc = inst.install_lib

    return loc
コード例 #4
0
ファイル: locations.py プロジェクト: f3n1Xx/DjngPrjct2
def distutils_scheme(dist_name, user=False, home=None, root=None,
                     isolated=False, prefix=None):
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}

    if isolated:
        extra_dist_args = {"script_args": ["--no-user-cfg"]}
    else:
        extra_dist_args = {}
    dist_args = {'name': dist_name}
    dist_args.update(extra_dist_args)

    d = Distribution(dist_args)
    d.parse_config_files()
    i = d.get_command_obj('install', create=True)
    # NOTE: setting user or home has the sitex-effect of creating the home dir
    # or user base for installations during finalize_options()
    # ideally, we'd prefer a scheme class that has no sitex-effects.
    assert not (user and prefix), "user={0} prefix={1}".format(user, prefix)
    i.user = user or i.user
    if user:
        i.prefix = ""
    i.prefix = prefix or i.prefix
    i.home = home or i.home
    i.root = root or i.root
    i.finalize_options()
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, 'install_' + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
    if 'install_lib' in d.get_option_dict('install'):
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(
            sys.prefix,
            'include',
            'site',
            'python' + sys.version[:3],
            dist_name,
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(
                os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(
                root,
                path_no_drive[1:],
            )

    return scheme
コード例 #5
0
ファイル: frompip.py プロジェクト: rbtcollins/setuptools_shim
def distutils_scheme(dist_name, user=False, home=None, root=None,
                     isolated=False, prefix=None):
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}

    if isolated:
        extra_dist_args = {"script_args": ["--no-user-cfg"]}
    else:
        extra_dist_args = {}
    dist_args = {'name': dist_name}
    dist_args.update(extra_dist_args)

    d = Distribution(dist_args)
    d.parse_config_files()
    i = d.get_command_obj('install', create=True)
    # NOTE: setting user or home has the side-effect of creating the home dir
    # or user base for installations during finalize_options()
    # ideally, we'd prefer a scheme class that has no side-effects.
    assert not (user and prefix), "user={0} prefix={1}".format(user, prefix)
    i.user = user or i.user
    if user:
        i.prefix = ""
    i.prefix = prefix or i.prefix
    i.home = home or i.home
    i.root = root or i.root
    i.finalize_options()
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, 'install_' + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
    if 'install_lib' in d.get_option_dict('install'):
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(
            sys.prefix,
            'include',
            'site',
            'python' + sys.version[:3],
            dist_name,
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(
                os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(
                root,
                path_no_drive[1:],
            )

    return scheme
コード例 #6
0
def distutils_scheme(
    dist_name, user=False, home=None, root=None, isolated=False, prefix=None
):
    # type:(str, bool, str, str, bool, str) -> Dict[str, str]
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    dist_args = {"name": dist_name}  # type: Dict[str, Union[str, List[str]]]
    if isolated:
        dist_args["script_args"] = ["--no-user-cfg"]

    d = Distribution(dist_args)
    d.parse_config_files()
    obj = None  # type: Optional[DistutilsCommand]
    obj = d.get_command_obj("install", create=True)
    assert obj is not None
    i = cast(distutils_install_command, obj)
    # NOTE: setting user or home has the side-effect of creating the home dir
    # or user base for installations during finalize_options()
    # ideally, we'd prefer a scheme class that has no side-effects.
    assert not (user and prefix), "user={} prefix={}".format(user, prefix)
    assert not (home and prefix), "home={} prefix={}".format(home, prefix)
    i.user = user or i.user
    if user or home:
        i.prefix = ""
    i.prefix = prefix or i.prefix
    i.home = home or i.home
    i.root = root or i.root
    i.finalize_options()

    scheme = {}
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, "install_" + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
    if "install_lib" in d.get_option_dict("install"):
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme["headers"] = os.path.join(
            sys.prefix,
            "include",
            "site",
            "python{}".format(get_major_minor_version()),
            dist_name,
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(root, path_no_drive[1:],)

    return scheme
コード例 #7
0
def distutils_scheme(dist_name, user=False, home=None, root=None, isolated=False, prefix=None):
    # type:(str, bool, str, str, bool, str) -> dict
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}

    if isolated:
        extra_dist_args = {"script_args": ["--no-user-cfg"]}
    else:
        extra_dist_args = {}
    dist_args = {"name": dist_name}  # type: Dict[str, Union[str, List[str]]]
    dist_args.update(extra_dist_args)

    d = Distribution(dist_args)
    # Ignoring, typeshed issue reported python/typeshed/issues/2567
    d.parse_config_files()
    # NOTE: Ignoring type since mypy can't find attributes on 'Command'
    i = d.get_command_obj("install", create=True)  # type: Any
    assert i is not None
    # NOTE: setting user or home has the side-effect of creating the home dir
    # or user base for installations during finalize_options()
    # ideally, we'd prefer a scheme class that has no side-effects.
    assert not (user and prefix), "user={} prefix={}".format(user, prefix)
    i.user = user or i.user
    if user:
        i.prefix = ""
    i.prefix = prefix or i.prefix
    i.home = home or i.home
    i.root = root or i.root
    i.finalize_options()
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, "install_" + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config

    # Ignoring, typeshed issue reported python/typeshed/issues/2567
    if "install_lib" in d.get_option_dict("install"):  # type: ignore
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme["headers"] = os.path.join(
            sys.prefix, "include", "site", "python" + sys.version[:3], dist_name
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(root, path_no_drive[1:])

    return scheme
コード例 #8
0
def clean(options):
    orig_dir = os.getcwd()
    os.chdir(options.pybayes_dir)  # so that distutils can source setup.cfg if it exists

    dist = Distribution()
    dist.parse_config_files()
    if "prefix" in dist.get_option_dict("install"):
        prefix = dist.get_option_dict("install")["prefix"][1]  # get prefix out of parsed options
        install_dir = os.path.join(get_python_lib(False, False, prefix), "pybayes")
    else:
        install_dir = os.path.join(get_python_lib(False, False), "pybayes")
    # we don't know if we should use plat_specific or no (depends on previous PyBayes install) in
    # both above get_python_lib() calls

    if os.path.isdir(install_dir):
        print "Recursively deleting {0}".format(install_dir)
        shutil.rmtree(install_dir)

    os.chdir(orig_dir)
コード例 #9
0
def _read_artifactory_config_section():
    dist = Distribution()
    file_names = dist.find_config_files()
    dist.parse_config_files(filenames=file_names)
    artifactory_config_key = "artifactory"
    artifactory_opts = dist.get_option_dict(artifactory_config_key)

    if not artifactory_opts:
        raise DistutilsOptionError('Could not find a {} section in {}'.format(
            artifactory_config_key, file_names))

    return artifactory_opts
コード例 #10
0
ファイル: setup.py プロジェクト: johnstile/guiqwt
def is_msvc():
    """Detect if Microsoft Visual C++ compiler was chosen to build package"""
    # checking if mingw is the compiler
    # mingw32 compiler configured in %USERPROFILE%\pydistutils.cfg 
    # or distutils\distutils.cfg
    from distutils.dist import Distribution
    dist = Distribution()
    dist.parse_config_files()
    bld = dist.get_option_dict('build')
    if bld:
        comp = bld.get('compiler')
        if comp is not None and 'mingw32' in comp:
            return False  # mingw is the compiler
    return os.name == 'nt' and 'mingw' not in ''.join(sys.argv)
コード例 #11
0
def _read_artifactory_config_section():
    dist = Distribution()
    file_names = dist.find_config_files()
    dist.parse_config_files(filenames=file_names)
    artifactory_config_key = "artifactory"
    artifactory_opts = dist.get_option_dict(artifactory_config_key)

    if not artifactory_opts:
        raise DistutilsOptionError(
            'Could not find a {} section in {}'.format(
                artifactory_config_key,
                file_names))

    return artifactory_opts
コード例 #12
0
ファイル: setup.py プロジェクト: CARIBOuSystem/guiqwt
def is_msvc():
    """Detect if Microsoft Visual C++ compiler was chosen to build package"""
    # checking if mingw is the compiler
    # mingw32 compiler configured in %USERPROFILE%\pydistutils.cfg
    # or distutils\distutils.cfg
    from distutils.dist import Distribution
    dist = Distribution()
    dist.parse_config_files()
    bld = dist.get_option_dict('build')
    if bld:
        comp = bld.get('compiler')
        if comp is not None and 'mingw32' in comp:
            return False  # mingw is the compiler
    return os.name == 'nt' and 'mingw' not in ''.join(sys.argv)
コード例 #13
0
ファイル: setup_helpers.py プロジェクト: njmiller/astropy
def get_distutils_option(option, commands):
    """ Returns the value of the given distutils option.

    Parameters
    ----------
    option : str
        The name of the option

    commands : list of str
        The list of commands on which this option is available

    Returns
    -------
    val : str or None
        the value of the given distutils option. If the option is not set,
        returns None.
    """

    display_opts = get_distutils_display_options()
    args = [arg for arg in sys.argv[1:] if arg not in display_opts]

    # Pre-parse the Distutils command-line options and config files to
    # if the option is set.
    dist = Distribution({'script_name': os.path.basename(sys.argv[0]),
                         'script_args': args})
    dist.cmdclass.update(cmdclassd)

    try:
        dist.parse_config_files()
        dist.parse_command_line()
    except DistutilsError:
        # Let distutils handle this itself
        return None
    except AttributeError:
        # This seems to get thrown for ./setup.py --help
        return None

    for cmd in commands:
        if cmd in dist.commands:
            break
    else:
        return None

    for cmd in commands:
        cmd_opts = dist.get_option_dict(cmd)
        if option in cmd_opts:
            return cmd_opts[option][1]
    else:
        return None
コード例 #14
0
ファイル: hooks.py プロジェクト: jhunkeler/pywcs
def get_distutils_option(option, commands):
    """ Returns the value of the given distutils option.

    Parameters
    ----------
    option : str
        The name of the option

    commands : list of str
        The list of commands on which this option is available

    Returns
    -------
    val : str or None
        the value of the given distutils option. If the option is not set,
        returns None.
    """
    # Pre-parse the Distutils command-line options and config files to
    # if the option is set.
    dist = Distribution()
    try:
        dist.parse_config_files()
        dist.parse_command_line()
    except DistutilsError:
        # Let distutils handle this itself
        return None
    except AttributeError:
        # This seems to get thrown for ./setup.py --help
        return None

    for cmd in commands:
        if cmd in dist.commands:
            break
    else:
        return None

    for cmd in commands:
        cmd_opts = dist.get_option_dict(cmd)
        if option in cmd_opts:
            return cmd_opts[option][1]
    else:
        return None
コード例 #15
0
def get_distutils_option(option, commands):
    """ Returns the value of the given distutils option.

    Parameters
    ----------
    option : str
        The name of the option

    commands : list of str
        The list of commands on which this option is available

    Returns
    -------
    val : str or None
        the value of the given distutils option. If the option is not set,
        returns None.
    """
    # Pre-parse the Distutils command-line options and config files to
    # if the option is set.
    dist = Distribution()
    try:
        dist.parse_config_files()
        dist.parse_command_line()
    except DistutilsError:
        # Let distutils handle this itself
        return None
    except AttributeError:
        # This seems to get thrown for ./setup.py --help
        return None

    for cmd in commands:
        if cmd in dist.commands:
            break
    else:
        return None

    for cmd in commands:
        cmd_opts = dist.get_option_dict(cmd)
        if option in cmd_opts:
            return cmd_opts[option][1]
    else:
        return None
コード例 #16
0
ファイル: setup.py プロジェクト: mindw/guiqwt
                    "ERROR: unable to build documentation because Sphinx do not handle source path with non-ASCII characters. Please try to move the source package to another location (path with *only* ASCII characters).",
                    file=sys.stderr)
            sys.path.pop(0)

    cmdclass['build_doc'] = build_doc

CFLAGS = ["-Wall"]

# checking if mingw is the compiler
# mingw32 compiler configured in %USERPROFILE%\pydistutils.cfg
# or distutils\distutils.cfg
is_mingw = False
from distutils.dist import Distribution
_dist = Distribution()
_dist.parse_config_files()
_bld = _dist.get_option_dict('build')
if _bld and 'mingw32' in _bld.get('compiler'):
    is_mingw = True
if os.name == 'nt' and 'mingw' not in ''.join(sys.argv) and not is_mingw:
    CFLAGS.insert(0, "/EHsc")
for arg, compile_arg in (
    ("--sse2", "-msse2"),
    ("--sse3", "-msse3"),
):
    if arg in sys.argv:
        sys.argv.pop(sys.argv.index(arg))
        CFLAGS.insert(0, compile_arg)

# Compiling Cython modules to C source code: this is the only way I found to
# be able to build both Fortran and Cython extensions together
# (this could be changed now as there is no longer Fortran extensions here...)
コード例 #17
0
ファイル: setup.py プロジェクト: tue-robotics/catkin_tools
To enable tab completion, add the following to your '~/.bashrc':

  source {0}

----------------------------------------------------------------
""".format(
                os.path.join(self.install_data, 'etc/bash_completion.d',
                             'catkin_tools-completion.bash')))


from distutils.core import setup
from distutils.dist import Distribution
dist = Distribution()
dist.parse_config_files()
dist.parse_command_line()
prefix = dist.get_option_dict('install').get('prefix',
                                             ("default", sys.prefix))[1]

setup(
    name='catkin_tools',
    version='0.5.0',
    python_requires='>=3.5',
    packages=find_packages(exclude=['tests*', 'docs']),
    package_data={
        'catkin_tools': [
            'jobs/cmake/python.cmake',
            'jobs/cmake/python_install_dir.cmake',
            'notifications/resources/linux/catkin_icon.png',
            'notifications/resources/linux/catkin_icon_red.png',
            'verbs/catkin_shell_verbs.bash',
            'docs/examples',
        ] + osx_notification_resources
コード例 #18
0
ファイル: setup.py プロジェクト: mindw/guiqwt
            except UnicodeDecodeError:
                print("ERROR: unable to build documentation because Sphinx do not handle source path with non-ASCII characters. Please try to move the source package to another location (path with *only* ASCII characters).", file=sys.stderr)            
            sys.path.pop(0)

    cmdclass['build_doc'] = build_doc

CFLAGS = ["-Wall"]

# checking if mingw is the compiler
# mingw32 compiler configured in %USERPROFILE%\pydistutils.cfg 
# or distutils\distutils.cfg
is_mingw = False
from distutils.dist import Distribution
_dist = Distribution()
_dist.parse_config_files()
_bld = _dist.get_option_dict('build')
if _bld and 'mingw32' in _bld.get('compiler'):
    is_mingw =  True 
if os.name == 'nt' and 'mingw' not in ''.join(sys.argv) and not is_mingw:
    CFLAGS.insert(0, "/EHsc")
for arg, compile_arg in (("--sse2", "-msse2"),
                         ("--sse3", "-msse3"),):
    if arg in sys.argv:
        sys.argv.pop(sys.argv.index(arg))
        CFLAGS.insert(0, compile_arg)

# Compiling Cython modules to C source code: this is the only way I found to 
# be able to build both Fortran and Cython extensions together
# (this could be changed now as there is no longer Fortran extensions here...)
cythonize_all('src')
コード例 #19
0
ファイル: locations.py プロジェクト: Yankur/Web-application
                                    'python' + sys.version[:3],
                                    dist_name)

        if root is not None:
            scheme["headers"] = os.path.join(
                root,
                os.path.abspath(scheme["headers"])[1:],
=======
        scheme[key] = getattr(i, 'install_' + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
    if 'install_lib' in d.get_option_dict('install'):
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(
            sys.prefix,
            'include',
            'site',
            'python' + sys.version[:3],
            dist_name,
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(
                os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(
コード例 #20
0
ファイル: build_distutils.py プロジェクト: B-Rich/Bento
class DistutilsBuilder(object):
    def __init__(self, verbosity=1, build_base=None):
        from distutils.dist import Distribution
        from distutils import log

        log.set_verbosity(verbosity)

        self._dist = Distribution()
        self._compilers = {}
        self._cmds = {}

        if build_base:
            opt_dict = self._dist.get_option_dict("build")
            opt_dict["build_base"] = ("bento", build_base)
        build = self._dist.get_command_obj("build")
        self._build_base = build.build_base

        self.ext_bld_cmd = self._setup_build_ext()
        self.clib_bld_cmd = self._setup_build_clib()

    def _setup_build_ext(self):
        # Horrible hack to initialize build_ext: build_ext initialization is
        # partially done within the run function (!), and is bypassed if no
        # extensions is available. We fake it just enough so that run does all
        # the initialization without trying to actually build anything.
        build = self._dist.get_command_obj("build")
        bld_cmd = build.get_finalized_command("build_ext")
        bld_cmd.initialize_options()
        bld_cmd.finalize_options()
        old_build_extensions = bld_cmd.build_extensions
        try:
            bld_cmd.build_extensions = lambda: None
            bld_cmd.extensions = [None]
            bld_cmd.run()
        finally:
            bld_cmd.build_extensions = old_build_extensions

        return bld_cmd

    def _setup_build_clib(self):
        # Horrible hack to initialize build_ext: build_ext initialization is
        # partially done within the run function (!), and is bypassed if no
        # extensions is available. We fake it just enough so that run does all
        # the initialization without trying to actually build anything.
        build = self._dist.get_command_obj("build")
        bld_cmd = build.get_finalized_command("build_clib")
        bld_cmd.initialize_options()
        bld_cmd.finalize_options()
        old_build_libraries = bld_cmd.build_libraries
        try:
            bld_cmd.build_libraries = lambda ignored: None
            bld_cmd.libraries = [None]
            bld_cmd.run()
        finally:
            bld_cmd.build_libraries = old_build_libraries

        return bld_cmd

    def _extension_filename(self, name, cmd):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, cmd.get_ext_filename(b))

    def _compiled_library_filename(self, name, compiler):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, compiler.library_filename(b))

    def build_extension(self, extension):
        import distutils.errors

        dist_extension = toyext_to_distext(extension)

        bld_cmd = self.ext_bld_cmd
        try:
            bld_cmd.build_extension(dist_extension)

            base, filename = os.path.split(self._extension_filename(dist_extension.name, bld_cmd))
            fullname = os.path.join(bld_cmd.build_lib, base, filename)
            return [relpath(fullname, self._build_base)]
        except distutils.errors.DistutilsError:
            e = extract_exception()
            raise BuildError(str(e))

    def build_compiled_library(self, library):
        import distutils.errors

        bld_cmd = self.clib_bld_cmd
        compiler = bld_cmd.compiler
        base, filename = os.path.split(self._compiled_library_filename(library.name, compiler))
        old_build_clib = bld_cmd.build_clib
        if base:
            # workaround for a distutils issue: distutils put all C libraries
            # in the same directory, and we cannot control the output directory
            # from the name - we need to hack build_clib directory
            bld_cmd.build_clib = os.path.join(old_build_clib, base)
        try:
            try:
                # workaround for yet another bug in distutils: distutils f***s up when
                # building a static library if the target alread exists on at least mac
                # os x.
                target = os.path.join(old_build_clib, base, filename)
                try:
                    os.remove(target)
                except OSError:
                    e = extract_exception()
                    if e.errno != errno.ENOENT:
                        raise
                build_info = {"sources": library.sources, "include_dirs": library.include_dirs}
                bld_cmd.build_libraries([(library.name, build_info)])

                return [relpath(target, self._build_base)]
            except distutils.errors.DistutilsError:
                e = extract_exception()
                raise bento.errors.BuildError(str(e))
        finally:
            bld_cmd.build_clib = old_build_clib
コード例 #21
0
ファイル: build_distutils.py プロジェクト: pberkes/Bento
class DistutilsBuilder(object):
    def __init__(self, verbosity=1, build_base=None):
        from distutils.dist import Distribution
        from distutils import log

        log.set_verbosity(verbosity)

        self._dist = Distribution()
        self._compilers = {}
        self._cmds = {}

        if build_base:
            opt_dict = self._dist.get_option_dict("build")
            opt_dict["build_base"] = ("bento", build_base)
        build = self._dist.get_command_obj("build")
        self._build_base = build.build_base

    def _setup_cmd(self, cmd, t):
        from distutils.ccompiler import new_compiler
        from distutils.sysconfig import customize_compiler
        from distutils.command.build import build

        build = self._dist.get_command_obj("build")
        bld_cmd = build.get_finalized_command(cmd)

        compiler = new_compiler(compiler=bld_cmd.compiler,
                                dry_run=bld_cmd.dry_run,
                                force=bld_cmd.force)
        customize_compiler(compiler)
        return bld_cmd, compiler

    def _setup_clib(self):
        from distutils.command.build_clib import build_clib
        return self._setup_cmd("build_clib", "compiled_libraries")

    def _setup_ext(self):
        from distutils.command.build_ext import build_ext
        return self._setup_cmd("build_ext", "extensions")

    def _extension_filename(self, name, cmd):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, cmd.get_ext_filename(b))

    def _compiled_library_filename(self, name, compiler):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, compiler.library_filename(b))

    def build_extension(self, extension):
        import distutils.errors

        dist = self._dist
        dist.ext_modules = [toyext_to_distext(extension)]

        bld_cmd, compiler = self._setup_ext()
        try:
            bld_cmd.run()

            base, filename = os.path.split(self._extension_filename(extension.name, bld_cmd))
            fullname = os.path.join(bld_cmd.build_lib, base, filename)
            return [relpath(fullname, self._build_base)]
        except distutils.errors.DistutilsError:
            e = extract_exception()
            raise BuildError(str(e))

    def build_compiled_library(self, library):
        import distutils.errors

        dist = self._dist
        dist.libraries = [to_dist_compiled_library(library)]

        bld_cmd, compiler = self._setup_clib()
        base, filename = os.path.split(self._compiled_library_filename(library.name, compiler))
        old_build_clib = bld_cmd.build_clib
        if base:
            # workaround for a distutils issue: distutils put all C libraries
            # in the same directory, and we cannot control the output directory
            # from the name - we need to hack build_clib directory
            bld_cmd.build_clib = os.path.join(old_build_clib, base)
        try:
            try:
                # workaround for yet another bug in distutils: distutils f***s up when
                # building a static library if the target alread exists on at least mac
                # os x.
                target = os.path.join(old_build_clib, base, filename)
                try:
                    os.remove(target)
                except OSError:
                    e = extract_exception()
                    if e.errno != errno.ENOENT:
                        raise
                bld_cmd.run()

                return [relpath(target, self._build_base)]
            except distutils.errors.DistutilsError:
                e = extract_exception()
                raise BuildError(str(e))
        finally:
            bld_cmd.build_clib = old_build_clib
コード例 #22
0
ファイル: config.py プロジェクト: bingbu/kimchi
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#

import os, os.path
from glob import iglob
import sys
from distutils.dist import Distribution
import platform

d = Distribution()
d.parse_config_files()
opt = d.get_option_dict('install').get('prefix')
PREFIX = opt[1] if opt is not None else sys.prefix


def get_prefix():
    if __file__[0] == '/':
        base = os.path.dirname(__file__)
    else:
        base = os.path.dirname('./%s' % __file__)

    if os.access('%s/../../src/burnet/config.py' % base, os.F_OK):
        return '%s/../..' % base
    else:
        return '%s/share/burnet' % PREFIX

def get_default_log_dir():
コード例 #23
0
ファイル: _distutils.py プロジェクト: cjc7373/pip
def distutils_scheme(
    dist_name: str,
    user: bool = False,
    home: str = None,
    root: str = None,
    isolated: bool = False,
    prefix: str = None,
    *,
    ignore_config_files: bool = False,
) -> Dict[str, str]:
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    dist_args: Dict[str, Union[str, List[str]]] = {"name": dist_name}
    if isolated:
        dist_args["script_args"] = ["--no-user-cfg"]

    d = Distribution(dist_args)
    if not ignore_config_files:
        try:
            d.parse_config_files()
        except UnicodeDecodeError:
            # Typeshed does not include find_config_files() for some reason.
            paths = d.find_config_files()  # type: ignore
            logger.warning(
                "Ignore distutils configs in %s due to encoding errors.",
                ", ".join(os.path.basename(p) for p in paths),
            )
    obj: Optional[DistutilsCommand] = None
    obj = d.get_command_obj("install", create=True)
    assert obj is not None
    i = cast(distutils_install_command, obj)
    # NOTE: setting user or home has the side-effect of creating the home dir
    # or user base for installations during finalize_options()
    # ideally, we'd prefer a scheme class that has no side-effects.
    assert not (user and prefix), f"user={user} prefix={prefix}"
    assert not (home and prefix), f"home={home} prefix={prefix}"
    i.user = user or i.user
    if user or home:
        i.prefix = ""
    i.prefix = prefix or i.prefix
    i.home = home or i.home
    i.root = root or i.root
    i.finalize_options()

    scheme = {}
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, "install_" + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
    if "install_lib" in d.get_option_dict("install"):
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme["headers"] = os.path.join(
            i.prefix,
            "include",
            "site",
            f"python{get_major_minor_version()}",
            dist_name,
        )

        if root is not None:
            path_no_drive = os.path.splitdrive(
                os.path.abspath(scheme["headers"]))[1]
            scheme["headers"] = os.path.join(
                root,
                path_no_drive[1:],
            )

    return scheme
コード例 #24
0
    def customize(self, dist=None):
        """ Customize Fortran compiler.

        This method gets Fortran compiler specific information from
        (i) class definition, (ii) environment, (iii) distutils config
        files, and (iv) command line.

        This method should be always called after constructing a
        compiler instance. But not in __init__ because Distribution
        instance is needed for (iii) and (iv).
        """
        log.info('customize %s' % (self.__class__.__name__))
        from distutils.dist import Distribution
        if dist is None:
            # These hooks are for testing only!
            dist = Distribution()
            dist.script_name = os.path.basename(sys.argv[0])
            dist.script_args = ['config_fc'] + sys.argv[1:]
            dist.cmdclass['config_fc'] = config_fc
            dist.parse_config_files()
            dist.parse_command_line()
        if isinstance(dist,Distribution):
            conf = dist.get_option_dict('config_fc')
        else:
            assert isinstance(dist,dict)
            conf = dist
        noopt = conf.get('noopt',[None,0])[1]
        if 0: # change to `if 1:` when making release.
            # Don't use architecture dependent compiler flags:
            noarch = 1
        else:
            noarch = conf.get('noarch',[None,noopt])[1]
        debug = conf.get('debug',[None,0])[1]

        self.find_executables()

        f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))
        f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))
        # Temporarily setting f77,f90 compilers so that
        # version_cmd can use their executables.
        if f77:
            self.set_executables(compiler_f77=[f77])
        if f90:
            self.set_executables(compiler_f90=[f90])

        # Must set version_cmd before others as self.get_flags*
        # methods may call self.get_version.
        vers_cmd = self.__get_cmd(self.get_version_cmd)
        if vers_cmd:
            vflags = self.__get_flags(self.get_flags_version)
            self.set_executables(version_cmd=[vers_cmd]+vflags)

        if f77:
            f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',
                                   (conf,'f77flags'))
        if f90:
            f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',
                                       (conf,'f90flags'))
            freeflags = self.__get_flags(self.get_flags_free,'FREEFLAGS',
                                         (conf,'freeflags'))
        # XXX Assuming that free format is default for f90 compiler.
        fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))
        if fix:
            fixflags = self.__get_flags(self.get_flags_fix) + f90flags

        oflags,aflags,dflags = [],[],[]
        if not noopt:
            oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))
            if f77 and self.get_flags_opt is not self.get_flags_opt_f77:
                f77flags += self.__get_flags(self.get_flags_opt_f77)
            if f90 and self.get_flags_opt is not self.get_flags_opt_f90:
                f90flags += self.__get_flags(self.get_flags_opt_f90)
            if fix and self.get_flags_opt is not self.get_flags_opt_f90:
                fixflags += self.__get_flags(self.get_flags_opt_f90)
            if not noarch:
                aflags = self.__get_flags(self.get_flags_arch,'FARCH',
                                          (conf,'arch'))
                if f77 and self.get_flags_arch is not self.get_flags_arch_f77:
                    f77flags += self.__get_flags(self.get_flags_arch_f77)
                if f90 and self.get_flags_arch is not self.get_flags_arch_f90:
                    f90flags += self.__get_flags(self.get_flags_arch_f90)
                if fix and self.get_flags_arch is not self.get_flags_arch_f90:
                    fixflags += self.__get_flags(self.get_flags_arch_f90)
        if debug:
            dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')
            if f77  and self.get_flags_debug is not self.get_flags_debug_f77:
                f77flags += self.__get_flags(self.get_flags_debug_f77)
            if f90  and self.get_flags_debug is not self.get_flags_debug_f90:
                f90flags += self.__get_flags(self.get_flags_debug_f90)
            if fix and self.get_flags_debug is not self.get_flags_debug_f90:
                fixflags += self.__get_flags(self.get_flags_debug_f90)

        fflags = self.__get_flags(self.get_flags,'FFLAGS') \
                 + dflags + oflags + aflags

        if f77:
            self.set_executables(compiler_f77=[f77]+f77flags+fflags)
        if f90:
            self.set_executables(compiler_f90=[f90]+freeflags+f90flags+fflags)
        if fix:
            self.set_executables(compiler_fix=[fix]+fixflags+fflags)
        #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS
        linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')
        if linker_so:
            linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')
            if sys.platform.startswith('aix'):
                python_lib = get_python_lib(standard_lib=1)
                ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
                python_exp = os.path.join(python_lib, 'config', 'python.exp')
                linker_so = [ld_so_aix, linker_so, '-bI:'+python_exp]
            else:
                linker_so = [linker_so]
            self.set_executables(linker_so=linker_so+linker_so_flags)

        linker_exe = self.__get_cmd(self.get_linker_exe,'LD')
        if linker_exe:
            linker_exe_flags = self.__get_flags(self.get_flags_linker_exe,'LDFLAGS')
            self.set_executables(linker_exe=[linker_exe]+linker_exe_flags)
        ar = self.__get_cmd('archiver','AR')
        if ar:
            arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')
            self.set_executables(archiver=[ar]+arflags)

        ranlib = self.__get_cmd('ranlib','RANLIB')
        if ranlib:
            self.set_executables(ranlib=[ranlib])

        self.set_library_dirs(self.get_library_dirs())
        self.set_libraries(self.get_libraries())


        verbose = conf.get('verbose',[None,0])[1]
        if verbose:
            self.dump_properties()
        return
コード例 #25
0
ファイル: setup.py プロジェクト: 1313e/rubiks-cube-scripts
# %% IMPORTS
# Built-in imports
from codecs import open
from os import path
import re

# Package imports
from Cython.Build import cythonize
from distutils.dist import Distribution
from setuptools import Extension, find_packages, setup

# %% SETUP DEFINITION
# Obtain library information from setup.cfg
dist = Distribution()
dist.parse_config_files()
libs_cfg = {key: val[1] for key, val in dist.get_option_dict('libs').items()}

# Obtain absolute paths to cube_dir and pumas_dir
cube_dir = path.abspath(libs_cfg['cube_dir'])
pumas_dir = path.abspath(libs_cfg['pumas_dir'])

# Get the requirements list
with open('requirements.txt', 'r') as f:
    requirements = f.read().splitlines()

# Read the __version__.py file
with open('pumas_cube/__version__.py', 'r') as f:
    vf = f.read()

# Obtain version from read-in __version__.py file
version = re.search(r"^_*version_* = ['\"]([^'\"]*)['\"]", vf, re.M).group(1)
コード例 #26
0
class DistutilsBuilder(object):
    def __init__(self, verbosity=1, build_base=None):
        from distutils.dist import Distribution
        from distutils import log

        log.set_verbosity(verbosity)

        self._dist = Distribution()
        self._compilers = {}
        self._cmds = {}

        if build_base:
            opt_dict = self._dist.get_option_dict("build")
            opt_dict["build_base"] = ("bento", build_base)
        build = self._dist.get_command_obj("build")
        self._build_base = build.build_base

        self.ext_bld_cmd = self._setup_build_ext()
        self.clib_bld_cmd = self._setup_build_clib()

    def _setup_build_ext(self):
        # Horrible hack to initialize build_ext: build_ext initialization is
        # partially done within the run function (!), and is bypassed if no
        # extensions is available. We fake it just enough so that run does all
        # the initialization without trying to actually build anything.
        build = self._dist.get_command_obj("build")
        bld_cmd = build.get_finalized_command("build_ext")
        bld_cmd.initialize_options()
        bld_cmd.finalize_options()
        old_build_extensions = bld_cmd.build_extensions
        try:
            bld_cmd.build_extensions = lambda: None
            bld_cmd.extensions = [None]
            bld_cmd.run()
        finally:
            bld_cmd.build_extensions = old_build_extensions

        return bld_cmd

    def _setup_build_clib(self):
        # Horrible hack to initialize build_ext: build_ext initialization is
        # partially done within the run function (!), and is bypassed if no
        # extensions is available. We fake it just enough so that run does all
        # the initialization without trying to actually build anything.
        build = self._dist.get_command_obj("build")
        bld_cmd = build.get_finalized_command("build_clib")
        bld_cmd.initialize_options()
        bld_cmd.finalize_options()
        old_build_libraries = bld_cmd.build_libraries
        try:
            bld_cmd.build_libraries = lambda ignored: None
            bld_cmd.libraries = [None]
            bld_cmd.run()
        finally:
            bld_cmd.build_libraries = old_build_libraries

        return bld_cmd

    def _extension_filename(self, name, cmd):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, cmd.get_ext_filename(b))

    def _compiled_library_filename(self, name, compiler):
        m = module_to_path(name)
        d, b = os.path.split(m)
        return os.path.join(d, compiler.library_filename(b))

    def build_extension(self, extension):
        import distutils.errors

        dist_extension = toyext_to_distext(extension)

        bld_cmd = self.ext_bld_cmd
        try:
            bld_cmd.build_extension(dist_extension)

            base, filename = os.path.split(self._extension_filename(dist_extension.name, bld_cmd))
            fullname = os.path.join(bld_cmd.build_lib, base, filename)
            return [relpath(fullname, self._build_base)]
        except distutils.errors.DistutilsError:
            e = extract_exception()
            raise BuildError(str(e))

    def build_compiled_library(self, library):
        import distutils.errors

        bld_cmd = self.clib_bld_cmd
        compiler = bld_cmd.compiler
        base, filename = os.path.split(self._compiled_library_filename(library.name, compiler))
        old_build_clib = bld_cmd.build_clib
        if base:
            # workaround for a distutils issue: distutils put all C libraries
            # in the same directory, and we cannot control the output directory
            # from the name - we need to hack build_clib directory
            bld_cmd.build_clib = os.path.join(old_build_clib, base)
        try:
            try:
                # workaround for yet another bug in distutils: distutils f***s up when
                # building a static library if the target alread exists on at least mac
                # os x.
                target = os.path.join(old_build_clib, base, filename)
                try:
                    os.remove(target)
                except OSError:
                    e = extract_exception()
                    if e.errno != errno.ENOENT:
                        raise
                build_info = {"sources": library.sources,
                        "include_dirs": library.include_dirs}
                bld_cmd.build_libraries([(library.name, build_info)])

                return [relpath(target, self._build_base)]
            except distutils.errors.DistutilsError:
                e = extract_exception()
                raise bento.errors.BuildError(str(e))
        finally:
            bld_cmd.build_clib = old_build_clib
コード例 #27
0
=======

    scheme = {}
>>>>>>> e585743114c1741ec20dc76010f96171f3516589
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, 'install_' + key)

    # install_lib specified in setup.cfg should install *everything*
    # into there (i.e. it takes precedence over both purelib and
    # platlib).  Note, i.install_lib is *always* set after
    # finalize_options(); we only want to override here if the user
    # has explicitly requested it hence going back to the config
<<<<<<< HEAD

    # Ignoring, typeshed issue reported python/typeshed/issues/2567
    if 'install_lib' in d.get_option_dict('install'):  # type: ignore
=======
    if 'install_lib' in d.get_option_dict('install'):
>>>>>>> e585743114c1741ec20dc76010f96171f3516589
        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(
            sys.prefix,
            'include',
            'site',
<<<<<<< HEAD
            'python' + sys.version[:3],
=======
            'python{}'.format(get_major_minor_version()),
>>>>>>> e585743114c1741ec20dc76010f96171f3516589