当前位置: 首页>>代码示例>>Python>>正文


Python sysconfig.is_python_build函数代码示例

本文整理汇总了Python中sysconfig.is_python_build函数的典型用法代码示例。如果您正苦于以下问题:Python is_python_build函数的具体用法?Python is_python_build怎么用?Python is_python_build使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_python_build函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_python

    def setup_python(self, context):
        """
        Set up a Python executable in the environment.

        :param context: The information for the environment creation request
                        being processed.
        """
        binpath = context.bin_path
        path = context.env_exe
        copier = self.symlink_or_copy
        dirname = context.python_dir
        if os.name != 'nt':
            copier(context.executable, path)
            if not os.path.islink(path):
                os.chmod(path, 0o755)
            for suffix in ('python', 'python3'):
                path = os.path.join(binpath, suffix)
                if not os.path.exists(path):
                    # Issue 18807: make copies if
                    # symlinks are not wanted
                    copier(context.env_exe, path, relative_symlinks_ok=True)
                    if not os.path.islink(path):
                        os.chmod(path, 0o755)
        else:
            if self.symlinks:
                # For symlinking, we need a complete copy of the root directory
                # If symlinks fail, you'll get unnecessary copies of files, but
                # we assume that if you've opted into symlinks on Windows then
                # you know what you're doing.
                suffixes = [
                    f for f in os.listdir(dirname) if
                    os.path.normcase(os.path.splitext(f)[1]) in ('.exe', '.dll')
                ]
                if sysconfig.is_python_build(True):
                    suffixes = [
                        f for f in suffixes if
                        os.path.normcase(f).startswith(('python', 'vcruntime'))
                    ]
            else:
                suffixes = ['python.exe', 'python_d.exe', 'pythonw.exe',
                            'pythonw_d.exe']

            for suffix in suffixes:
                src = os.path.join(dirname, suffix)
                if os.path.exists(src):
                    copier(src, os.path.join(binpath, suffix))

            if sysconfig.is_python_build(True):
                # copy init.tcl
                for root, dirs, files in os.walk(context.python_dir):
                    if 'init.tcl' in files:
                        tcldir = os.path.basename(root)
                        tcldir = os.path.join(context.env_dir, 'Lib', tcldir)
                        if not os.path.exists(tcldir):
                            os.makedirs(tcldir)
                        src = os.path.join(root, 'init.tcl')
                        dst = os.path.join(tcldir, 'init.tcl')
                        shutil.copyfile(src, dst)
                        break
开发者ID:Eyepea,项目名称:cpython,代码行数:59,代码来源:__init__.py

示例2: create_test

    def create_test(self, name=None, code=None):
        if not name:
            name = 'noop%s' % BaseTestCase.TEST_UNIQUE_ID
            BaseTestCase.TEST_UNIQUE_ID += 1

        if code is None:
            code = textwrap.dedent("""
                    import unittest

                    class Tests(unittest.TestCase):
                        def test_empty_test(self):
                            pass
                """)

        # test_regrtest cannot be run twice in parallel because
        # of setUp() and create_test()
        name = self.TESTNAME_PREFIX + name
        path = os.path.join(self.tmptestdir, name + '.py')

        self.addCleanup(support.unlink, path)
        # Use 'x' mode to ensure that we do not override existing tests
        try:
            with open(path, 'x', encoding='utf-8') as fp:
                fp.write(code)
        except PermissionError as exc:
            if not sysconfig.is_python_build():
                self.skipTest("cannot write %s: %s" % (path, exc))
            raise
        return name
开发者ID:grantjenks,项目名称:cpython,代码行数:29,代码来源:test_regrtest.py

示例3: symlink_or_copy

    def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
        """
        Try symlinking a file, and if that fails, fall back to copying.
        """
        force_copy = not self.symlinks
        if not force_copy:
            try:
                if not os.path.islink(dst): # can't link to itself!
                    if relative_symlinks_ok:
                        assert os.path.dirname(src) == os.path.dirname(dst)
                        os.symlink(os.path.basename(src), dst)
                    else:
                        os.symlink(src, dst)
            except Exception:   # may need to use a more specific exception
                logger.warning('Unable to symlink %r to %r', src, dst)
                force_copy = True
        if force_copy:
            if os.name == 'nt':
                # On Windows, we rewrite symlinks to our base python.exe into
                # copies of venvlauncher.exe
                basename, ext = os.path.splitext(os.path.basename(src))
                if basename.endswith('_d'):
                    ext = '_d' + ext
                    basename = basename[:-2]
                if sysconfig.is_python_build(True):
                    if basename == 'python':
                        basename = 'venvlauncher'
                    elif basename == 'pythonw':
                        basename = 'venvwlauncher'
                    scripts = os.path.dirname(src)
                else:
                    scripts = os.path.join(os.path.dirname(__file__), "scripts", "nt")
                src = os.path.join(scripts, basename + ext)

            shutil.copyfile(src, dst)
开发者ID:Eyepea,项目名称:cpython,代码行数:35,代码来源:__init__.py

示例4: test_symlink

    def test_symlink(self):
        # On Windows, the EXE needs to know where pythonXY.dll is at so we have
        # to add the directory to the path.
        env = None
        if sys.platform == "win32":
            env = {k.upper(): os.environ[k] for k in os.environ}
            env["PATH"] = "{};{}".format(
                os.path.dirname(sys.executable), env.get("PATH", ""))
            # Requires PYTHONHOME as well since we locate stdlib from the
            # EXE path and not the DLL path (which should be fixed)
            env["PYTHONHOME"] = os.path.dirname(sys.executable)
            if sysconfig.is_python_build(True):
                env["PYTHONPATH"] = os.path.dirname(os.__file__)

        # Issue 7880
        def get(python, env=None):
            cmd = [python, '-c',
                   'import sysconfig; print(sysconfig.get_platform())']
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE, env=env)
            out, err = p.communicate()
            if p.returncode:
                print((out, err))
                self.fail('Non-zero return code {0} (0x{0:08X})'
                            .format(p.returncode))
            return out, err
        real = os.path.realpath(sys.executable)
        link = os.path.abspath(TESTFN)
        os.symlink(real, link)
        try:
            self.assertEqual(get(real), get(link, env))
        finally:
            unlink(link)
开发者ID:Eyepea,项目名称:cpython,代码行数:33,代码来源:test_sysconfig.py

示例5: main

def main():
    global ENABLE_USER_SITE

    abs__file__()
    known_paths = removeduppaths()
    from sysconfig import is_python_build
    if is_python_build():
        from _sysconfigdata import build_time_vars
        sys.path.append(os.path.join(build_time_vars['abs_builddir'], 'Modules'))
    if ENABLE_USER_SITE is None:
        ENABLE_USER_SITE = check_enableusersite()
    known_paths = addusersitepackages(known_paths)
    known_paths = addsitepackages(known_paths)
    if sys.platform == 'os2emx':
        setBEGINLIBPATH()
    setquit()
    setcopyright()
    sethelper()
    aliasmbcs()
    setencoding()
    execsitecustomize()
    if ENABLE_USER_SITE:
        execusercustomize()
    # Remove sys.setdefaultencoding() so that users cannot change the
    # encoding after initialization.  The test for presence is needed when
    # this module is run as a script, because this code is executed twice.
    if hasattr(sys, "setdefaultencoding"):
        del sys.setdefaultencoding
开发者ID:pigaov10,项目名称:plone4.3,代码行数:28,代码来源:site.py

示例6: test_architecture_via_symlink

    def test_architecture_via_symlink(self): # issue3762
        # On Windows, the EXE needs to know where pythonXY.dll and *.pyd is at
        # so we add the directory to the path, PYTHONHOME and PYTHONPATH.
        env = None
        if sys.platform == "win32":
            env = {k.upper(): os.environ[k] for k in os.environ}
            env["PATH"] = "{};{}".format(
                os.path.dirname(sys.executable), env.get("PATH", ""))
            env["PYTHONHOME"] = os.path.dirname(sys.executable)
            if sysconfig.is_python_build(True):
                env["PYTHONPATH"] = os.path.dirname(os.__file__)

        def get(python, env=None):
            cmd = [python, '-c',
                'import platform; print(platform.architecture())']
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE, env=env)
            r = p.communicate()
            if p.returncode:
                print(repr(r[0]))
                print(repr(r[1]), file=sys.stderr)
                self.fail('unexpected return code: {0} (0x{0:08X})'
                          .format(p.returncode))
            return r

        real = os.path.realpath(sys.executable)
        link = os.path.abspath(support.TESTFN)
        os.symlink(real, link)
        try:
            self.assertEqual(get(real), get(link, env=env))
        finally:
            os.remove(link)
开发者ID:Eyepea,项目名称:cpython,代码行数:32,代码来源:test_platform.py

示例7: _get_xxmodule_path

def _get_xxmodule_path():
    if sysconfig.is_python_build():
        srcdir = sysconfig.get_config_var('projectbase')
        path = os.path.join(os.getcwd(), srcdir, 'Modules', 'xxmodule.c')
    else:
        path = os.path.join(os.path.dirname(__file__), 'xxmodule.c')
    if os.path.exists(path):
        return path
开发者ID:Naddiseo,项目名称:cpython,代码行数:8,代码来源:support.py

示例8: setup_python

    def setup_python(self, context):
        """
        Set up a Python executable in the environment.

        :param context: The information for the environment creation request
                        being processed.
        """
        binpath = context.bin_path
        path = context.env_exe
        copier = self.symlink_or_copy
        copier(context.executable, path)
        dirname = context.python_dir
        if os.name != 'nt':
            if not os.path.islink(path):
                os.chmod(path, 0o755)
            for suffix in ('python', 'python3'):
                path = os.path.join(binpath, suffix)
                if not os.path.exists(path):
                    # Issue 18807: make copies if
                    # symlinks are not wanted
                    copier(context.env_exe, path, relative_symlinks_ok=True)
                    if not os.path.islink(path):
                        os.chmod(path, 0o755)
        else:
            # See bpo-34011. When using a proper install, we should only need to
            # copy the top-level of DLLs.
            include = self.include_binary
            files = [f for f in os.listdir(dirname) if include(f)]
            for f in files:
                src = os.path.join(dirname, f)
                dst = os.path.join(binpath, f)
                if dst != context.env_exe:  # already done, above
                    copier(src, dst)

            # When creating from a build directory, we continue to copy all files.
            if sysconfig.is_python_build(True):
                subdir = 'DLLs'
                dirname = os.path.join(dirname, subdir)
                if os.path.isdir(dirname):
                    files = [f for f in os.listdir(dirname) if include(f)]
                    for f in files:
                        src = os.path.join(dirname, f)
                        dst = os.path.join(binpath, f)
                        copier(src, dst)
                # copy init.tcl over
                for root, dirs, files in os.walk(context.python_dir):
                    if 'init.tcl' in files:
                        tcldir = os.path.basename(root)
                        tcldir = os.path.join(context.env_dir, 'Lib', tcldir)
                        if not os.path.exists(tcldir):
                            os.makedirs(tcldir)
                        src = os.path.join(root, 'init.tcl')
                        dst = os.path.join(tcldir, 'init.tcl')
                        shutil.copyfile(src, dst)
                        break
开发者ID:adrian17,项目名称:cpython,代码行数:55,代码来源:__init__.py

示例9: install

def install(project):
    """Installs a project.

    Returns True on success, False on failure
    """
    if is_python_build():
        # Python would try to install into the site-packages directory under
        # $PREFIX, but when running from an uninstalled code checkout we don't
        # want to create directories under the installation root
        message = ('installing third-party projects from an uninstalled '
                   'Python is not supported')
        logger.error(message)
        return False

    logger.info('Checking the installation location...')
    purelib_path = get_path('purelib')

    # trying to write a file there
    try:
        with tempfile.NamedTemporaryFile(suffix=project,
                                         dir=purelib_path) as testfile:
            testfile.write(b'test')
    except OSError:
        # FIXME this should check the errno, or be removed altogether (race
        # condition: the directory permissions could be changed between here
        # and the actual install)
        logger.info('Unable to write in "%s". Do you have the permissions ?'
                    % purelib_path)
        return False

    logger.info('Getting information about %r...', project)
    try:
        info = get_infos(project)
    except InstallationException:
        logger.info('Cound not find %r', project)
        return False

    if info['install'] == []:
        logger.info('Nothing to install')
        return False

    install_path = get_config_var('base')
    try:
        install_from_infos(install_path,
                           info['install'], info['remove'], info['conflict'])

    except InstallationConflict as e:
        if logger.isEnabledFor(logging.INFO):
            projects = ('%r %s' % (p.name, p.version) for p in e.args[0])
            logger.info('%r conflicts with %s', project, ','.join(projects))

    return True
