简体   繁体   English

当 tox 安装要求时定义超时

[英]Define timeout when tox is installing requirements

I have a gitlab ci pipeline which basically do some stuff on the enviornment ( install python and other packages) then it simply run tox in order to run some tests.我有一个 gitlab ci 管道,它基本上在环境中做一些事情(安装 python 和其他包)然后它只是运行tox以运行一些测试。

stages:
  - check



before_script:
    # here you can run any commands before the pipelines start
    - apt-get -qq update && apt-get -qq install -y python3.9
    - apt-get install -y libpq-dev &&  apt-get install -y python3.9-dev
    - apt-get install -y build-essential && apt-get install -y gcc && apt-get install -y postgresql
    - apt-get install -y  postgresql-contrib && apt-get install -y  ffmpeg libsm6 libxext6
    - apt-get install -y git
    - pip install tox



check:
  stage: check
  image: gitlab.*****.com:****/*****
  environment: prod
  services:
    - name: docker:19.03.8-dind #20.10.7
      alias: docker
  only:
    - master
  script:
    - |
      echo "
      machine gitlab.*****.com
      login gitlab-ci-token
      password $CI_JOB_TOKEN
      " > ~/.netrc 
    - tox

This is my tox.ini :这是我的tox.ini

[tox]
envlist =
    {python3.9}


[testenv]
passenv = *
setenv =
    AIRFLOW_HOME = /airflow_home
deps=
    pytest
    -r{toxinidir}/requirements.txt 
commands=
    pytest 

The problem is that when tox is building the env and installing the packages specified in the requirements.txt it returns a ReadTimeOutError .问题是当tox构建环境并安装requirements.txt中指定的包时,它返回ReadTimeOutError

I've tried to delete tox and simply run a pip install -r requirem.nets --default-timeout=200 and it worked.我试图删除tox并简单地运行pip install -r requirem.nets --default-timeout=200并且它有效。
So the problem seems to be a timeout.所以问题似乎是超时。 I'd like to define a timeout but i don't want to discard tox.我想定义一个timeout ,但我不想丢弃毒物。

How can i do it?我该怎么做?

tox is using pip under the hood, so you can use the same options, preferable as environment variables. tox 在后台使用 pip,因此您可以使用相同的选项,最好作为环境变量。

So, following https://pip.pypa.io/en/stable/topics/configuration/#environment-variables you need to convert --default-timeout into the PIP_DEFAULT_TIMEOUT variable.因此,在https://pip.pypa.io/en/stable/topics/configuration/#environment-variables 之后,您需要将--default-timeout转换为PIP_DEFAULT_TIMEOUT变量。

You can use this variable either by setting it in CI and then use the passenv directive in your tox.ini , or you can set it directly in tox.ini via the setenv directive.您可以通过在 CI 中设置它然后在tox.ini中使用passenv指令来使用此变量,或者您可以通过setenv指令直接在tox.ini中设置它。

Relevant documentation for tox: tox的相关文档:

You can change default install_command :您可以更改默认install_command

install_command = pip install {opts} --default-timeout=200 {packages}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM