我试图实现北斗期间setuptools的build
编译期间,但下面的代码中install
明确build
命令期间运行的编译和不运行。运行自定义setuptools的建设安装
#!/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
和distutils
之间的复杂关系。有没有人知道如何在Python 2.7的install
期间运行自定义构建?
更新:研究发现,install
绝对不来电build
命令,但它调用bdist_egg
它运行build_ext
。似乎我应该实施“Compass”构建扩展。