Repository: pypa/virtualenv

Issue:
`.dist-info.virtualenv` marker files break importlib.metadata in app-data seeded venvs
Since virtualenv 20.0.0, dist-info directories in virtual environments seeded using the `app-data` method are accompanied by empty marker files with the same name as the directory plus a `.virtualenv` suffix:

https://github.com/pypa/virtualenv/blob/c8ac632cd40bfb014515151a02d1ea55d47ff467/src/virtualenv/seed/via_app_data/pip_install/base.py#L73-L76

This breaks `importlib.metadata`, which picks these files up and attempts to create `importlib.metadata.Distribution` instances for them. As a result, something like `importlib.metadata.version("pip")` will return `None`.

The following session was run in a virtual environment created by virtualenv 20.0.2 inside a `python:3.8.1` Docker image:

```python
Python 3.8.1 (default, Feb  2 2020, 08:37:37)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.metadata
>>> for d in importlib.metadata.distributions():
...     name = d.metadata["name"]
...     version = d.metadata["version"]
...     path = d._path
...     print(f"{path=} {name=} {version=}")
...
path=PosixPath('/venv/lib/python3.8/site-packages/pip-20.0.2.dist-info.virtualenv') name=None version=None
path=PosixPath('/venv/lib/python3.8/site-packages/wheel-0.34.2.dist-info.virtualenv') name=None version=None
path=PosixPath('/venv/lib/python3.8/site-packages/pip-20.0.2.dist-info') name='pip' version='20.0.2'
path=PosixPath('/venv/lib/python3.8/site-packages/wheel-0.34.2.dist-info') name='wheel' version='0.34.2'
path=PosixPath('/venv/lib/python3.8/site-packages/setuptools-45.2.0.dist-info') name='setuptools' version='45.2.0'
path=PosixPath('/venv/lib/python3.8/site-packages/setuptools-45.2.0.dist-info.virtualenv') name=None version=None
>>> d = importlib.metadata.distribution("pip")
>>> d.metadata["name"]
>>> importlib.metadata.version("pip")
>>>
```

This may in fact be an issue in `importlib.metadata`. I'm reporting it here in the assumption that virtualenv may be able to fix or work around this issue faster, and that it would need to work around the issue anyway for Python 3.8.0 and 3.8.1.

The issue also causes Poetry to break when invoked inside such virtual environments, for example in Nox and tox: https://github.com/python-poetry/poetry/issues/1953. This is currently affecting projects that use Poetry in their CI pipelines.


Discussion:
This indeed is a really bad choice of name on our side; will create a PR to fix this (which will land today).

Resolving patch:
diff --git a/src/virtualenv/seed/via_app_data/pip_install/base.py b/src/virtualenv/seed/via_app_data/pip_install/base.py
--- a/src/virtualenv/seed/via_app_data/pip_install/base.py
+++ b/src/virtualenv/seed/via_app_data/pip_install/base.py
@@ -70,9 +70,8 @@ def _generate_new_files(self):
         installer = self._dist_info / "INSTALLER"
         installer.write_text("pip\n")
         new_files.add(installer)
-        # inject a no-op root element, as workaround for bug added
-        # by https://github.com/pypa/pip/commit/c7ae06c79#r35523722
-        marker = self._image_dir / "{}.virtualenv".format(self._dist_info.name)
+        # inject a no-op root element, as workaround for bug in https://github.com/pypa/pip/issues/7226
+        marker = self._image_dir / "{}.virtualenv".format(self._dist_info.stem)
         marker.write_text("")
         new_files.add(marker)
         folder = mkdtemp()


Test patch: