Repository: pypa/build (python)

Issue:
build uninstalls setuptools even if needed by a dependency
~This is a continuation of #109, although slightly different.~ Not really, `setuptools` is still installed in my `venv` after this happens. So, build isolation is working.

I have a project that uses `flit` as build backend, however some of its dependencies use setuptools as build backend. When I call `python -m build .`, what I observe is:

1. setuptools gets uninstalled
2. Build dependencies are installed
3. Runtime dependencies start being downloaded
4. When it reaches a dependency that needs setuptools, it fails with `No module named 'setuptools'`

Example:

<details>

```
$ python -m build .                                                                                                                                                                                                                                                    
Found existing installation: setuptools 49.2.1                                                                                                                                                                                                                                                                               
Uninstalling setuptools-49.2.1:                                                                                                                                                                                                                                                                                              
  Successfully uninstalled setuptools-49.2.1                                                                                                                                                                                                                                                                                 
Collecting oldest-supported-numpy                                                                                                                                                                                                                                                                                            
  Using cached oldest_supported_numpy-0.8-py3-none-any.whl (3.7 kB)                                                                                                                                                                                                                                                          
Collecting flit_core<3,>=2.0                                                                                                                                                                                                                                                                                                 
  Using cached flit_core-2.3.0-py2.py3-none-any.whl (40 kB)                                                                                                                                                                                                                                                                  
Collecting wheel                                                                                                                                                                                                                                                                                                             
  Using cached wheel-0.36.2-py2.py3-none-any.whl (35 kB) 
Collecting numpy==1.19.3; python_version == "3.9" and platform_python_implementation != "PyPy"                                                                                                                                                                                                                       [79/560]
  Using cached numpy-1.19.3-cp39-cp39-manylinux2010_x86_64.whl (14.9 MB)                                                                                                                                                                                                                                                     
Collecting pytoml                                                                                                                                                                                                                                                                                                            
  Using cached pytoml-0.1.21-py2.py3-none-any.whl (8.5 kB)                                                                                                                                                                                                                                                                   
Installing collected packages: numpy, oldest-supported-numpy, pytoml, flit-core, wheel                                                                                                                                                                                                                                       
Successfully installed flit-core-2.3.0 numpy-1.19.3 oldest-supported-numpy-0.8 pytoml-0.1.21 wheel-0.36.2                                                                                                                                                                                                                    
WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.                                                                                                                                                                                                                                             
You should consider upgrading via the '/tmp/build-env-yoyx_wof/bin/python -m pip install --upgrade pip' command.                                                                                                                                                                                                             
Ignoring pycodestyle: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                  
Ignoring hypothesis: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                   
Ignoring tox: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                          
Ignoring sphinx: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                       
Ignoring coverage: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                     
Ignoring myst-parser: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                  
Ignoring sphinx-gallery: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                               
Ignoring notebook: markers 'extra == "jupyter"' don't match your environment                                                                                                                                                                                                                                                 
Ignoring isort: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                        
Ignoring nbconvert: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                    
Ignoring sphinx-notfound-page: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                         
Ignoring pytest-mypy: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                  
Ignoring sphinx-autoapi: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                               
Ignoring sphinx-rtd-theme: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                             
Ignoring jupytext: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                     
Ignoring pytest-remotedata: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                            
Ignoring nbsphinx: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                     
Ignoring ipywidgets: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                                                                   
Ignoring mypy: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                            
Ignoring pytest-cov: markers 'extra == "dev"' don't match your environment                                                                                                                                                                    
Ignoring black: markers 'extra == "dev"' don't match your environment                                                                                                                                                                         
Ignoring czml3: markers 'extra == "cesium"' don't match your environment                                               
Ignoring pytest: markers 'extra == "dev"' don't match your environment                                                                                                                                                                        
Ignoring pytest-mpl: markers 'extra == "dev"' don't match your environment                                             
Ignoring jupyter-client: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                  
Ignoring ipython: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                                         
Ignoring pytest-doctestplus: markers 'extra == "dev"' don't match your environment                                                                                                                                                                                              
Ignoring sphinx-hoverxref: markers 'extra == "dev"' don't match your environment                                       
Ignoring cached-property: markers 'python_version < "3.8"' don't match your environment                                                                                                                                                                                                                                      
Ignoring ipykernel: markers 'extra == "dev"' don't match your environment                                              
Collecting matplotlib!=3.0.1,>=2.0                                                                                                                                                                                                                                                                                           
  Downloading matplotlib-3.3.4-cp39-cp39-manylinux1_x86_64.whl (11.5 MB)                                               
     |████████████████████████████████| 11.5 MB 1.8 MB/s                                                                                                                                                                                                                                                                     
Collecting astropy<5,>=3.2                                                                                             
  Downloading astropy-4.2-cp39-cp39-manylinux1_x86_64.whl (9.6 MB)                                                     
     |████████████████████████████████| 9.6 MB 1.5 MB/s                                                                                                                                                                                                                         
Collecting numba>=0.46                                                                                                                                                                                                                        
  Using cached numba-0.51.2.tar.gz (2.1 MB)                                                                                                                                                                                                                                                                                  
    ERROR: Command errored out with exit status 1:                                                                                                                                                                                                                                                                           
     command: /tmp/build-env-yoyx_wof/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vpxvqzau/numba/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vpxvqzau/numba/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');
f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-5n_1l6e9                                                                                                                                   
         cwd: /tmp/pip-install-vpxvqzau/numba/                                                                                                                
    Complete output (3 lines):                                                                                         
    Traceback (most recent call last):                 
      File "<string>", line 1, in <module>                                                                             
    ModuleNotFoundError: No module named 'setuptools'                                                                                   
    ----------------------------------------                                                                                            
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.                                                                                                                                                                                                              
WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.                                       
You should consider upgrading via the '/tmp/build-env-yoyx_wof/bin/python -m pip install --upgrade pip' command.                                                                                                                                                                
Traceback (most recent call last):                                                                                                      
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main                                                 
    return _run_code(code, main_globals, None,                                                                         
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code                                                            
    exec(code, run_globals)                                                                                            
  File "/home/juanlu/Personal/poliastro/poliastro/.venv39/lib/python3.9/site-packages/build/__main__.py", line 214, in <module>                                                                                                               
    main(sys.argv[1:], 'python -m build')                                                                              
  File "/home/juanlu/Personal/poliastro/poliastro/.venv39/lib/python3.9/site-packages/build/__main__.py", line 206, in main                                                                                                                   
    build_package(args.srcdir, outdir, distributions, config_settings, not args.no_isolation, args.skip_dependencies)  
  File "/home/juanlu/Personal/poliastro/poliastro/.venv39/lib/python3.9/site-packages/build/__main__.py", line 94, in build_package                                                                                                           
    _build_in_isolated_env(builder, outdir, distributions, config_settings)                   
  File "/home/juanlu/Personal/poliastro/poliastro/.venv39/lib/python3.9/site-packages/build/__main__.py", line 58, in _build_in_isolated_env                                                                                                  
    env.install(builder.get_dependencies(distribution))                                                                
  File "/home/juanlu/Personal/poliastro/poliastro/.venv39/lib/python3.9/site-packages/build/env.py", line 143, in install                                                                                                                     
    subprocess.check_call(cmd)                                                                                         
  File "/usr/lib/python3.9/subprocess.py", line 373, in check_call                                                     
    raise CalledProcessError(retcode, cmd)                                                                             
subprocess.CalledProcessError: Command '['/tmp/build-env-yoyx_wof/bin/python', '-Im', 'pip', 'install', '--no-warn-script-location', '-r', '/tmp/build-reqs-s3r1fubv.txt']' returned non-zero exit status 1.
```

Pull request description:
env: pass --use-pep517 to force build isolation
In #231 we discovered pip is not building some dependencies in
isolation, it is using the build environment, which can become an issue
since we remove setuptools from the environment.

As suggested by @layday, this patch passes --use-pep517 to pip so that
it builds in isolation, as recomended by PEP 517.

Fixes #231

Signed-off-by: Filipe Laíns <lains@riseup.net>

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c6a2b67..7ec4a05 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -7,9 +7,12 @@ Unreleased
 ==========
 
 - Upgrade pip based on venv pip version, avoids error from unrecognised pip flag on Debian Python 3.6.5-3.8 (`PR #229`_, Fixes `#228`_)
+- Build dependencies in isolation, instead of in the build environment (`PR #232`_, Fixes `#231`_)
 
 .. _PR #229: https://github.com/pypa/build/pull/229
 .. _#228: https://github.com/pypa/build/issues/228
+.. _PR #232: https://github.com/pypa/build/pull/232
+.. _#231: https://github.com/pypa/build/issues/231
 
 
 
diff --git a/src/build/__main__.py b/src/build/__main__.py
index 32681c1..864e615 100644
--- a/src/build/__main__.py
+++ b/src/build/__main__.py
@@ -160,7 +160,7 @@ def main_parser():  # type: () -> argparse.ArgumentParser
         '-C',
         action='append',
         help='pass options to the backend.  options which begin with a hyphen must be in the form of '
-        '`--config-setting=--opt(=value)` or `-C--opt(=value)`',
+        '"--config-setting=--opt(=value)" or "-C--opt(=value)"',
     )
     return parser
 
diff --git a/src/build/env.py b/src/build/env.py
index 8d79527..d2f031a 100644
--- a/src/build/env.py
+++ b/src/build/env.py
@@ -143,6 +143,7 @@ class _IsolatedEnvVenvPip(IsolatedEnv):
                 '-{}m'.format('E' if sys.version_info[0] == 2 else 'I'),
                 'pip',
                 'install',
+                '--use-pep517',
                 '--no-warn-script-location',
                 '-r',
                 os.path.abspath(req_file.name),


Test patch:
diff --git a/tests/test_env.py b/tests/test_env.py
index 04f18ab..b9f6742 100644
--- a/tests/test_env.py
+++ b/tests/test_env.py
@@ -42,6 +42,7 @@ def test_isolated_environment_install(mocker):
             '-{}m'.format('E' if sys.version_info[0] == 2 else 'I'),
             'pip',
             'install',
+            '--use-pep517',
             '--no-warn-script-location',
             '-r',
         ]