我试图在setuptools的build
期间实现Compass编译,但是下面的代码在显式build
命令期间运行编译,而在install
期间不运行。在
#!/usr/bin/env python
import os
import setuptools
from distutils.command.build import build
SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
class BuildCSS(setuptools.Command):
description = 'build CSS from SCSS'
user_options = []
def initialize_options(self):
pass
def run(self):
os.chdir(os.path.join(SETUP_DIR, 'django_project_dir', 'compass_project_dir'))
import platform
if 'Windows' == platform.system():
command = 'compass.bat compile'
else:
command = 'compass compile'
import subprocess
try:
subprocess.check_call(command.split())
except (subprocess.CalledProcessError, OSError):
print 'ERROR: problems with compiling Sass. Is Compass installed?'
raise SystemExit
os.chdir(SETUP_DIR)
def finalize_options(self):
pass
class Build(build):
sub_commands = build.sub_commands + [('build_css', None)]
setuptools.setup(
# Custom attrs here.
cmdclass={
'build': Build,
'build_css': BuildCSS,
},
)
Build.run
处的任何自定义指令(例如某些打印)在install
期间也不适用,但是dist
实例在commands
属性中只包含我的build
命令实现实例。简直 不可思议!但我认为问题在于setuptools
和{install
期间运行自定义构建吗?在
更新:发现install
绝对不调用build
命令,但它调用运行build_ext
的{
不幸的是,我还没有找到答案。似乎可以正确运行安装后脚本only at Distutils 2.现在您可以使用以下解决方法:
更新:由于setuptools的堆栈检查,我们应该重写}方法:
install.do_egg_install
,而不是{Update2:}使用,因此最正确的方法(尤其是如果您想使}命令。完整代码:
^{pr2}$easy_install
正好运行bdist_egg
命令,该命令也由{easy_install
工作)是重写{你可以看看我是怎么用这个here.
相关问题 更多 >
编程相关推荐