为什么tox在install_command期间看不到环境变量?

alv*_*vas 6 python continuous-integration environment-variables travis-ci tox

鉴于tox==3.13.2请参阅详细信息

++pip install tox
Requirement already satisfied: tox in /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages (3.13.2)
Run Code Online (Sandbox Code Playgroud)

tox.ini

[tox]
envlist =
    py-cythonized


[testenv]
; simplify numpy installation
setenv =
    LAPACK=
    ATLAS=None
    PYTHONWARNINGS=ignore

; Copy all environment variables to the tox test environment
passenv = *

deps =
    py-cythonized: Cython >= 0.28.5

changedir = nltk/test
commands =
    ; scipy and scikit-learn requires numpy even to run setup.py so
    ; they can't be installed in one command
    pip install scipy scikit-learn

    ; python runtests.py --with-coverage --cover-inclusive --cover-package=nltk --cover-html --cover-html-dir={envdir}/docs []
    python runtests.py []
Run Code Online (Sandbox Code Playgroud)

特别是:

# Test Cython compiled installation.
[testenv:py-cythonized]
setenv =
    CYTHONIZE_NLTK = "true"
    NLTK_DATA = {homedir}/nltk_data/
extras = all
passenv =
    CYTHONIZE_NLTK
commands =
    {toxinidir}/tools/travis/coverage-pylint.sh
Run Code Online (Sandbox Code Playgroud)

还有的CYTHONIZE_NLTK,应与测试时传递变量tox -e py-cythonize tox.ini -vv

CYTHONIZE_NLTK变量是我的检查setup.py,以添加扩展模块ext_modules

MODULES_TO_COMPILE = [
    #'nltk.ccg.*', # Fails on https://travis-ci.org/nltk/nltk/jobs/529589821#L2077
    'nltk.chat.*',
    'nltk.chunk.*',

def compile_modules(modules):
    """
    Compile the named modules using Cython, using the clearer Python 3 semantics.
    """
    import Cython
    from Cython.Build import cythonize
    files = [name.replace('.', os.path.sep) + '.py' for name in modules]
    print("Compiling %d modules using Cython %s" % (len(modules), Cython.__version__))
    return cythonize(files, language_level=3)


print('PRINTING ENVIRON...')
print(os.environ)
if os.getenv('CYTHONIZE_NLTK') == 'true':
    ext_modules = compile_modules(MODULES_TO_COMPILE)
else:
    ext_modules = None

setup(
    name="nltk",
    extras_require=extras_require,
    packages=find_packages(),
    ext_modules=ext_modules,
    zip_safe=False,  # since normal files will be present too?
    entry_points=console_scripts,
)
Run Code Online (Sandbox Code Playgroud)

但是,从CI看来,当tox执行以下操作时CYTHONIZE_NLTK ,无法识别install_command

[5305] /home/travis/build/nltk/nltk$ /home/travis/build/nltk/nltk/.tox/py-cythonized/bin/python -m pip install --exists-action w '/home/travis/build/nltk/nltk/.tox/.tmp/package/1/nltk-3.5.zip[all]'
Run Code Online (Sandbox Code Playgroud)

有关https://travis-ci.org/nltk/nltk/jobs/578224159#L1988的更多详细信息