2017-09-08 2 views
0

Je dispose d'un fichier setup.py pour mon projet FlashText:comment faire fonctionner BuildDoc uniquement lorsque python-sphinx est installé à partir du fichier setup.py?

from setuptools import setup, Command 
from sphinx.setup_command import BuildDoc 

setup(
    . 
    . 
    cmdclass={'test': PyTest, 'build_sphinx': BuildDoc}, 
) 

pip install flashtext échoue si python-sphynx est pas installé.

ImportError: No module named sphinx.setup_command


Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-LI0I_O/flashtext/

Cela corrigera ce problème:

sudo apt-get install python-sphinx 

Ce que j'ai besoin est si quelqu'un ne devraient pas avoir python-sphinx installé, aussi pouvoir installer la bibliothèque. Comment dois-je gérer cela?

par exemple py.test est traitée comme ceci:

import subprocess 


class PyTest(Command): 
    user_options = [] 

    def initialize_options(self): 
     pass 

    def finalize_options(self): 
     pass 

    def run(self): 
     errno = subprocess.call(['py.test']) 
     raise SystemExit(errno) 

PS: Code complet est disponible sur GitHub https://github.com/vi3k6i5/flashtext

Répondre

1
cmdclass={'test': PyTest} 

try: 
    from sphinx.setup_command import BuildDoc 
    cmdclass['build_sphinx'] = BuildDoc 
except ImportError: 
    print('WARNING: sphinx not available, not building docs') 

setup(
    . 
    . 
    cmdclass=cmdclass 
) 
+0

C'est génial. Je vais ajouter ceci et mettre à jour. Merci :) –

+0

Merci. cela a résolu le problème. Testé et vérifié :) –