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

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

如何在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},      ...     )


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5601802.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存