Att*_*igh 19 python code-generation build setuptools tox
我想在安装时生成一个python文件.
我想既这项工作python setup.py develop,python setup.py install和pip install.到现在为止还挺好.
但是我也希望这与tox一起使用.这是我遇到问题的地方.
我使用的方法是调整develop和install命令以在setup.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'
)
Run Code Online (Sandbox Code Playgroud)
然而tox,安装方法似乎在某种程度上setup.py远离了我的源代码,并且tox代表的魔法黑盒使得它能够解决正在发生的事情.
这个问题似乎取决于这种伏都教魔法,由于某种原因,setup.py它会通过exec....
Command "/home/tom/active/latex2sympy/.tox/py35/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-e698cucb-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-lu2idbzz-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/tom/active/latex2sympy/.tox/py35/include/site/python3.5/latex2sympy" failed with error code 1 in /tmp/pip-e698cucb-build/
Run Code Online (Sandbox Code Playgroud)
我试过的事情:
pdb.set_trace(命令挂起,我看不到输出)strace -F这显示setup.py确实在相对于源代码的预期位置我考虑过的事情:
在项目的tox.ini文件中,您可以添加要在测试环境中运行的命令。一个简单的例子看起来像这样:
[tox]
envlist = py27,py34,py35,py36
[testenv]
deps=
pytest
; ... other dependencies
commands=
pytest --basetemp={envtmpdir} {posargs}
; Add your command here?
Run Code Online (Sandbox Code Playgroud)
您是否可以添加一个命令来使 tox 执行您想要的操作?(该命令将为每个环境运行)。
| 归档时间: |
|
| 查看次数: |
740 次 |
| 最近记录: |