本文整理汇总了Python中setuptools.sandbox.run_setup函数的典型用法代码示例。如果您正苦于以下问题:Python run_setup函数的具体用法?Python run_setup怎么用?Python run_setup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_setup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _directory_import
def _directory_import(path):
"""
Import astropy_helpers from the given path, which will be added to
sys.path.
Must return True if the import succeeded, and False otherwise.
"""
# Return True on success, False on failure but download is allowed, and
# otherwise raise SystemExit
path = os.path.abspath(path)
# Use an empty WorkingSet rather than the man pkg_resources.working_set,
# since on older versions of setuptools this will invoke a VersionConflict
# when trying to install an upgrade
ws = pkg_resources.WorkingSet([])
ws.add_entry(path)
dist = ws.by_key.get(DIST_NAME)
if dist is None:
# We didn't find an egg-info/dist-info in the given path, but if a
# setup.py exists we can generate it
setup_py = os.path.join(path, 'setup.py')
if os.path.isfile(setup_py):
with _silence():
run_setup(os.path.join(path, 'setup.py'), ['egg_info'])
for dist in pkg_resources.find_distributions(path, True):
# There should be only one...
return dist
return dist
开发者ID:astrofrog,项目名称:sphere,代码行数:32,代码来源:ah_bootstrap.py
示例2: test_setup_requires_with_attr_version
def test_setup_requires_with_attr_version(self, use_setup_cfg):
def make_dependency_sdist(dist_path, distname, version):
files = [(
'setup.py',
DALS("""
import setuptools
setuptools.setup(
name={name!r},
version={version!r},
py_modules=[{name!r}],
)
""".format(name=distname, version=version)),
), (
distname + '.py',
DALS("""
version = 42
"""),
)]
make_sdist(dist_path, files)
with contexts.save_pkg_resources_state():
with contexts.tempdir() as temp_dir:
test_pkg = create_setup_requires_package(
temp_dir, setup_attrs=dict(version='attr: foobar.version'),
make_package=make_dependency_sdist,
use_setup_cfg=use_setup_cfg+('version',),
)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
run_setup(test_setup_py, [str('--version')])
lines = stdout.readlines()
assert len(lines) > 0
assert lines[-1].strip() == '42'
开发者ID:benoit-pierre,项目名称:setuptools,代码行数:32,代码来源:test_easy_install.py
示例3: test_setup_requires_overrides_version_conflict
def test_setup_requires_overrides_version_conflict(self, use_setup_cfg):
"""
Regression test for distribution issue 323:
https://bitbucket.org/tarek/distribute/issues/323
Ensures that a distribution's setup_requires requirements can still be
installed and used locally even if a conflicting version of that
requirement is already on the path.
"""
fake_dist = PRDistribution('does-not-matter', project_name='foobar',
version='0.0')
working_set.add(fake_dist)
with contexts.save_pkg_resources_state():
with contexts.tempdir() as temp_dir:
test_pkg = create_setup_requires_package(
temp_dir, use_setup_cfg=use_setup_cfg)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
# Don't even need to install the package, just
# running the setup.py at all is sufficient
run_setup(test_setup_py, [str('--name')])
lines = stdout.readlines()
assert len(lines) > 0
assert lines[-1].strip() == 'test_pkg'
开发者ID:benoit-pierre,项目名称:setuptools,代码行数:27,代码来源:test_easy_install.py
示例4: _directory_import
def _directory_import(path):
"""
Import astropy_helpers from the given path, which will be added to
sys.path.
Must return True if the import succeeded, and False otherwise.
"""
# Return True on success, False on failure but download is allowed, and
# otherwise raise SystemExit
path = os.path.abspath(path)
pkg_resources.working_set.add_entry(path)
dist = pkg_resources.working_set.by_key.get(DIST_NAME)
if dist is None:
# We didn't find an egg-info/dist-info in the given path, but if a
# setup.py exists we can generate it
setup_py = os.path.join(path, 'setup.py')
if os.path.isfile(setup_py):
with _silence():
run_setup(os.path.join(path, 'setup.py'), ['egg_info'])
for dist in pkg_resources.find_distributions(path, True):
# There should be only one...
pkg_resources.working_set.add(dist, path, False)
break
return dist
开发者ID:5Zhiyong,项目名称:astropy,代码行数:28,代码来源:ah_bootstrap.py
示例5: test_setup_requires_overrides_version_conflict
def test_setup_requires_overrides_version_conflict(self):
"""
Regression test for issue #323.
Ensures that a distribution's setup_requires requirements can still be
installed and used locally even if a conflicting version of that
requirement is already on the path.
"""
pr_state = pkg_resources.__getstate__()
fake_dist = PRDistribution('does-not-matter', project_name='foobar',
version='0.0')
working_set.add(fake_dist)
try:
with contexts.tempdir() as temp_dir:
test_pkg = create_setup_requires_package(temp_dir)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
# Don't even need to install the package, just
# running the setup.py at all is sufficient
run_setup(test_setup_py, ['--name'])
lines = stdout.readlines()
assert len(lines) > 0
assert lines[-1].strip(), 'test_pkg'
finally:
pkg_resources.__setstate__(pr_state)
开发者ID:17264138,项目名称:IndividualProject,代码行数:28,代码来源:test_easy_install.py
示例6: test_bootstrap_from_directory
def test_bootstrap_from_directory(tmpdir, testpackage, capsys):
"""
Tests simply bundling a copy of the astropy_helpers source code in its
entirety bundled directly in the source package and not in an archive.
"""
import ah_bootstrap
source = tmpdir.mkdir('source')
testpackage.copy(source.join('_astropy_helpers_test_'))
with source.as_cwd():
source.join('setup.py').write(TEST_SETUP_PY.format(args=''))
run_setup('setup.py', [])
stdout, stderr = capsys.readouterr()
stdout = stdout.splitlines()
if stdout:
path = stdout[-1].strip()
else:
path = ''
# Ensure that the astropy_helpers used by the setup.py is the one that
# was imported from git submodule
assert path == str(source.join('_astropy_helpers_test_',
'_astropy_helpers_test_',
'__init__.py'))
开发者ID:cdeil,项目名称:astropy-helpers,代码行数:27,代码来源:test_ah_bootstrap.py
示例7: test_setup_requires_override_nspkg
def test_setup_requires_override_nspkg(self, use_setup_cfg):
"""
Like ``test_setup_requires_overrides_version_conflict`` but where the
``setup_requires`` package is part of a namespace package that has
*already* been imported.
"""
with contexts.save_pkg_resources_state():
with contexts.tempdir() as temp_dir:
foobar_1_archive = os.path.join(temp_dir, 'foo.bar-0.1.tar.gz')
make_nspkg_sdist(foobar_1_archive, 'foo.bar', '0.1')
# Now actually go ahead an extract to the temp dir and add the
# extracted path to sys.path so foo.bar v0.1 is importable
foobar_1_dir = os.path.join(temp_dir, 'foo.bar-0.1')
os.mkdir(foobar_1_dir)
with tarfile.open(foobar_1_archive) as tf:
tf.extractall(foobar_1_dir)
sys.path.insert(1, foobar_1_dir)
dist = PRDistribution(foobar_1_dir, project_name='foo.bar',
version='0.1')
working_set.add(dist)
template = DALS("""\
import foo # Even with foo imported first the
# setup_requires package should override
import setuptools
setuptools.setup(**%r)
if not (hasattr(foo, '__path__') and
len(foo.__path__) == 2):
print('FAIL')
if 'foo.bar-0.2' not in foo.__path__[0]:
print('FAIL')
""")
test_pkg = create_setup_requires_package(
temp_dir, 'foo.bar', '0.2', make_nspkg_sdist, template,
use_setup_cfg=use_setup_cfg)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
try:
# Don't even need to install the package, just
# running the setup.py at all is sufficient
run_setup(test_setup_py, [str('--name')])
except pkg_resources.VersionConflict:
self.fail(
'Installing setup.py requirements '
'caused a VersionConflict')
assert 'FAIL' not in stdout.getvalue()
lines = stdout.readlines()
assert len(lines) > 0
assert lines[-1].strip() == 'test_pkg'
开发者ID:benoit-pierre,项目名称:setuptools,代码行数:57,代码来源:test_easy_install.py
示例8: test_download_if_needed
def test_download_if_needed(tmpdir, testpackage, capsys):
"""
Tests the case where astropy_helpers was not actually included in a
package, or is otherwise missing, and we need to "download" it.
This does not test actually downloading from the internet--this is normally
done through setuptools' easy_install command which can also install from a
source archive. From the point of view of ah_boostrap the two actions are
equivalent, so we can just as easily simulate this by providing a setup.cfg
giving the path to a source archive to "download" (as though it were a
URL).
"""
source = tmpdir.mkdir('source')
# Ensure ah_bootstrap is imported from the local directory
import ah_bootstrap
# Make a source distribution of the test package
with silence():
run_setup(str(testpackage.join('setup.py')),
['sdist', '--dist-dir=dist', '--formats=gztar'])
dist_dir = testpackage.join('dist')
with source.as_cwd():
source.join('setup.py').write(TEST_SETUP_PY.format(
args='download_if_needed=True'))
source.join('setup.cfg').write(textwrap.dedent("""\
[easy_install]
find_links = {find_links}
""".format(find_links=str(dist_dir))))
run_setup('setup.py', [])
stdout, stderr = capsys.readouterr()
# Just take the last line--on Python 2.6 distutils logs warning
# messages to stdout instead of stderr, causing them to be mixed up
# with our expected output
path = stdout.splitlines()[-1].strip()
# easy_install should have worked by 'installing' astropy_helpers as a
# .egg in the current directory
eggs = glob.glob('*.egg')
assert eggs
egg = source.join(eggs[0])
assert os.path.isdir(str(egg))
a = os.path.normcase(path)
b = os.path.normcase(str(egg.join('_astropy_helpers_test_',
'__init__.py')))
assert a == b
开发者ID:RayPlante,项目名称:astropy-helpers,代码行数:53,代码来源:test_ah_bootstrap.py
示例9: archive_package
def archive_package(self, cache=True):
"""Downloads the source tree and makes the source distribution.
It yields triple of package name, filename of the source
distribution, and its full path. ::
with build.archive_package() as (package, filename, path):
sftp.put(path, filename)
:param cache: whether to cache the package file or not.
``True`` by default
:type cache: :class:`bool`
"""
logger_ = self.get_logger('archive_package')
with self.branch.fetch(self.commit.ref) as path:
setup_script = os.path.join(path, 'setup.py')
if not os.path.isfile(setup_script):
raise IOError('cannot found setup.py script in the source '
'tree {0!r}'.format(self.commit))
tag = '.{0}.{1:%Y%m%d%H%M%S}.{2!s:.7}'.format(
self.branch.label,
self.commit.committed_at.astimezone(UTC()),
self.commit
)
with capture_stdout() as buffer_:
run_setup(setup_script, ['--fullname'])
fullname = buffer_.getvalue().rstrip().splitlines()[-1]
package_name = fullname + tag
filename = package_name + '.tar.bz2'
if cache:
cache_dir_path = os.path.join(
tempfile.gettempdir(),
'asuka-dist-cache'
)
if not os.path.isdir(cache_dir_path):
os.makedirs(cache_dir_path)
cache_path = os.path.join(cache_dir_path, filename)
if os.path.isfile(cache_path):
logger_.info('cache exists: %s, skipping sdist...',
cache_path)
yield package_name, filename, cache_path
return
run_setup(setup_script, [
'egg_info', '--tag-build', tag,
'sdist', '--formats=bztar'
])
filepath = os.path.join(path, 'dist', filename)
logger_.info('sdist_path = %r', filepath)
if cache:
logger_.info('save sdist cache %s...', cache_path)
shutil.copyfile(filepath, cache_path)
yield package_name, filename, filepath
开发者ID:ibank,项目名称:asuka,代码行数:52,代码来源:dist.py
示例10: test_setup_requires
def test_setup_requires(self):
"""Regression test for Distribute issue #318
Ensure that a package with setup_requires can be installed when
setuptools is installed in the user site-packages without causing a
SandboxViolation.
"""
test_setup_attrs = {
'name': 'test_pkg', 'version': '0.0',
'setup_requires': ['foobar'],
'dependency_links': [os.path.abspath(self.dir)]
}
test_pkg = os.path.join(self.dir, 'test_pkg')
test_setup_py = os.path.join(test_pkg, 'setup.py')
os.mkdir(test_pkg)
f = open(test_setup_py, 'w')
f.write(textwrap.dedent("""\
import setuptools
setuptools.setup(**%r)
""" % test_setup_attrs))
f.close()
foobar_path = os.path.join(self.dir, 'foobar-0.1.tar.gz')
make_trivial_sdist(
foobar_path,
textwrap.dedent("""\
import setuptools
setuptools.setup(
name='foobar',
version='0.1'
)
"""))
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
try:
try:
with reset_setup_stop_context():
run_setup(test_setup_py, ['install'])
except SandboxViolation:
self.fail('Installation caused SandboxViolation')
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
开发者ID:Orav,项目名称:kbengine,代码行数:49,代码来源:test_easy_install.py
示例11: test_bootstrap_from_submodule
def test_bootstrap_from_submodule(tmpdir, testpackage, capsys):
"""
Tests importing _astropy_helpers_test_ from a submodule in a git
repository. This tests actually performing a fresh clone of the repository
without the submodule initialized, and that importing astropy_helpers in
that context works transparently after calling
`ah_boostrap.use_astropy_helpers`.
"""
orig_repo = tmpdir.mkdir('orig')
# Ensure ah_bootstrap is imported from the local directory
import ah_bootstrap
with orig_repo.as_cwd():
run_cmd('git', ['init'])
# Write a test setup.py that uses ah_bootstrap; it also ensures that
# any previous reference to astropy_helpers is first wiped from
# sys.modules
orig_repo.join('setup.py').write(TEST_SETUP_PY.format(args=''))
run_cmd('git', ['add', 'setup.py'])
# Add our own clone of the astropy_helpers repo as a submodule named
# astropy_helpers
run_cmd('git', ['submodule', 'add', str(testpackage),
'_astropy_helpers_test_'])
run_cmd('git', ['commit', '-m', 'test repository'])
os.chdir(str(tmpdir))
# Creates a clone of our test repo in the directory 'clone'
run_cmd('git', ['clone', 'orig', 'clone'])
os.chdir('clone')
run_setup('setup.py', [])
stdout, stderr = capsys.readouterr()
path = stdout.strip()
# Ensure that the astropy_helpers used by the setup.py is the one that
# was imported from git submodule
a = os.path.normcase(path)
b = os.path.normcase(str(tmpdir.join('clone', '_astropy_helpers_test_',
'_astropy_helpers_test_',
'__init__.py')))
assert a == b
开发者ID:RayPlante,项目名称:astropy-helpers,代码行数:49,代码来源:test_ah_bootstrap.py
示例12: run_setup
def run_setup(self, *args):
old_stdout = sys.stdout
old_stderr = sys.stderr
stdout = sys.stdout = StringIO()
stderr = sys.stderr = StringIO()
try:
run_setup('setup.py', args)
returncode = 0
except SystemExit as e:
returncode = e.args[0]
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
return (stdout.getvalue().strip(), stderr.getvalue().strip(),
returncode)
开发者ID:embray,项目名称:setup.cfg,代码行数:16,代码来源:__init__.py
示例13: run_setup
def run_setup(self, setup_script, setup_base, args):
args = list(args)
if self.verbose>2:
v = 'v' * (self.verbose - 1)
args.insert(0,'-'+v)
elif self.verbose<2:
args.insert(0,'-q')
if self.dry_run:
args.insert(0,'-n')
log.info(
"Running %s %s", setup_script[len(setup_base)+1:], ' '.join(args)
)
try:
run_setup(setup_script, args)
except SystemExit, v:
raise DistutilsError("Setup script exited with %s" % (v.args[0],))
开发者ID:carlitux,项目名称:gaebuild,代码行数:16,代码来源:dist_installer.py
示例14: test_check_submodule_no_git
def test_check_submodule_no_git(tmpdir, testpackage):
"""
Tests that when importing astropy_helpers from a submodule, it is still
recognized as a submodule even when using the --no-git option.
In particular this ensures that the auto-upgrade feature is not activated.
"""
orig_repo = tmpdir.mkdir('orig')
# Ensure ah_bootstrap is imported from the local directory
import ah_bootstrap
with orig_repo.as_cwd():
run_cmd('git', ['init'])
# Write a test setup.py that uses ah_bootstrap; it also ensures that
# any previous reference to astropy_helpers is first wiped from
# sys.modules
args = 'auto_upgrade=True'
orig_repo.join('setup.py').write(TEST_SETUP_PY.format(args=args))
run_cmd('git', ['add', 'setup.py'])
# Add our own clone of the astropy_helpers repo as a submodule named
# astropy_helpers
run_cmd('git', ['submodule', 'add', str(testpackage),
'_astropy_helpers_test_'])
run_cmd('git', ['commit', '-m', 'test repository'])
# Temporarily patch _do_upgrade to fail if called
class UpgradeError(Exception):
pass
def _do_upgrade(*args, **kwargs):
raise UpgradeError()
orig_do_upgrade = ah_bootstrap._do_upgrade
ah_bootstrap._do_upgrade = _do_upgrade
try:
run_setup('setup.py', ['--no-git'])
except UpgradeError:
pytest.fail('Attempted to run auto-upgrade despite importing '
'_astropy_helpers_test_ from a git submodule')
finally:
ah_bootstrap._do_upgrade = orig_do_upgrade
开发者ID:Shivaji123,项目名称:astropy-helpers,代码行数:46,代码来源:test_ah_bootstrap.py
示例15: test_update_git_devstr
def test_update_git_devstr(package_template, capsys):
"""Tests that the commit number in the package's version string updates
after git commits even without re-running setup.py.
"""
run_setup('setup.py', ['--version'])
stdout, stderr = capsys.readouterr()
version = stdout.strip()
m = _DEV_VERSION_RE.match(version)
assert m, (
"Stdout did not match the version string pattern:"
"\n\n{0}\n\nStderr:\n\n{1}".format(stdout, stderr))
revcount = int(m.group(1))
import packagename
assert packagename.__version__ == version
# Make a silly git commit
with open('.test', 'w'):
pass
run_cmd('git', ['add', '.test'])
run_cmd('git', ['commit', '-m', 'test'])
import packagename.version
imp.reload(packagename.version)
# Previously this checked packagename.__version__, but in order for that to
# be updated we also have to re-import _astropy_init which could be tricky.
# Checking directly that the packagename.version module was updated is
# sufficient:
m = _DEV_VERSION_RE.match(packagename.version.version)
assert m
assert int(m.group(1)) == revcount + 1
# This doesn't test astropy_helpers.get_helpers.update_git_devstr directly
# since a copy of that function is made in packagename.version (so that it
# can work without astropy_helpers installed). In order to get test
# coverage on the actual astropy_helpers copy of that function just call it
# directly and compare to the value in packagename
from astropy_helpers.git_helpers import update_git_devstr
newversion = update_git_devstr(version, path=str(package_template))
assert newversion == packagename.version.version
开发者ID:RayPlante,项目名称:astropy-helpers,代码行数:46,代码来源:test_git_helpers.py
示例16: test_setup_requires
def test_setup_requires(self):
"""Regression test for Distribute issue #318
Ensure that a package with setup_requires can be installed when
setuptools is installed in the user site-packages without causing a
SandboxViolation.
"""
test_pkg = create_setup_requires_package(self.dir)
test_setup_py = os.path.join(test_pkg, 'setup.py')
try:
with quiet_context():
with reset_setup_stop_context():
run_setup(test_setup_py, ['install'])
except SandboxViolation:
self.fail('Installation caused SandboxViolation')
开发者ID:13lcp2000,项目名称:recetario4-4,代码行数:17,代码来源:test_easy_install.py
示例17: test_bootstrap_from_archive
def test_bootstrap_from_archive(tmpdir, testpackage, capsys):
"""
Tests importing _astropy_helpers_test_ from a .tar.gz source archive
shipped alongside the package that uses it.
"""
orig_repo = tmpdir.mkdir('orig')
# Ensure ah_bootstrap is imported from the local directory
import ah_bootstrap
# Make a source distribution of the test package
with silence():
run_setup(str(testpackage.join('setup.py')),
['sdist', '--dist-dir=dist', '--formats=gztar'])
dist_dir = testpackage.join('dist')
for dist_file in dist_dir.visit('*.tar.gz'):
dist_file.copy(orig_repo)
with orig_repo.as_cwd():
# Write a test setup.py that uses ah_bootstrap; it also ensures that
# any previous reference to astropy_helpers is first wiped from
# sys.modules
args = 'path={0!r}'.format(os.path.basename(str(dist_file)))
orig_repo.join('setup.py').write(TEST_SETUP_PY.format(args=args))
run_setup('setup.py', [])
stdout, stderr = capsys.readouterr()
path = stdout.splitlines()[-1].strip()
# Installation from the .tar.gz should have resulted in a .egg
# directory that the _astropy_helpers_test_ package was imported from
eggs = glob.glob('*.egg')
assert eggs
egg = orig_repo.join(eggs[0])
assert os.path.isdir(str(egg))
a = os.path.normcase(path)
b = os.path.normcase(str(egg.join('_astropy_helpers_test_',
'__init__.py')))
assert a == b
开发者ID:RayPlante,项目名称:astropy-helpers,代码行数:44,代码来源:test_ah_bootstrap.py
示例18: test_setup_requires
def test_setup_requires(self):
"""Regression test for Distribute issue #318
Ensure that a package with setup_requires can be installed when
setuptools is installed in the user site-packages without causing a
SandboxViolation.
"""
test_pkg = create_setup_requires_package(os.getcwd())
test_setup_py = os.path.join(test_pkg, 'setup.py')
try:
with contexts.quiet():
with self.patched_setup_context():
run_setup(test_setup_py, ['install'])
except IndexError:
# Test fails in some cases due to bugs in Python
# See https://bitbucket.org/pypa/setuptools/issue/201
pass
开发者ID:yuexizhaohong,项目名称:python,代码行数:19,代码来源:test_easy_install.py
示例19: run_setup
def run_setup(*args, **kwargs):
"""
In Python 3, on MacOS X, the import cache has to be invalidated otherwise
new extensions built with ``run_setup`` do not always get picked up.
"""
try:
return sandbox.run_setup(*args, **kwargs)
finally:
if sys.version_info[:2] >= (3, 3):
import importlib
importlib.invalidate_caches()
开发者ID:Punyaslok,项目名称:astropy-helpers,代码行数:12,代码来源:__init__.py
示例20: setup_and_run
def setup_and_run(temp_dir):
test_pkg = create_setup_requires_package(temp_dir)
test_setup_py = os.path.join(test_pkg, 'setup.py')
try:
stdout, stderr = quiet_context(
lambda: reset_setup_stop_context(
# Don't even need to install the package, just running
# the setup.py at all is sufficient
lambda: run_setup(test_setup_py, ['--name'])
))
except VersionConflict:
self.fail('Installing setup.py requirements caused '
'VersionConflict')
lines = stdout.splitlines()
self.assertGreater(len(lines), 0)
self.assert_(lines[-1].strip(), 'test_pkg')
开发者ID:drbazzi,项目名称:cs169,代码行数:17,代码来源:test_easy_install.py
注:本文中的setuptools.sandbox.run_setup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论