• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python zipapp.create_archive函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python zipfile.is_zipfile函数代码示例发布时间:2022-05-26
下一篇:
Python utils.datetime函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap