在安装过程中运行自定义setuptools构建

编程入门 行业动态 更新时间:2024-10-27 10:24:23
本文介绍了在安装过程中运行自定义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 distutilsmand.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?

更新:

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上存在 >现在您可以使用以下解决方法:

Unfortunatelly, I haven't found the answer. Seems like the ability to run post-install scripts correctly there's only at Distutils 2. Now you can use this work-around:

更新:由于setuptools的堆栈检查,我们应该覆盖 install.do_egg_install ,而不是 run 方法:

Update: Because of setuptools' stack checks, we should override install.do_egg_install, not run method:

from setuptoolsmand.install import install class Install(install): def do_egg_install(self): self.run_command('build_css') install.do_egg_install(self)

Update2: easy_install 完全运行 bdist_egg 命令,该命令由 install 使用同样,因此最正确的方法(尤其是如果要使 easy_install 工作)是覆盖 bdist_egg 命令。整个代码:

Update2: easy_install runs exactly bdist_egg command which is used by install too, so the most correct way (espetially if you want to make easy_install work) is to override bdist_egg command. Whole code:

#!/usr/bin/env python import setuptools from distutilsmand.build import build as _build from setuptoolsmand.bdist_egg import bdist_egg as _bdist_egg class bdist_egg(_bdist_egg): def run(self): self.run_command('build_css') _bdist_egg.run(self) class build_css(setuptools.Command): description = 'build CSS from SCSS' user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): pass # Here goes CSS compilation. class build(_build): sub_commands = _build.sub_commands + [('build_css', None)] setuptools.setup( # Here your setup args. cmdclass={ 'bdist_egg': bdist_egg, 'build': build, 'build_css': build_css, }, )

在这里查看我的用法。

更多推荐

在安装过程中运行自定义setuptools构建

本文发布于:2023-11-14 21:36:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   过程中   setuptools

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!