开发者ID:MrMalina,项目名称:Source.Python,代码行数:52,代码来源:install.py

示例10: setup_python

    def setup_python(self, context):
        """
        Set up a Python executable in the environment.

        :param context: The information for the environment creation request
                        being processed.
        """
        binpath = context.bin_path
        path = context.env_exe
        copier = self.symlink_or_copy
        dirname = context.python_dir
        if os.name != 'nt':
            copier(context.executable, path)
            if not os.path.islink(path):
                os.chmod(path, 0o755)
            for suffix in ('python', 'python3'):
                path = os.path.join(binpath, suffix)
                if not os.path.exists(path):
                    # Issue 18807: make copies if
                    # symlinks are not wanted
                    copier(context.env_exe, path, relative_symlinks_ok=True)
                    if not os.path.islink(path):
                        os.chmod(path, 0o755)
        else:
            # For normal cases, the venvlauncher will be copied from
            # our scripts folder. For builds, we need to copy it
            # manually.
            if sysconfig.is_python_build(True):
                suffix = '.exe'
                if context.python_exe.lower().endswith('_d.exe'):
                    suffix = '_d.exe'

                src = os.path.join(dirname, "venvlauncher" + suffix)
                dst = os.path.join(binpath, context.python_exe)
                copier(src, dst)

                src = os.path.join(dirname, "venvwlauncher" + suffix)
                dst = os.path.join(binpath, "pythonw" + suffix)
                copier(src, dst)

                # copy init.tcl over
                for root, dirs, files in os.walk(context.python_dir):
                    if 'init.tcl' in files:
                        tcldir = os.path.basename(root)
                        tcldir = os.path.join(context.env_dir, 'Lib', tcldir)
                        if not os.path.exists(tcldir):
                            os.makedirs(tcldir)
                        src = os.path.join(root, 'init.tcl')
                        dst = os.path.join(tcldir, 'init.tcl')
                        shutil.copyfile(src, dst)
                        break
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:51,代码来源:__init__.py

示例11: main_in_temp_cwd

def main_in_temp_cwd():
    """Run main() in a temporary working directory."""
    if sysconfig.is_python_build():
        try:
            os.mkdir(TEMPDIR)
        except FileExistsError:
            pass

    # Define a writable temp dir that will be used as cwd while running
    # the tests. The name of the dir includes the pid to allow parallel
    # testing (see the -j option).
    test_cwd = 'test_python_{}'.format(os.getpid())
    test_cwd = os.path.join(TEMPDIR, test_cwd)

    # Run the tests in a context manager that temporarily changes the CWD to a
    # temporary and writable directory.  If it's not possible to create or
    # change the CWD, the original CWD will be used.  The original CWD is
    # available from support.SAVEDCWD.
    with support.temp_cwd(test_cwd, quiet=True):
        main()
开发者ID:esc,项目名称:cpython,代码行数:20,代码来源:main.py

示例12: create_test

    def create_test(self, name=None, code=""):
        if not name:
            name = "noop%s" % BaseTestCase.TEST_UNIQUE_ID
            BaseTestCase.TEST_UNIQUE_ID += 1

        # test_regrtest cannot be run twice in parallel because
        # of setUp() and create_test()
        name = self.TESTNAME_PREFIX + "%s_%s" % (os.getpid(), name)
        path = os.path.join(self.testdir, name + ".py")

        self.addCleanup(support.unlink, path)
        # Use 'x' mode to ensure that we do not override existing tests
        try:
            with open(path, "x", encoding="utf-8") as fp:
                fp.write(code)
        except PermissionError as exc:
            if not sysconfig.is_python_build():
                self.skipTest("cannot write %s: %s" % (path, exc))
            raise
        return name
