本文整理汇总了Python中zipapp.create_archive函数的典型用法代码示例。如果您正苦于以下问题:Python create_archive函数的具体用法?Python create_archive怎么用?Python create_archive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_archive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--root", default=".")
parser.add_argument("--dest")
args = parser.parse_args()
if args.dest is not None:
dest = args.dest
else:
dest = os.path.join(args.root, "virtualenv.pyz")
bio = io.BytesIO()
with zipfile.ZipFile(bio, "w") as zipf:
filenames = ["LICENSE.txt", "virtualenv.py"]
for whl in os.listdir(os.path.join(args.root, "virtualenv_support")):
filenames.append(os.path.join("virtualenv_support", whl))
for filename in filenames:
zipf.write(os.path.join(args.root, filename), filename)
zipf.writestr("__main__.py", "import virtualenv; virtualenv.main()")
bio.seek(0)
zipapp.create_archive(bio, dest)
print("zipapp created at {}".format(dest))
开发者ID:pfmoore,项目名称:virtualenv,代码行数:25,代码来源:make_zipapp.py
示例2: test_meson_zipapp
def test_meson_zipapp(self):
if is_windows():
raise unittest.SkipTest('NOT IMPLEMENTED')
source = Path(__file__).resolve().parent.as_posix()
target = self.tmpdir / 'meson.pyz'
zipapp.create_archive(source=source, target=target, interpreter=python_command[0], main=None)
self._run([target.as_posix(), '--help'])
开发者ID:mesonbuild,项目名称:meson,代码行数:7,代码来源:run_meson_command_tests.py
示例3: run
def run(self):
with TemporaryDirectory() as tmpdir:
copytree('unicodemoticon', os.path.join(tmpdir, 'unicodemoticon'))
fyle = os.path.join(tmpdir, '__main__.py')
with open(fyle, 'w', encoding='utf-8') as entry:
entry.write("import runpy\nrunpy.run_module('unicodemoticon')")
create_archive(tmpdir, 'unicodemoticon.pyz', '/usr/bin/env python3')
开发者ID:juancarlospaco,项目名称:unicodemoticon,代码行数:7,代码来源:setup.py
示例4: test_create_archive
def test_create_archive(self):
# Test packing a directory.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target))
self.assertTrue(target.is_file())
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例5: test_main_and_main_py
def test_main_and_main_py(self):
# Test that supplying a main argument with __main__.py fails.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
with self.assertRaises(zipapp.ZipAppError):
zipapp.create_archive(str(source), str(target), main='pkg.mod:fn')
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例6: test_read_shebang
def test_read_shebang(self):
# Test that we can read the shebang line correctly.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), interpreter='python')
self.assertEqual(zipapp.get_interpreter(str(target)), 'python')
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例7: test_no_shebang_is_not_executable
def test_no_shebang_is_not_executable(self):
# Test that an archive with no shebang line is not made executable.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), interpreter=None)
self.assertFalse(target.stat().st_mode & stat.S_IEXEC)
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例8: test_read_missing_shebang
def test_read_missing_shebang(self):
# Test that reading the shebang line of a file without one returns None.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target))
self.assertEqual(zipapp.get_interpreter(str(target)), None)
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例9: test_create_archive_with_pathlib
def test_create_archive_with_pathlib(self):
# Test packing a directory using Path objects for source and target.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(source, target)
self.assertTrue(target.is_file())
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例10: test_no_main
def test_no_main(self):
# Test that packing a directory with no __main__.py fails.
source = self.tmpdir / 'source'
source.mkdir()
(source / 'foo.py').touch()
target = self.tmpdir / 'source.pyz'
with self.assertRaises(zipapp.ZipAppError):
zipapp.create_archive(str(source), str(target))
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例11: test_pack_to_fileobj
def test_pack_to_fileobj(self):
# Test that we can pack to a file object.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = io.BytesIO()
zipapp.create_archive(str(source), target, interpreter='python')
self.assertTrue(target.getvalue().startswith(b'#!python\n'))
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例12: make_archive
def make_archive(self):
# Test that an archive with no shebang line is not made executable.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(source, target)
return target
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例13: test_create_archive_default_target
def test_create_archive_default_target(self):
# Test packing a directory to the default name.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
zipapp.create_archive(str(source))
expected_target = self.tmpdir / 'source.pyz'
self.assertTrue(expected_target.is_file())
开发者ID:ndorte,项目名称:cpython,代码行数:8,代码来源:test_zipapp.py
示例14: test_default_no_shebang
def test_default_no_shebang(self):
# Test that no shebang line is written to the target by default.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target))
with target.open('rb') as f:
self.assertNotEqual(f.read(2), b'#!')
开发者ID:ndorte,项目名称:cpython,代码行数:9,代码来源:test_zipapp.py
示例15: test_remove_shebang
def test_remove_shebang(self):
# Test that we can remove the shebang from a file.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), interpreter='python')
new_target = self.tmpdir / 'changed.pyz'
zipapp.create_archive(str(target), str(new_target), interpreter=None)
self.assertEqual(zipapp.get_interpreter(str(new_target)), None)
开发者ID:ndorte,项目名称:cpython,代码行数:10,代码来源:test_zipapp.py
示例16: test_main_written
def test_main_written(self):
# Test that the __main__.py is written correctly.
source = self.tmpdir / 'source'
source.mkdir()
(source / 'foo.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), main='pkg.mod:fn')
with zipfile.ZipFile(str(target), 'r') as z:
self.assertIn('__main__.py', z.namelist())
self.assertIn(b'pkg.mod.fn()', z.read('__main__.py'))
开发者ID:ndorte,项目名称:cpython,代码行数:10,代码来源:test_zipapp.py
示例17: test_read_from_pathobj
def test_read_from_pathobj(self):
# Test that we can copy an archive using a pathlib.Path object
# for the source.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target1 = self.tmpdir / 'target1.pyz'
target2 = self.tmpdir / 'target2.pyz'
zipapp.create_archive(source, target1, interpreter='python')
zipapp.create_archive(target1, target2, interpreter='python2.7')
self.assertEqual(zipapp.get_interpreter(target2), 'python2.7')
开发者ID:ndorte,项目名称:cpython,代码行数:11,代码来源:test_zipapp.py
示例18: test_write_shebang_to_fileobj
def test_write_shebang_to_fileobj(self):
# Test that we can change the shebang of a file, writing the result to a
# file object.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), interpreter='python')
new_target = io.BytesIO()
zipapp.create_archive(str(target), new_target, interpreter='python2.7')
self.assertTrue(new_target.getvalue().startswith(b'#!python2.7\n'))
开发者ID:ndorte,项目名称:cpython,代码行数:11,代码来源:test_zipapp.py
示例19: test_custom_interpreter
def test_custom_interpreter(self):
# Test that a shebang line with a custom interpreter is written
# correctly.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
zipapp.create_archive(str(source), str(target), interpreter='python')
with target.open('rb') as f:
self.assertEqual(f.read(2), b'#!')
self.assertEqual(b'python\n', f.readline())
开发者ID:ndorte,项目名称:cpython,代码行数:11,代码来源:test_zipapp.py
示例20: test_read_from_fileobj
def test_read_from_fileobj(self):
# Test that we can copy an archive using an open file object.
source = self.tmpdir / 'source'
source.mkdir()
(source / '__main__.py').touch()
target = self.tmpdir / 'source.pyz'
temp_archive = io.BytesIO()
zipapp.create_archive(str(source), temp_archive, interpreter='python')
new_target = io.BytesIO()
temp_archive.seek(0)
zipapp.create_archive(temp_archive, new_target, interpreter='python2.7')
self.assertTrue(new_target.getvalue().startswith(b'#!python2.7\n'))
开发者ID:ndorte,项目名称:cpython,代码行数:12,代码来源:test_zipapp.py
注:本文中的zipapp.create_archive函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论