We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
The --target option clashes with other command line flags and config files
The ``--target`` option clashes with several other command like flags and config files like ``--user`` and distutils setup. Ideally we should handle this far more gracefully.

See also #3826, #4106, #562, #4139

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/pip/_internal/utils/setuptools_build.py`
Content:
```
1 import sys
2 from typing import List, Optional, Sequence
3 
4 # Shim to wrap setup.py invocation with setuptools
5 #
6 # We set sys.argv[0] to the path to the underlying setup.py file so
7 # setuptools / distutils don't take the path to the setup.py to be "-c" when
8 # invoking via the shim.  This avoids e.g. the following manifest_maker
9 # warning: "warning: manifest_maker: standard file '-c' not found".
10 _SETUPTOOLS_SHIM = (
11     "import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};"
12     "f=getattr(tokenize, 'open', open)(__file__);"
13     "code=f.read().replace('\\r\\n', '\\n');"
14     "f.close();"
15     "exec(compile(code, __file__, 'exec'))"
16 )
17 
18 
19 def make_setuptools_shim_args(
20     setup_py_path,  # type: str
21     global_options=None,  # type: Sequence[str]
22     no_user_config=False,  # type: bool
23     unbuffered_output=False  # type: bool
24 ):
25     # type: (...) -> List[str]
26     """
27     Get setuptools command arguments with shim wrapped setup file invocation.
28 
29     :param setup_py_path: The path to setup.py to be wrapped.
30     :param global_options: Additional global options.
31     :param no_user_config: If True, disables personal user configuration.
32     :param unbuffered_output: If True, adds the unbuffered switch to the
33      argument list.
34     """
35     args = [sys.executable]
36     if unbuffered_output:
37         args += ["-u"]
38     args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)]
39     if global_options:
40         args += global_options
41     if no_user_config:
42         args += ["--no-user-cfg"]
43     return args
44 
45 
46 def make_setuptools_bdist_wheel_args(
47     setup_py_path,  # type: str
48     global_options,  # type: Sequence[str]
49     build_options,  # type: Sequence[str]
50     destination_dir,  # type: str
51 ):
52     # type: (...) -> List[str]
53     # NOTE: Eventually, we'd want to also -S to the flags here, when we're
54     # isolating. Currently, it breaks Python in virtualenvs, because it
55     # relies on site.py to find parts of the standard library outside the
56     # virtualenv.
57     args = make_setuptools_shim_args(
58         setup_py_path,
59         global_options=global_options,
60         unbuffered_output=True
61     )
62     args += ["bdist_wheel", "-d", destination_dir]
63     args += build_options
64     return args
65 
66 
67 def make_setuptools_clean_args(
68     setup_py_path,  # type: str
69     global_options,  # type: Sequence[str]
70 ):
71     # type: (...) -> List[str]
72     args = make_setuptools_shim_args(
73         setup_py_path,
74         global_options=global_options,
75         unbuffered_output=True
76     )
77     args += ["clean", "--all"]
78     return args
79 
80 
81 def make_setuptools_develop_args(
82     setup_py_path,  # type: str
83     global_options,  # type: Sequence[str]
84     install_options,  # type: Sequence[str]
85     no_user_config,  # type: bool
86     prefix,  # type: Optional[str]
87     home,  # type: Optional[str]
88     use_user_site,  # type: bool
89 ):
90     # type: (...) -> List[str]
91     assert not (use_user_site and prefix)
92 
93     args = make_setuptools_shim_args(
94         setup_py_path,
95         global_options=global_options,
96         no_user_config=no_user_config,
97     )
98 
99     args += ["develop", "--no-deps"]
100 
101     args += install_options
102 
103     if prefix:
104         args += ["--prefix", prefix]
105     if home is not None:
106         args += ["--home", home]
107 
108     if use_user_site:
109         args += ["--user", "--prefix="]
110 
111     return args
112 
113 
114 def make_setuptools_egg_info_args(
115     setup_py_path,  # type: str
116     egg_info_dir,  # type: Optional[str]
117     no_user_config,  # type: bool
118 ):
119     # type: (...) -> List[str]
120     args = make_setuptools_shim_args(
121         setup_py_path, no_user_config=no_user_config
122     )
123 
124     args += ["egg_info"]
125 
126     if egg_info_dir:
127         args += ["--egg-base", egg_info_dir]
128 
129     return args
130 
131 
132 def make_setuptools_install_args(
133     setup_py_path,  # type: str
134     global_options,  # type: Sequence[str]
135     install_options,  # type: Sequence[str]
136     record_filename,  # type: str
137     root,  # type: Optional[str]
138     prefix,  # type: Optional[str]
139     header_dir,  # type: Optional[str]
140     home,  # type: Optional[str]
141     use_user_site,  # type: bool
142     no_user_config,  # type: bool
143     pycompile  # type: bool
144 ):
145     # type: (...) -> List[str]
146     assert not (use_user_site and prefix)
147     assert not (use_user_site and root)
148 
149     args = make_setuptools_shim_args(
150         setup_py_path,
151         global_options=global_options,
152         no_user_config=no_user_config,
153         unbuffered_output=True
154     )
155     args += ["install", "--record", record_filename]
156     args += ["--single-version-externally-managed"]
157 
158     if root is not None:
159         args += ["--root", root]
160     if prefix is not None:
161         args += ["--prefix", prefix]
162     if home is not None:
163         args += ["--home", home]
164     if use_user_site:
165         args += ["--user", "--prefix="]
166 
167     if pycompile:
168         args += ["--compile"]
169     else:
170         args += ["--no-compile"]
171 
172     if header_dir:
173         args += ["--install-headers", header_dir]
174 
175     args += install_options
176 
177     return args
178
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py
--- a/src/pip/_internal/utils/setuptools_build.py
+++ b/src/pip/_internal/utils/setuptools_build.py
@@ -103,7 +103,7 @@
     if prefix:
         args += ["--prefix", prefix]
     if home is not None:
-        args += ["--home", home]
+        args += ["--install-dir", home]
 
     if use_user_site:
         args += ["--user", "--prefix="]

{"golden_diff": "diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py\n--- a/src/pip/_internal/utils/setuptools_build.py\n+++ b/src/pip/_internal/utils/setuptools_build.py\n@@ -103,7 +103,7 @@\n     if prefix:\n         args += [\"--prefix\", prefix]\n     if home is not None:\n-        args += [\"--home\", home]\n+        args += [\"--install-dir\", home]\n \n     if use_user_site:\n         args += [\"--user\", \"--prefix=\"]\n", "issue": "The --target option clashes with other command line flags and config files\nThe ``--target`` option clashes with several other command like flags and config files like ``--user`` and distutils setup. Ideally we should handle this far more gracefully.\r\n\r\nSee also #3826, #4106, #562, #4139\n", "before_files": [{"content": "import sys\nfrom typing import List, Optional, Sequence\n\n# Shim to wrap setup.py invocation with setuptools\n#\n# We set sys.argv[0] to the path to the underlying setup.py file so\n# setuptools / distutils don't take the path to the setup.py to be \"-c\" when\n# invoking via the shim.  This avoids e.g. the following manifest_maker\n# warning: \"warning: manifest_maker: standard file '-c' not found\".\n_SETUPTOOLS_SHIM = (\n    \"import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};\"\n    \"f=getattr(tokenize, 'open', open)(__file__);\"\n    \"code=f.read().replace('\\\\r\\\\n', '\\\\n');\"\n    \"f.close();\"\n    \"exec(compile(code, __file__, 'exec'))\"\n)\n\n\ndef make_setuptools_shim_args(\n    setup_py_path,  # type: str\n    global_options=None,  # type: Sequence[str]\n    no_user_config=False,  # type: bool\n    unbuffered_output=False  # type: bool\n):\n    # type: (...) -> List[str]\n    \"\"\"\n    Get setuptools command arguments with shim wrapped setup file invocation.\n\n    :param setup_py_path: The path to setup.py to be wrapped.\n    :param global_options: Additional global options.\n    :param no_user_config: If True, disables personal user configuration.\n    :param unbuffered_output: If True, adds the unbuffered switch to the\n     argument list.\n    \"\"\"\n    args = [sys.executable]\n    if unbuffered_output:\n        args += [\"-u\"]\n    args += [\"-c\", _SETUPTOOLS_SHIM.format(setup_py_path)]\n    if global_options:\n        args += global_options\n    if no_user_config:\n        args += [\"--no-user-cfg\"]\n    return args\n\n\ndef make_setuptools_bdist_wheel_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    build_options,  # type: Sequence[str]\n    destination_dir,  # type: str\n):\n    # type: (...) -> List[str]\n    # NOTE: Eventually, we'd want to also -S to the flags here, when we're\n    # isolating. Currently, it breaks Python in virtualenvs, because it\n    # relies on site.py to find parts of the standard library outside the\n    # virtualenv.\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        unbuffered_output=True\n    )\n    args += [\"bdist_wheel\", \"-d\", destination_dir]\n    args += build_options\n    return args\n\n\ndef make_setuptools_clean_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n):\n    # type: (...) -> List[str]\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        unbuffered_output=True\n    )\n    args += [\"clean\", \"--all\"]\n    return args\n\n\ndef make_setuptools_develop_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    install_options,  # type: Sequence[str]\n    no_user_config,  # type: bool\n    prefix,  # type: Optional[str]\n    home,  # type: Optional[str]\n    use_user_site,  # type: bool\n):\n    # type: (...) -> List[str]\n    assert not (use_user_site and prefix)\n\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        no_user_config=no_user_config,\n    )\n\n    args += [\"develop\", \"--no-deps\"]\n\n    args += install_options\n\n    if prefix:\n        args += [\"--prefix\", prefix]\n    if home is not None:\n        args += [\"--home\", home]\n\n    if use_user_site:\n        args += [\"--user\", \"--prefix=\"]\n\n    return args\n\n\ndef make_setuptools_egg_info_args(\n    setup_py_path,  # type: str\n    egg_info_dir,  # type: Optional[str]\n    no_user_config,  # type: bool\n):\n    # type: (...) -> List[str]\n    args = make_setuptools_shim_args(\n        setup_py_path, no_user_config=no_user_config\n    )\n\n    args += [\"egg_info\"]\n\n    if egg_info_dir:\n        args += [\"--egg-base\", egg_info_dir]\n\n    return args\n\n\ndef make_setuptools_install_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    install_options,  # type: Sequence[str]\n    record_filename,  # type: str\n    root,  # type: Optional[str]\n    prefix,  # type: Optional[str]\n    header_dir,  # type: Optional[str]\n    home,  # type: Optional[str]\n    use_user_site,  # type: bool\n    no_user_config,  # type: bool\n    pycompile  # type: bool\n):\n    # type: (...) -> List[str]\n    assert not (use_user_site and prefix)\n    assert not (use_user_site and root)\n\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        no_user_config=no_user_config,\n        unbuffered_output=True\n    )\n    args += [\"install\", \"--record\", record_filename]\n    args += [\"--single-version-externally-managed\"]\n\n    if root is not None:\n        args += [\"--root\", root]\n    if prefix is not None:\n        args += [\"--prefix\", prefix]\n    if home is not None:\n        args += [\"--home\", home]\n    if use_user_site:\n        args += [\"--user\", \"--prefix=\"]\n\n    if pycompile:\n        args += [\"--compile\"]\n    else:\n        args += [\"--no-compile\"]\n\n    if header_dir:\n        args += [\"--install-headers\", header_dir]\n\n    args += install_options\n\n    return args\n", "path": "src/pip/_internal/utils/setuptools_build.py"}], "after_files": [{"content": "import sys\nfrom typing import List, Optional, Sequence\n\n# Shim to wrap setup.py invocation with setuptools\n#\n# We set sys.argv[0] to the path to the underlying setup.py file so\n# setuptools / distutils don't take the path to the setup.py to be \"-c\" when\n# invoking via the shim.  This avoids e.g. the following manifest_maker\n# warning: \"warning: manifest_maker: standard file '-c' not found\".\n_SETUPTOOLS_SHIM = (\n    \"import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};\"\n    \"f=getattr(tokenize, 'open', open)(__file__);\"\n    \"code=f.read().replace('\\\\r\\\\n', '\\\\n');\"\n    \"f.close();\"\n    \"exec(compile(code, __file__, 'exec'))\"\n)\n\n\ndef make_setuptools_shim_args(\n    setup_py_path,  # type: str\n    global_options=None,  # type: Sequence[str]\n    no_user_config=False,  # type: bool\n    unbuffered_output=False  # type: bool\n):\n    # type: (...) -> List[str]\n    \"\"\"\n    Get setuptools command arguments with shim wrapped setup file invocation.\n\n    :param setup_py_path: The path to setup.py to be wrapped.\n    :param global_options: Additional global options.\n    :param no_user_config: If True, disables personal user configuration.\n    :param unbuffered_output: If True, adds the unbuffered switch to the\n     argument list.\n    \"\"\"\n    args = [sys.executable]\n    if unbuffered_output:\n        args += [\"-u\"]\n    args += [\"-c\", _SETUPTOOLS_SHIM.format(setup_py_path)]\n    if global_options:\n        args += global_options\n    if no_user_config:\n        args += [\"--no-user-cfg\"]\n    return args\n\n\ndef make_setuptools_bdist_wheel_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    build_options,  # type: Sequence[str]\n    destination_dir,  # type: str\n):\n    # type: (...) -> List[str]\n    # NOTE: Eventually, we'd want to also -S to the flags here, when we're\n    # isolating. Currently, it breaks Python in virtualenvs, because it\n    # relies on site.py to find parts of the standard library outside the\n    # virtualenv.\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        unbuffered_output=True\n    )\n    args += [\"bdist_wheel\", \"-d\", destination_dir]\n    args += build_options\n    return args\n\n\ndef make_setuptools_clean_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n):\n    # type: (...) -> List[str]\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        unbuffered_output=True\n    )\n    args += [\"clean\", \"--all\"]\n    return args\n\n\ndef make_setuptools_develop_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    install_options,  # type: Sequence[str]\n    no_user_config,  # type: bool\n    prefix,  # type: Optional[str]\n    home,  # type: Optional[str]\n    use_user_site,  # type: bool\n):\n    # type: (...) -> List[str]\n    assert not (use_user_site and prefix)\n\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        no_user_config=no_user_config,\n    )\n\n    args += [\"develop\", \"--no-deps\"]\n\n    args += install_options\n\n    if prefix:\n        args += [\"--prefix\", prefix]\n    if home is not None:\n        args += [\"--install-dir\", home]\n\n    if use_user_site:\n        args += [\"--user\", \"--prefix=\"]\n\n    return args\n\n\ndef make_setuptools_egg_info_args(\n    setup_py_path,  # type: str\n    egg_info_dir,  # type: Optional[str]\n    no_user_config,  # type: bool\n):\n    # type: (...) -> List[str]\n    args = make_setuptools_shim_args(\n        setup_py_path, no_user_config=no_user_config\n    )\n\n    args += [\"egg_info\"]\n\n    if egg_info_dir:\n        args += [\"--egg-base\", egg_info_dir]\n\n    return args\n\n\ndef make_setuptools_install_args(\n    setup_py_path,  # type: str\n    global_options,  # type: Sequence[str]\n    install_options,  # type: Sequence[str]\n    record_filename,  # type: str\n    root,  # type: Optional[str]\n    prefix,  # type: Optional[str]\n    header_dir,  # type: Optional[str]\n    home,  # type: Optional[str]\n    use_user_site,  # type: bool\n    no_user_config,  # type: bool\n    pycompile  # type: bool\n):\n    # type: (...) -> List[str]\n    assert not (use_user_site and prefix)\n    assert not (use_user_site and root)\n\n    args = make_setuptools_shim_args(\n        setup_py_path,\n        global_options=global_options,\n        no_user_config=no_user_config,\n        unbuffered_output=True\n    )\n    args += [\"install\", \"--record\", record_filename]\n    args += [\"--single-version-externally-managed\"]\n\n    if root is not None:\n        args += [\"--root\", root]\n    if prefix is not None:\n        args += [\"--prefix\", prefix]\n    if home is not None:\n        args += [\"--home\", home]\n    if use_user_site:\n        args += [\"--user\", \"--prefix=\"]\n\n    if pycompile:\n        args += [\"--compile\"]\n    else:\n        args += [\"--no-compile\"]\n\n    if header_dir:\n        args += [\"--install-headers\", header_dir]\n\n    args += install_options\n\n    return args\n", "path": "src/pip/_internal/utils/setuptools_build.py"}]}