开发者ID:ChanChiChoi,项目名称:cpython,代码行数:20,代码来源:test_regrtest.py

示例13: fixup_build_ext

def fixup_build_ext(cmd):
    """Function needed to make build_ext tests pass.

    When Python was built with --enable-shared on Unix, -L. is not enough to
    find libpython<blah>.so, because regrtest runs in a tempdir, not in the
    source directory where the .so lives.  (Mac OS X embeds absolute paths
    to shared libraries into executables, so the fixup is a no-op on that
    platform.)

    When Python was built with in debug mode on Windows, build_ext commands
    need their debug attribute set, and it is not done automatically for
    some reason.

    This function handles both of these things, and also fixes
    cmd.distribution.include_dirs if the running Python is an uninstalled
    build.  Example use:

        cmd = build_ext(dist)
        support.fixup_build_ext(cmd)
        cmd.ensure_finalized()
    """
    if os.name == 'nt':
        cmd.debug = sys.executable.endswith('_d.exe')
    elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
        # To further add to the shared builds fun on Unix, we can't just add
        # library_dirs to the Extension() instance because that doesn't get
        # plumbed through to the final compiler command.
        runshared = sysconfig.get_config_var('RUNSHARED')
        if runshared is None:
            cmd.library_dirs = ['.']
        else:
            if sys.platform == 'darwin':
                cmd.library_dirs = []
            else:
                name, equals, value = runshared.partition('=')
                cmd.library_dirs = value.split(os.pathsep)

    # Allow tests to run with an uninstalled Python
    if sysconfig.is_python_build():
        pysrcdir = sysconfig.get_config_var('projectbase')
        cmd.distribution.include_dirs.append(os.path.join(pysrcdir, 'Include'))
开发者ID:Naddiseo,项目名称:cpython,代码行数:41,代码来源:support.py

示例14: test_exception

 def test_exception(self):
     parser = expat.ParserCreate()
     parser.StartElementHandler = self.StartElementHandler
     try:
         parser.Parse(b"<a><b><c/></b></a>", 1)
         self.fail()
     except RuntimeError as e:
         self.assertEqual(e.args[0], 'a',
                          "Expected RuntimeError for element 'a', but" + \
                          " found %r" % e.args[0])
         # Check that the traceback contains the relevant line in pyexpat.c
         entries = traceback.extract_tb(e.__traceback__)
         self.assertEqual(len(entries), 3)
         self.check_traceback_entry(entries[0],
                                    "test_pyexpat.py", "test_exception")
         self.check_traceback_entry(entries[1],
                                    "pyexpat.c", "StartElement")
         self.check_traceback_entry(entries[2],
                                    "test_pyexpat.py", "StartElementHandler")
         if sysconfig.is_python_build():
             self.assertIn('call_with_frame("StartElement"', entries[1][3])
开发者ID:ARK4579,项目名称:cpython,代码行数:21,代码来源:test_pyexpat.py

示例15: create_test

    def create_test(self, name=None, code=''):
        if not name:
            name = 'noop%s' % BaseTestCase.TEST_UNIQUE_ID
            BaseTestCase.TEST_UNIQUE_ID += 1

        # test_regrtest cannot be run twice in parallel because
        # of setUp() and create_test()
        name = self.TESTNAME_PREFIX + name
        path = os.path.join(self.tmptestdir, name + '.py')

        self.addCleanup(support.unlink, path)
        # Use O_EXCL to ensure that we do not override existing tests
        try:
            fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
        except OSError as exc:
            if (exc.errno in (errno.EACCES, errno.EPERM)
               and not sysconfig.is_python_build()):
                self.skipTest("cannot write %s: %s" % (path, exc))
            else:
                raise
        else:
            with os.fdopen(fd, 'w') as fp:
                fp.write(code)
        return name
开发者ID:RDWang,项目名称:python,代码行数:24,代码来源:test_regrtest.py


注:本文中的sysconfig.is_python_build函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。