Tôi đã cố gắng triển khai tính năng biên soạn Compass trong các công cụ thiết lập build
, nhưng mã sau chạy trình biên dịch trong lệnh build
rõ ràng và không chạy trong install
.Chạy các công cụ cài đặt tùy chỉnh được xây dựng trong khi cài đặt
#!/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,
},
)
Bất kỳ hướng dẫn tùy chỉnh tại Build.run
(ví dụ một số in) không áp dụng trong install
quá, nhưng dist
dụ chứa trong commands
thuộc tính duy nhất của tôi build
trường hợp thực hiện lệnh. Đáng kinh ngạc! Nhưng tôi nghĩ rằng rắc rối là trong quan hệ phức tạp giữa setuptools
và distutils
. Có ai biết làm thế nào để làm cho xây dựng tùy chỉnh chạy trong install
trên Python 2,7?
Cập nhật: Tìm thấy rằng install
chắc chắn không gọi build
lệnh, nhưng nó gọi bdist_egg
chạy build_ext
. Có vẻ như tôi nên triển khai tiện ích mở rộng "Compass".