本文整理汇总了Python中setuptools.dist.Distribution类的典型用法代码示例。如果您正苦于以下问题:Python Distribution类的具体用法?Python Distribution怎么用?Python Distribution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Distribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sdist_with_latin1_encoded_filename
def test_sdist_with_latin1_encoded_filename(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()
# Latin-1 filename
filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
open(filename, 'w').close()
quiet()
try:
cmd.run()
finally:
unquiet()
if sys.version_info >= (3,):
filename = filename.decode('latin-1')
if sys.platform == 'win32':
# Latin-1 is similar to Windows-1252
self.assertTrue(filename in cmd.filelist.files)
else:
# The Latin-1 filename should have been skipped
self.assertFalse(filename in cmd.filelist.files)
else:
# No conversion takes place under Python 2 and the file
# is included. We shall keep it that way for BBB.
self.assertTrue(filename in cmd.filelist.files)
示例2: test_run_ok
def test_run_ok(self):
""" Assert spawn is called with the right parameters """
from setuptools.dist import Distribution
dist = Distribution(
dict(name='foo',
packages=['foo'],
use_2to3=True,
version='0.0',
))
dist.script_name = 'setup.py'
from build_commands import BowerCommand
cmd = BowerCommand(dist)
import tempfile
cmd.instance_dir = tempfile.mkdtemp()
import mock
with mock.patch('build_commands.bower.find_executable') \
as find_executable:
find_executable.return_value = '/tmp/bower'
cmd.finalize_options()
spawn_mock = mock.MagicMock()
cmd.spawn = spawn_mock
import sys
old_stdout = sys.stdout
try:
cmd.run()
finally:
sys.stdout = old_stdout
expected = ['bower', 'install', cmd.instance_dir]
spawn_mock.assert_called_once_with(expected)
示例3: test_write_manifest_skips_non_utf8_filenames
def test_write_manifest_skips_non_utf8_filenames(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
mm = manifest_maker(dist)
mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
os.mkdir('sdist_test.egg-info')
# Latin-1 filename
filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
# Add filename with surrogates and write manifest
quiet()
try:
mm.run()
u_filename = filename.decode('utf-8', 'surrogateescape')
mm.filelist.files.append(u_filename)
# Re-write manifest
mm.write_manifest()
finally:
unquiet()
manifest = open(mm.manifest, 'rbU')
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded
try:
contents.decode('UTF-8')
except UnicodeDecodeError, e:
self.fail(e)
示例4: test_sdist_with_utf8_encoded_filename
def test_sdist_with_utf8_encoded_filename(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()
# UTF-8 filename
filename = os.path.join(b('sdist_test'), b('smörbröd.py'))
open(filename, 'w').close()
quiet()
try:
cmd.run()
finally:
unquiet()
if sys.platform == 'darwin':
filename = decompose(filename)
if sys.version_info >= (3,):
if sys.platform == 'win32':
# Python 3 mangles the UTF-8 filename
filename = filename.decode('cp1252')
self.assertTrue(filename in cmd.filelist.files)
else:
filename = filename.decode('utf-8')
self.assertTrue(filename in cmd.filelist.files)
else:
self.assertTrue(filename in cmd.filelist.files)
示例5: test_manifest_is_written_with_utf8_encoding
def test_manifest_is_written_with_utf8_encoding(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
mm = manifest_maker(dist)
mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
os.mkdir('sdist_test.egg-info')
# UTF-8 filename
filename = os.path.join('sdist_test', 'smörbröd.py')
# Add UTF-8 filename and write manifest
quiet()
try:
mm.run()
mm.filelist.files.append(filename)
mm.write_manifest()
finally:
unquiet()
manifest = open(mm.manifest, 'rbU')
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded
try:
u_contents = contents.decode('UTF-8')
except UnicodeDecodeError, e:
self.fail(e)
示例6: test_local_index
def test_local_index(self):
# make sure the local index is used
# when easy_install looks for installed
# packages
new_location = tempfile.mkdtemp()
target = tempfile.mkdtemp()
egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
f = open(egg_file, 'w')
try:
f.write('Name: foo\n')
except:
f.close()
sys.path.append(target)
old_ppath = os.environ.get('PYTHONPATH')
os.environ['PYTHONPATH'] = ':'.join(sys.path)
try:
dist = Distribution()
dist.script_name = 'setup.py'
cmd = easy_install(dist)
cmd.install_dir = target
cmd.args = ['foo']
cmd.ensure_finalized()
cmd.local_index.scan([new_location])
res = cmd.easy_install('foo')
self.assertEquals(res.location, new_location)
finally:
sys.path.remove(target)
shutil.rmtree(new_location)
shutil.rmtree(target)
if old_ppath is not None:
os.environ['PYTHONPATH'] = old_ppath
else:
del os.environ['PYTHONPATH']
示例7: test_test
def test_test(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
dist = Distribution(dict(
name='foo',
packages=['name', 'name.space', 'name.space.tests'],
namespace_packages=['name'],
test_suite='name.space.tests.test_suite',
use_2to3=True,
))
dist.script_name = 'setup.py'
cmd = test(dist)
cmd.user = 1
cmd.ensure_finalized()
cmd.install_dir = site.USER_SITE
cmd.user = 1
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
try: # try/except/finally doesn't work in Python 2.4, so we need nested try-statements.
cmd.run()
except SystemExit: # The test runner calls sys.exit, stop that making an error.
pass
finally:
sys.stdout = old_stdout
示例8: test_read_manifest_skips_non_utf8_filenames
def test_read_manifest_skips_non_utf8_filenames(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = "setup.py"
cmd = sdist(dist)
cmd.ensure_finalized()
# Create manifest
with quiet():
cmd.run()
# Add Latin-1 filename to manifest
filename = os.path.join(b("sdist_test"), LATIN1_FILENAME)
cmd.manifest = os.path.join("sdist_test.egg-info", "SOURCES.txt")
manifest = open(cmd.manifest, "ab")
manifest.write(b("\n") + filename)
manifest.close()
# The file must exist to be included in the filelist
open(filename, "w").close()
# Re-read manifest
cmd.filelist.files = []
with quiet():
cmd.read_manifest()
# The Latin-1 filename should have been skipped
filename = filename.decode("latin-1")
assert filename not in cmd.filelist.files
示例9: test_sdist_with_utf8_encoded_filename
def test_sdist_with_utf8_encoded_filename(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = "setup.py"
cmd = sdist(dist)
cmd.ensure_finalized()
# UTF-8 filename
filename = os.path.join(b("sdist_test"), b("smörbröd.py"))
open(filename, "w").close()
with quiet():
cmd.run()
if sys.platform == "darwin":
filename = decompose(filename)
if six.PY3:
fs_enc = sys.getfilesystemencoding()
if sys.platform == "win32":
if fs_enc == "cp1252":
# Python 3 mangles the UTF-8 filename
filename = filename.decode("cp1252")
assert filename in cmd.filelist.files
else:
filename = filename.decode("mbcs")
assert filename in cmd.filelist.files
else:
filename = filename.decode("utf-8")
assert filename in cmd.filelist.files
else:
assert filename in cmd.filelist.files
示例10: test_manifest_is_read_with_utf8_encoding
def test_manifest_is_read_with_utf8_encoding(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = "setup.py"
cmd = sdist(dist)
cmd.ensure_finalized()
# Create manifest
with quiet():
cmd.run()
# Add UTF-8 filename to manifest
filename = os.path.join(b("sdist_test"), b("smörbröd.py"))
cmd.manifest = os.path.join("sdist_test.egg-info", "SOURCES.txt")
manifest = open(cmd.manifest, "ab")
manifest.write(b("\n") + filename)
manifest.close()
# The file must exist to be included in the filelist
open(filename, "w").close()
# Re-read manifest
cmd.filelist.files = []
with quiet():
cmd.read_manifest()
# The filelist should contain the UTF-8 filename
if six.PY3:
filename = filename.decode("utf-8")
assert filename in cmd.filelist.files
示例11: test_manifest_is_read_with_surrogateescape_error_handler
def test_manifest_is_read_with_surrogateescape_error_handler(self):
# Test for #303.
# This is hard to test on HFS Plus because it quotes unknown
# bytes (see previous test). Furthermore, egg_info.FileList
# only appends filenames that os.path.exist.
# We therefore write the manifest file by hand and check whether
# read_manifest produces a UnicodeDecodeError.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()
filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
quiet()
try:
cmd.run()
# Add Latin-1 filename to manifest
cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
manifest = open(cmd.manifest, 'ab')
manifest.write(filename+b('\n'))
manifest.close()
# Re-read manifest
try:
cmd.read_manifest()
except UnicodeDecodeError, e:
self.fail(e)
finally:
unquiet()
示例12: test_manifest_is_written_with_surrogateescape_error_handler
def test_manifest_is_written_with_surrogateescape_error_handler(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = 'setup.py'
mm = manifest_maker(dist)
mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
os.mkdir('sdist_test.egg-info')
# Latin-1 filename
filename = posixpath.join(b('sdist_test'), LATIN1_FILENAME)
# Add filename with surrogates and write manifest
quiet()
try:
mm.run()
if sys.version_info >= (3,):
u = filename.decode('utf-8', 'surrogateescape')
mm.filelist.files.append(u)
else:
mm.filelist.files.append(filename)
mm.write_manifest()
finally:
unquiet()
manifest = open(mm.manifest, 'rbU')
contents = manifest.read()
manifest.close()
# The manifest should contain the Latin-1 filename
self.assertTrue(filename in contents)
示例13: test_tests_are_run_once
def test_tests_are_run_once(capfd):
params = dict(
name='foo',
packages=['dummy'],
)
with open('setup.py', 'wt') as f:
f.write('from setuptools import setup; setup(\n')
for k, v in sorted(params.items()):
f.write(' %s=%r,\n' % (k, v))
f.write(')\n')
os.makedirs('dummy')
with open('dummy/__init__.py', 'wt'):
pass
with open('dummy/test_dummy.py', 'wt') as f:
f.write(DALS(
"""
from __future__ import print_function
import unittest
class TestTest(unittest.TestCase):
def test_test(self):
print('Foo')
"""))
dist = Distribution(params)
dist.script_name = 'setup.py'
cmd = test(dist)
cmd.ensure_finalized()
# The test runner calls sys.exit
with contexts.suppress_exceptions(SystemExit):
cmd.run()
out, err = capfd.readouterr()
assert out == 'Foo\n'
示例14: test_manifest_is_written_with_utf8_encoding
def test_manifest_is_written_with_utf8_encoding(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
dist.script_name = "setup.py"
mm = manifest_maker(dist)
mm.manifest = os.path.join("sdist_test.egg-info", "SOURCES.txt")
os.mkdir("sdist_test.egg-info")
# UTF-8 filename
filename = os.path.join("sdist_test", "smörbröd.py")
# Add UTF-8 filename and write manifest
quiet()
try:
mm.run()
mm.filelist.files.append(filename)
mm.write_manifest()
finally:
unquiet()
manifest = open(mm.manifest, "rbU")
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded
try:
u_contents = contents.decode("UTF-8")
except UnicodeDecodeError as e:
self.fail(e)
# The manifest should contain the UTF-8 filename
if sys.version_info >= (3,):
self.assertTrue(posix(filename) in u_contents)
else:
self.assertTrue(posix(filename) in contents)
示例15: __init__
def __init__(self, *attrs):
Distribution.__init__(self, *attrs)
self.cmdclass['install'] = uWSGIInstall
self.cmdclass['install_lib'] = uWSGIInstallLib
self.cmdclass['build_ext'] = uWSGIBuilder
if HAS_WHEEL:
self.cmdclass['bdist_wheel'] = uWSGIWheel