请原谅快速的自我解答。我希望这可以帮助以太坊之外的人。现在,我想分享一个我满意的解决方案。
这是一个安全的解决方案,基于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}, ... )


