DataDog / riot

A Python virtual env builder and command runner
https://ddriot.readthedocs.io/
Apache License 2.0
23 stars 15 forks source link

Error joining sub-envs paths #193

Open avara1986 opened 1 year ago

avara1986 commented 1 year ago

riot has an error with multiple virtualenvs paths, raising unexpected ImportErrors, an example of this behavior is with backport modules. Steps to reproduce the error:

Files

riotfile.py file:

from riot import Venv
from riot import latest

venv = Venv(
    pkgs={
        "mock": latest,
    },
    venvs=[
        Venv(
            name="test_error",
            pys=["2.7"],
            command="python {cmdargs} test_riot_error/prueba.py",
            pkgs={
                "six": latest,
                "django": latest,
                "django-import-export": latest,
            },
            venvs=[
                Venv(
                    pys=["2.7"],
                    command="python {cmdargs} test_riot_error/test_error.py",
                    pkgs={
                        "importlib_metadata": "<=1.4.0",
                        "backports.shutil-get-terminal-size": latest,
                    },
                ),
            ]
        ),
        Venv(
            pys=["2.7"],
            name="test_ok",
            command="python {cmdargs} test_riot_error/test_error.py",
            venvs=[
                Venv(
                    pys=["2.7"],
                    command="python {cmdargs} test_riot_error/test_error.py",
                    pkgs={
                        "django-import-export": ">=1.2.0",
                        "importlib_metadata": "<=1.4.0",
                    },
                ),
            ]

        )
    ]
)

test_riot_error/test_error.py file:

import importlib_metadata

print("importlib_metadata")
print(importlib_metadata)

Run riot

riot -v run -r

x test_error: [190db53]  pythonInterpreter(_hint='2.7') 'mock' 'six' 'django' 'django-import-export' 'importlib_metadata<=1.4.0' 'backports.shutil-get-terminal-size'
✓ test_ok: [84035a7]  pythonInterpreter(_hint='2.7') 'mock' 'django-import-export>=1.2.0' 'importlib_metadata<=1.4.0'

Error:

Traceback (most recent call last):
  File "test_riot_error/prueba.py", line 1, in <module>
    import importlib_metadata
  File "/home/alberto.vara/projects/system-tests/.riot/venv_py2718_importlib_metadata140_backportsshutil-get-terminal-size/lib/python2.7/site-packages/importlib_metadata/__init__.py", line 16, in <module>
    from ._compat import (
  File "/home/alberto.vara/projects/system-tests/.riot/venv_py2718_importlib_metadata140_backportsshutil-get-terminal-size/lib/python2.7/site-packages/importlib_metadata/_compat.py", line 19, in <module>
    from backports.configparser import ConfigParser
ImportError: No module named configparser

Virtualenvs paths:

.riot/venv_py2718_django-import-export120_importlib_metadata140/lib/python2.7/site-packages/backports/
├── configparser
│   ├── helpers.py
│   ├── helpers.pyc
│   ├── __init__.py
│   └── __init__.pyc
├── csv.py
├── csv.pyc
├── __init__.py
└── __init__.pyc
.riot/venv_py2718_importlib_metadata140_backportsshutil-get-terminal-size/lib/python2.7/site-packages/backports
├── configparser
│   ├── helpers.py
│   ├── helpers.pyc
│   ├── __init__.py
│   └── __init__.pyc
├── __init__.py
├── __init__.pyc
└── shutil_get_terminal_size
    ├── get_terminal_size.py
    ├── get_terminal_size.pyc
    ├── __init__.py
    └── __init__.pyc
.riot/venv_py2718_six_django_django-import-export/lib/python2.7/site-packages/backports
├── csv.py
└── csv.pyc

Issue detected in this PR https://github.com/DataDog/dd-trace-py/pull/4514