2017-05-10 1 views
15

インストール時にpythonファイルを生成したいと思います。Pythonパッケージ:インストール時にPythonファイルを生成し、毒でこの作業を行います

python setup.py developpython setup.py installpip installの両方でこの作品を欲しいです。ここまでは順調ですね。

しかし、これも毒素で動作します。これは私が問題を抱えているところです。

私が使用してのアプローチは非常に似setup.pyでソースコードを生成するためにdevelopinstallコマンドを微調整することです:

# 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='[email protected]', 
    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を介してsetup.pyを実行するこのブードゥー教の魔法に問題があるようです。何らかの理由で。私が試した

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/ 

もの:-v -v -v -v

  • で実行

    • pdb.set_trace(コマンドがハングし、Iを追加する
    • 手動ピップコマンドをReruning出力が表示されない)
    • ipythonシェルを追加する(install_requiredの場合でもipythonはインストールされていません)
    • が、これはsetup.pyは、ソースコードに予想される場所に相対確かに私がしようとして考えられてきた

    物事であることを示しているstrace -Fの実行:

    • 実行時にネットワークのバックドアシェルを作成します(プロジェクトのtox.ini -fileで怠惰)
  • +0

    PEP 263を処理するためのtox legacyインタープリタサポート( 'tokenize.open'は暗黙的に' detect_encoding')を定義し、MS改行を* nix改行に変更するように見えます。私はこれがpip間の問題であると言います(私はそれが 'pip - * - build' dirsのmktempingであると仮定します)。 – cowbert

    +0

    私はあなたがテストのためにtoxを使いたいと思うので、tox.iniファイルに 'usedevelop = True'を指定するのは問題でしょうか?これは回避策ですが、ユースケースでは十分かもしれません。 – bow

    答えて

    0

    、あなたがするcommandsを追加することができますテスト環境で実行します。簡単な例は次のようになります。

    [tox] 
    envlist = py27,py34,py35,py36 
    
    [testenv] 
    deps= 
        pytest 
        ; ... other dependencies 
    commands= 
        pytest --basetemp={envtmpdir} {posargs} 
        ; Add your command here? 
    

    毒を作るコマンドを追加することは可能ですか? (このコマンドは環境のそれぞれに対して実行されます)。

    関連する問題