Repository: jazzband/pip-tools

Issue:
6.0.0 has an undeclared dependency on importlib-metadata at python 3.6
<!-- Describe the issue briefly here. -->

pip-compile from pip-tools 6.0 doesn't work at python 3.6, throws an error about failing to find importlib.metadata

#### Environment Versions

pip-tools 6.0.0, python 3.6.8 are the important ones

#### Steps to replicate

```
[root@72c74788e4f9 /]# python3 -m venv /tmp/pip_tools

[root@72c74788e4f9 /]# source /tmp/pip_tools/bin/activate

(pip_tools) [root@72c74788e4f9 /]# python --version
Python 3.6.8

(pip_tools) [root@72c74788e4f9 /]# pip install pip-tools
Collecting pip-tools
  Downloading https://files.pythonhosted.org/packages/8d/81/15daf8485a9a508ee0fbbc3be328329a96efba8263863eeec331fd7972d9/pip_tools-6.0.0-py3-none-any.whl (43kB)
    100% |████████████████████████████████| 51kB 764kB/s
Collecting click>=7 (from pip-tools)
  Cache entry deserialization failed, entry ignored
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
    100% |████████████████████████████████| 92kB 2.0MB/s
Collecting pip>=20.3 (from pip-tools)
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 879kB/s
Installing collected packages: click, pip, pip-tools
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed click-7.1.2 pip-21.0.1 pip-tools-6.0.0

(pip_tools) [root@72c74788e4f9 /]# pip-compile --help
```
#### Expected result

```
Usage: pip-compile [OPTIONS] [SRC_FILES]...

  Compiles requirements.txt from requirements.in specs.

...
```

#### Actual result

```

Traceback (most recent call last):
  File "/tmp/pip_tools/lib64/python3.6/site-packages/pip/_vendor/pep517/meta.py", line 10, in <module>
    import importlib.metadata as imp_meta
ModuleNotFoundError: No module named 'importlib.metadata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/pip_tools/bin/pip-compile", line 7, in <module>
    from piptools.scripts.compile import cli
  File "/tmp/pip_tools/lib64/python3.6/site-packages/piptools/scripts/compile.py", line 12, in <module>
    from pip._vendor.pep517 import meta
  File "/tmp/pip_tools/lib64/python3.6/site-packages/pip/_vendor/pep517/meta.py", line 12, in <module>
    import importlib_metadata as imp_meta
ModuleNotFoundError: No module named 'importlib_metadata'
```


Discussion:
I have the same issue on my 3.6 projects when they pip-compile.

But, if the import is coming from within pip, wouldn't this be pip's fault, for not depending on this properly when it vendored pep517?

edit: it looks like pep517 [requires importlib_metadata for python<3.8](https://github.com/pypa/pep517/blob/master/pyproject.toml#L13)
pip is not broken, and I expect that pip maintainers would say: if pip-tools chooses to rely on the internals of pip, then it is pip-tools problem to make that work.

(I don't know why pip-tools doesn't depend on pep517 directly, probably there's a good reason)
I see there was discussion on whether or not to use pip's private vendored copy of pep517 at https://github.com/jazzband/pip-tools/pull/1311#discussion_r567360260

FWIW I'm on team prefer-public-APIs, and I think this issue supports that.  But, maintainer's choice!

Resolving patch:
diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -6,10 +6,10 @@
 
 import click
 from click.utils import LazyFile, safecall
+from pep517 import meta
 from pip._internal.commands import create_command
 from pip._internal.req.constructors import install_req_from_line
 from pip._internal.utils.misc import redact_auth_from_url
-from pip._vendor.pep517 import meta
 
 from .._compat import parse_requirements
 from ..cache import DependencyCache


Test patch: