Python打包:在安装时生成一个Python文件,使用tox完成这项工作

2024-03-29 05:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在安装时生成一个python文件。在

我希望这项工作同时使用python setup.py developpython setup.py installpip install。到现在为止,一直都还不错。在

不过,我也希望它能与tox一起工作。这就是我遇到问题的地方。在

我使用的方法是调整developinstall命令以在中生成源代码设置.py是这样的:

# make code as python 3 compatible as possible
from __future__ import absolute_import, division, print_function, unicode_literals

import subprocess
import setuptools
import os.path
import distutils.core

from setuptools.command.develop import develop
from setuptools.command.install import install


# Build anltr files on installation
#   this is such a mess... it looks like there are
#   no common steps to develop and install

class AntlrDevelopCommand(develop):
    def run(self):
        compile_grammar()
        develop.run(self)

class AntlrInstallCommand(install):
    def run(self):
        compile_grammar()
        install.run(self)

def compile_grammar():
    here = os.path.dirname(__file__) or '.'
    package_dir = os.path.join(here, 'latex2sympy')
    subprocess.check_output(['antlr4',  'PS.g4', '-o', 'gen'], cwd=package_dir)

setuptools.setup(
    name='latex2sympy',
    version=0.1,
    author='august.codes',
    author_email='augustt198@gmail.com',
    description='Parse latex markup into sympy: suitable for programmatic modifcation',
    license='GPLv3',
    keywords='MIT',
    url='',
    packages=['latex2sympy'],
    classifiers=[
],
    install_requires=['antlr-ast',  'sympy'],
    cmdclass=dict(
        install=AntlrInstallCommand,
        develop=AntlrDevelopCommand),
    test_suite='nose.collector'
)

然而tox的安装方法似乎以某种方式运行在setup.py之外,tox所代表的魔法黑匣子让人有点恼火地去弄清楚到底发生了什么。在

问题似乎归结于这个巫术,它通过一个exec运行它。。。。因为某种原因。在

^{pr2}$

我尝试过的事情:

  • 用-v-v-v-v运行
  • 手动重新调整pip命令
  • 添加pdb.set_trace(命令挂起,我看不到输出)
  • 添加ipython shell(即使在需要安装时也不安装ipython)
  • 运行strace -F这表明setup.py确实位于相对于源代码的预期位置

我考虑过尝试的事情:

  • 在运行时创建网络后门外壳(太懒)

Tags: installpathrunfrompyimport命令self
1条回答
网友
1楼 · 发布于 2024-03-29 05:28:56

毒性试验-项目的文件,您可以添加要在测试环境中运行的commands。一个简单的例子如下所示:

[tox]
envlist = py27,py34,py35,py36

[testenv]
deps=
    pytest
    ; ... other dependencies
commands= 
    pytest  basetemp={envtmpdir} {posargs}
    ; Add your command here?

你可以添加一个命令让tox做你想做的吗?(该命令将针对每个环境运行)。在

相关问题 更多 >