栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在setup.py中执行(安全)bash shell命令?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在setup.py中执行(安全)bash shell命令?

请原谅快速的自我解答。我希望这可以帮助以太坊之外的人。现在,我想分享一个我满意的解决方案。

这是一个安全的解决方案,基于Peter Lamut的文章。请注意,这在子流程调用中 使用shell =
True。您可以绕过python部署系统上的grunt-task要求,也可以将其用于混淆和JS打包。

from setuptools import setupfrom setuptools.command.install import installimport subprocessimport osclass CustomInstallCommand(install):    """Custom install setup to help run shell commands (outside shell) before installation"""    def run(self):        dir_path = os.path.dirname(os.path.realpath(__file__))        template_path = os.path.join(dir_path, 'src/path/to/templates')        templatejs_path = os.path.join(dir_path, 'src/path/to/templates.js')        templatejs = subprocess.check_output([ 'nunjucks-precompile', '--include', '["\.tmpl$"]', template_path        ])        f = open(templatejs_path, 'w')        f.write(templatejs)        f.close()        install.run(self)setup(cmdclass={'install': CustomInstallCommand},      ...     )


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号