本文介绍了在安装过程中运行自定义setuptools构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在setuptools的 build 期间实现Compass编译,但是以下代码在显式的 build 命令,并且不会在安装期间运行。

I've tried to implement Compass compiling during setuptools' build, but the following code runs compilation during explicit build command and doesn't runs during 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 distutils 之间的复杂关系。有人知道如何在Python 2.7的安装期间运行自定义构建吗?

Any custom instructions at Build.run (e.g. some printing) doesn't apply during install too, but dist instance contains in commands attribute only my build command implementation instances. Incredible! But I think the trouble is in complex relations between setuptools and distutils. Does anybody knows how to make custom building run during install on Python 2.7?

更新:发现 install 绝对不会调用 build 命令,但会调用 bdist_egg 运行 build_ext 。似乎我应该实现 Compass构建扩展。

Update: Found that install definitely doesn't calls build command, but it calls bdist_egg which runs build_ext. Seems like I should implement "Compass" build extension.

推荐答案

不幸的是,我没有找到答案。似乎能够正确运行安装后脚本的功能仅在Distutils 2上存在

这篇关于在安装过程中运行自定义setuptools构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 02:23
查看更多