We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
poetry appears to be trying to install with the wrong version of pip
<!--
  Hi there! Thank you for discovering and submitting an issue.

  Before you submit this; let's make sure of a few things.
  Please make sure the following boxes are ticked if they are correct.
  If not, please try and fulfill these first.
-->

<!-- Checked checkbox should look like this: [x] -->
- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/sdispater/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

<!--
  Once those are done, if you're able to fill in the following list with your information,
  it'd be very helpful to whoever handles the issue.
-->

- **OS version and name**: Docker image: ubuntu:xenial (as root)
- **Poetry version**: 0.12.10
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: https://gist.github.com/nottrobin/e104b9ec140cae4f403f381ed71b3307

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

In my system, I have both `python` and `pip`, and `python3` and `pip3` commands. (Installed with `apt install python-pip python3-pip`).

I installed poetry with `pip3 install poetry`, and you can see that it's using `python3` as its binary:

``` bash
$ head -n 1 `which poetry`
#!/usr/bin/python3
```

I've also configured it not to create virtualenvs, and I'm running this as root inside a `ubuntu:xenial` docker container.

So now my `poetry install` errors, because it claims not to have python3.5:

``` bash
# poetry install -vvv
Skipping virtualenv creation, as specified in config file.
Installing dependencies from lock file


Package operations: 1 install, 0 updates, 0 removals, 1 skipped

  - Skipping pytz (2018.7) Already installed
  - Installing django (2.1.4)

[EnvCommandError]
Command ['/usr/bin/pip', 'install', '--no-deps', 'django==2.1.4'] errored with the following output:                                           
Collecting django==2.1.4                                                                                                                       
  Using cached https://files.pythonhosted.org/packages/83/f7/4939b60c4127d5f49ccb570e34f4c59ecc222949220234a88e4f363f1456/Django-2.1.4.tar.gz  
    Complete output from command python setup.py egg_info:                                                                                     
                                                                                                                                               
    ==========================                                                                                                                 
    Unsupported Python version                                                                                                                 
    ==========================                                                                                                                 
                                                                                                                                               
    This version of Django requires Python 3.5, but you're trying to                                                                           
    install it on Python 2.7.                                                                                                                  
                                                                                                                                               
    This may be because you are using a version of pip that doesn't                                                                            
    understand the python_requires classifier. Make sure you                                                                                   
    have pip >= 9.0 and setuptools >= 24.2, then try again:                                                                                    
                                                                                                                                               
        $ python -m pip install --upgrade pip setuptools                                                                                       
        $ python -m pip install django                                                                                                         
                                                                                                                                               
    This will install the latest version of Django which works on your                                                                         
    version of Python. If you can't upgrade your pip (or Python), request                                                                      
    an older version of Django:                                                                                                                
                                                                                                                                               
        $ python -m pip install "django<2"                                                                                                     
                                                                                                                                               
    ----------------------------------------                                                                                                   
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dlrX8a/django/                                                   
You are using pip version 8.1.1, however version 18.1 is available.                                                                            
You should consider upgrading via the 'pip install --upgrade pip' command.                                                                     

Exception trace:
 /usr/local/lib/python3.5/dist-packages/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /usr/local/lib/python3.5/dist-packages/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /usr/local/lib/python3.5/dist-packages/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /usr/local/lib/python3.5/dist-packages/poetry/console/commands/command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 /usr/local/lib/python3.5/dist-packages/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /usr/local/lib/python3.5/dist-packages/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /usr/local/lib/python3.5/dist-packages/poetry/console/commands/install.py in handle() at line 57
   return_code = installer.run()
 /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in run() at line 76
   self._do_install(local_repo)
 /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _do_install() at line 287
   self._execute(op)
 /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _execute() at line 295
   getattr(self, "_execute_{}".format(method))(operation)
 /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _execute_install() at line 320
   self._installer.install(operation.package)
 /usr/local/lib/python3.5/dist-packages/poetry/installation/pip_installer.py in install() at line 91
   self.run(*args)
 /usr/local/lib/python3.5/dist-packages/poetry/installation/pip_installer.py in run() at line 112
   return self._env.run("pip", *args, **kwargs)
 /usr/local/lib/python3.5/dist-packages/poetry/utils/env.py in run() at line 354
   raise EnvCommandError(e)

install [--no-dev] [--dry-run] [-E|--extras EXTRAS] [--develop DEVELOP]
```

But:

``` bash
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `poetry/installation/pip_installer.py`
Content:
```
1 import os
2 import shutil
3 import tempfile
4 
5 from subprocess import CalledProcessError
6 
7 from poetry.config import Config
8 from poetry.utils.helpers import get_http_basic_auth
9 from poetry.utils.helpers import safe_rmtree
10 
11 
12 try:
13     import urllib.parse as urlparse
14 except ImportError:
15     import urlparse
16 
17 from poetry.utils._compat import encode
18 from poetry.utils.env import Env
19 
20 from .base_installer import BaseInstaller
21 
22 
23 class PipInstaller(BaseInstaller):
24     def __init__(self, env, io):  # type: (Env, ...) -> None
25         self._env = env
26         self._io = io
27 
28     def install(self, package, update=False):
29         if package.source_type == "directory":
30             self.install_directory(package)
31 
32             return
33 
34         if package.source_type == "git":
35             self.install_git(package)
36 
37             return
38 
39         args = ["install", "--no-deps"]
40 
41         if package.source_type == "legacy" and package.source_url:
42             parsed = urlparse.urlparse(package.source_url)
43             if parsed.scheme == "http":
44                 self._io.write_error(
45                     "    <warning>Installing from unsecure host: {}</warning>".format(
46                         parsed.hostname
47                     )
48                 )
49                 args += ["--trusted-host", parsed.hostname]
50 
51             auth = get_http_basic_auth(
52                 Config.create("auth.toml"), package.source_reference
53             )
54             if auth:
55                 index_url = "{scheme}://{username}:{password}@{netloc}{path}".format(
56                     scheme=parsed.scheme,
57                     username=auth[0],
58                     password=auth[1],
59                     netloc=parsed.netloc,
60                     path=parsed.path,
61                 )
62             else:
63                 index_url = package.source_url
64 
65             args += ["--index-url", index_url]
66 
67         if update:
68             args.append("-U")
69 
70         if package.hashes and not package.source_type:
71             # Format as a requirements.txt
72             # We need to create a requirements.txt file
73             # for each package in order to check hashes.
74             # This is far from optimal but we do not have any
75             # other choice since this is the only way for pip
76             # to verify hashes.
77             req = self.create_temporary_requirement(package)
78             args += ["-r", req]
79 
80             try:
81                 self.run(*args)
82             finally:
83                 os.unlink(req)
84         else:
85             req = self.requirement(package)
86             if not isinstance(req, list):
87                 args.append(req)
88             else:
89                 args += req
90 
91             self.run(*args)
92 
93     def update(self, _, target):
94         self.install(target, update=True)
95 
96     def remove(self, package):
97         # If we have a VCS package, remove its source directory
98         if package.source_type == "git":
99             src_dir = self._env.path / "src" / package.name
100             if src_dir.exists():
101                 safe_rmtree(str(src_dir))
102 
103         try:
104             self.run("uninstall", package.name, "-y")
105         except CalledProcessError as e:
106             if "not installed" in str(e):
107                 return
108 
109             raise
110 
111     def run(self, *args, **kwargs):  # type: (...) -> str
112         return self._env.run("pip", *args, **kwargs)
113 
114     def requirement(self, package, formatted=False):
115         if formatted and not package.source_type:
116             req = "{}=={}".format(package.name, package.version)
117             for h in package.hashes:
118                 req += " --hash sha256:{}".format(h)
119 
120             req += "\n"
121 
122             return req
123 
124         if package.source_type in ["file", "directory"]:
125             if package.root_dir:
126                 req = os.path.join(package.root_dir, package.source_url)
127             else:
128                 req = os.path.realpath(package.source_url)
129 
130             if package.develop and package.source_type == "directory":
131                 req = ["-e", req]
132 
133             return req
134 
135         if package.source_type == "git":
136             return "git+{}@{}#egg={}".format(
137                 package.source_url, package.source_reference, package.name
138             )
139 
140         return "{}=={}".format(package.name, package.version)
141 
142     def create_temporary_requirement(self, package):
143         fd, name = tempfile.mkstemp(
144             "reqs.txt", "{}-{}".format(package.name, package.version)
145         )
146 
147         try:
148             os.write(fd, encode(self.requirement(package, formatted=True)))
149         finally:
150             os.close(fd)
151 
152         return name
153 
154     def install_directory(self, package):
155         from poetry.io import NullIO
156         from poetry.masonry.builder import SdistBuilder
157         from poetry.poetry import Poetry
158         from poetry.utils._compat import decode
159         from poetry.utils.env import NullEnv
160         from poetry.utils.toml_file import TomlFile
161 
162         if package.root_dir:
163             req = os.path.join(package.root_dir, package.source_url)
164         else:
165             req = os.path.realpath(package.source_url)
166 
167         args = ["install", "--no-deps", "-U"]
168 
169         pyproject = TomlFile(os.path.join(req, "pyproject.toml"))
170 
171         has_poetry = False
172         has_build_system = False
173         if pyproject.exists():
174             pyproject_content = pyproject.read()
175             has_poetry = (
176                 "tool" in pyproject_content and "poetry" in pyproject_content["tool"]
177             )
178             # Even if there is a build system specified
179             # pip as of right now does not support it fully
180             # TODO: Check for pip version when proper PEP-517 support lands
181             # has_build_system = ("build-system" in pyproject_content)
182 
183         setup = os.path.join(req, "setup.py")
184         has_setup = os.path.exists(setup)
185         if not has_setup and has_poetry and (package.develop or not has_build_system):
186             # We actually need to rely on creating a temporary setup.py
187             # file since pip, as of this comment, does not support
188             # build-system for editable packages
189             # We also need it for non-PEP-517 packages
190             builder = SdistBuilder(Poetry.create(pyproject.parent), NullEnv(), NullIO())
191 
192             with open(setup, "w") as f:
193                 f.write(decode(builder.build_setup()))
194 
195         if package.develop:
196             args.append("-e")
197 
198         args.append(req)
199 
200         try:
201             return self.run(*args)
202         finally:
203             if not has_setup and os.path.exists(setup):
204                 os.remove(setup)
205 
206     def install_git(self, package):
207         from poetry.packages import Package
208         from poetry.vcs import Git
209 
210         src_dir = self._env.path / "src" / package.name
211         if src_dir.exists():
212             safe_rmtree(str(src_dir))
213 
214         src_dir.parent.mkdir(exist_ok=True)
215 
216         git = Git()
217         git.clone(package.source_url, src_dir)
218         git.checkout(package.source_reference, src_dir)
219 
220         # Now we just need to install from the source directory
221         pkg = Package(package.name, package.version)
222         pkg.source_type = "directory"
223         pkg.source_url = str(src_dir)
224         pkg.develop = True
225 
226         self.install_directory(pkg)
227
```
--- 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/poetry/installation/pip_installer.py b/poetry/installation/pip_installer.py
--- a/poetry/installation/pip_installer.py
+++ b/poetry/installation/pip_installer.py
@@ -109,7 +109,7 @@
             raise
 
     def run(self, *args, **kwargs):  # type: (...) -> str
-        return self._env.run("pip", *args, **kwargs)
+        return self._env.run("python", "-m", "pip", *args, **kwargs)
 
     def requirement(self, package, formatted=False):
         if formatted and not package.source_type:

{"golden_diff": "diff --git a/poetry/installation/pip_installer.py b/poetry/installation/pip_installer.py\n--- a/poetry/installation/pip_installer.py\n+++ b/poetry/installation/pip_installer.py\n@@ -109,7 +109,7 @@\n             raise\n \n     def run(self, *args, **kwargs):  # type: (...) -> str\n-        return self._env.run(\"pip\", *args, **kwargs)\n+        return self._env.run(\"python\", \"-m\", \"pip\", *args, **kwargs)\n \n     def requirement(self, package, formatted=False):\n         if formatted and not package.source_type:\n", "issue": "poetry appears to be trying to install with the wrong version of pip\n<!--\r\n  Hi there! Thank you for discovering and submitting an issue.\r\n\r\n  Before you submit this; let's make sure of a few things.\r\n  Please make sure the following boxes are ticked if they are correct.\r\n  If not, please try and fulfill these first.\r\n-->\r\n\r\n<!-- Checked checkbox should look like this: [x] -->\r\n- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.\r\n- [x] I have searched the [issues](https://github.com/sdispater/poetry/issues) of this repo and believe that this is not a duplicate.\r\n- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).\r\n\r\n<!--\r\n  Once those are done, if you're able to fill in the following list with your information,\r\n  it'd be very helpful to whoever handles the issue.\r\n-->\r\n\r\n- **OS version and name**: Docker image: ubuntu:xenial (as root)\r\n- **Poetry version**: 0.12.10\r\n- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: https://gist.github.com/nottrobin/e104b9ec140cae4f403f381ed71b3307\r\n\r\n## Issue\r\n<!-- Now feel free to write your issue, but please be descriptive! Thanks again \ud83d\ude4c \u2764\ufe0f -->\r\n\r\nIn my system, I have both `python` and `pip`, and `python3` and `pip3` commands. (Installed with `apt install python-pip python3-pip`).\r\n\r\nI installed poetry with `pip3 install poetry`, and you can see that it's using `python3` as its binary:\r\n\r\n``` bash\r\n$ head -n 1 `which poetry`\r\n#!/usr/bin/python3\r\n```\r\n\r\nI've also configured it not to create virtualenvs, and I'm running this as root inside a `ubuntu:xenial` docker container.\r\n\r\nSo now my `poetry install` errors, because it claims not to have python3.5:\r\n\r\n``` bash\r\n# poetry install -vvv\r\nSkipping virtualenv creation, as specified in config file.\r\nInstalling dependencies from lock file\r\n\r\n\r\nPackage operations: 1 install, 0 updates, 0 removals, 1 skipped\r\n\r\n  - Skipping pytz (2018.7) Already installed\r\n  - Installing django (2.1.4)\r\n\r\n[EnvCommandError]\r\nCommand ['/usr/bin/pip', 'install', '--no-deps', 'django==2.1.4'] errored with the following output:                                           \r\nCollecting django==2.1.4                                                                                                                       \r\n  Using cached https://files.pythonhosted.org/packages/83/f7/4939b60c4127d5f49ccb570e34f4c59ecc222949220234a88e4f363f1456/Django-2.1.4.tar.gz  \r\n    Complete output from command python setup.py egg_info:                                                                                     \r\n                                                                                                                                               \r\n    ==========================                                                                                                                 \r\n    Unsupported Python version                                                                                                                 \r\n    ==========================                                                                                                                 \r\n                                                                                                                                               \r\n    This version of Django requires Python 3.5, but you're trying to                                                                           \r\n    install it on Python 2.7.                                                                                                                  \r\n                                                                                                                                               \r\n    This may be because you are using a version of pip that doesn't                                                                            \r\n    understand the python_requires classifier. Make sure you                                                                                   \r\n    have pip >= 9.0 and setuptools >= 24.2, then try again:                                                                                    \r\n                                                                                                                                               \r\n        $ python -m pip install --upgrade pip setuptools                                                                                       \r\n        $ python -m pip install django                                                                                                         \r\n                                                                                                                                               \r\n    This will install the latest version of Django which works on your                                                                         \r\n    version of Python. If you can't upgrade your pip (or Python), request                                                                      \r\n    an older version of Django:                                                                                                                \r\n                                                                                                                                               \r\n        $ python -m pip install \"django<2\"                                                                                                     \r\n                                                                                                                                               \r\n    ----------------------------------------                                                                                                   \r\nCommand \"python setup.py egg_info\" failed with error code 1 in /tmp/pip-build-dlrX8a/django/                                                   \r\nYou are using pip version 8.1.1, however version 18.1 is available.                                                                            \r\nYou should consider upgrading via the 'pip install --upgrade pip' command.                                                                     \r\n\r\nException trace:\r\n /usr/local/lib/python3.5/dist-packages/cleo/application.py in run() at line 94\r\n   status_code = self.do_run(input_, output_)\r\n /usr/local/lib/python3.5/dist-packages/poetry/console/application.py in do_run() at line 88\r\n   return super(Application, self).do_run(i, o)\r\n /usr/local/lib/python3.5/dist-packages/cleo/application.py in do_run() at line 197\r\n   status_code = command.run(input_, output_)\r\n /usr/local/lib/python3.5/dist-packages/poetry/console/commands/command.py in run() at line 77\r\n   return super(BaseCommand, self).run(i, o)\r\n /usr/local/lib/python3.5/dist-packages/cleo/commands/base_command.py in run() at line 146\r\n   status_code = self.execute(input_, output_)\r\n /usr/local/lib/python3.5/dist-packages/cleo/commands/command.py in execute() at line 107\r\n   return self.handle()\r\n /usr/local/lib/python3.5/dist-packages/poetry/console/commands/install.py in handle() at line 57\r\n   return_code = installer.run()\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in run() at line 76\r\n   self._do_install(local_repo)\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _do_install() at line 287\r\n   self._execute(op)\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _execute() at line 295\r\n   getattr(self, \"_execute_{}\".format(method))(operation)\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _execute_install() at line 320\r\n   self._installer.install(operation.package)\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/pip_installer.py in install() at line 91\r\n   self.run(*args)\r\n /usr/local/lib/python3.5/dist-packages/poetry/installation/pip_installer.py in run() at line 112\r\n   return self._env.run(\"pip\", *args, **kwargs)\r\n /usr/local/lib/python3.5/dist-packages/poetry/utils/env.py in run() at line 354\r\n   raise EnvCommandError(e)\r\n\r\ninstall [--no-dev] [--dry-run] [-E|--extras EXTRAS] [--develop DEVELOP]\r\n```\r\n\r\nBut:\r\n\r\n``` bash\r\n$ python3 --version\r\nPython 3.5.2\r\n$ pip3 --version\r\npip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)\r\n```\r\n\n", "before_files": [{"content": "import os\nimport shutil\nimport tempfile\n\nfrom subprocess import CalledProcessError\n\nfrom poetry.config import Config\nfrom poetry.utils.helpers import get_http_basic_auth\nfrom poetry.utils.helpers import safe_rmtree\n\n\ntry:\n    import urllib.parse as urlparse\nexcept ImportError:\n    import urlparse\n\nfrom poetry.utils._compat import encode\nfrom poetry.utils.env import Env\n\nfrom .base_installer import BaseInstaller\n\n\nclass PipInstaller(BaseInstaller):\n    def __init__(self, env, io):  # type: (Env, ...) -> None\n        self._env = env\n        self._io = io\n\n    def install(self, package, update=False):\n        if package.source_type == \"directory\":\n            self.install_directory(package)\n\n            return\n\n        if package.source_type == \"git\":\n            self.install_git(package)\n\n            return\n\n        args = [\"install\", \"--no-deps\"]\n\n        if package.source_type == \"legacy\" and package.source_url:\n            parsed = urlparse.urlparse(package.source_url)\n            if parsed.scheme == \"http\":\n                self._io.write_error(\n                    \"    <warning>Installing from unsecure host: {}</warning>\".format(\n                        parsed.hostname\n                    )\n                )\n                args += [\"--trusted-host\", parsed.hostname]\n\n            auth = get_http_basic_auth(\n                Config.create(\"auth.toml\"), package.source_reference\n            )\n            if auth:\n                index_url = \"{scheme}://{username}:{password}@{netloc}{path}\".format(\n                    scheme=parsed.scheme,\n                    username=auth[0],\n                    password=auth[1],\n                    netloc=parsed.netloc,\n                    path=parsed.path,\n                )\n            else:\n                index_url = package.source_url\n\n            args += [\"--index-url\", index_url]\n\n        if update:\n            args.append(\"-U\")\n\n        if package.hashes and not package.source_type:\n            # Format as a requirements.txt\n            # We need to create a requirements.txt file\n            # for each package in order to check hashes.\n            # This is far from optimal but we do not have any\n            # other choice since this is the only way for pip\n            # to verify hashes.\n            req = self.create_temporary_requirement(package)\n            args += [\"-r\", req]\n\n            try:\n                self.run(*args)\n            finally:\n                os.unlink(req)\n        else:\n            req = self.requirement(package)\n            if not isinstance(req, list):\n                args.append(req)\n            else:\n                args += req\n\n            self.run(*args)\n\n    def update(self, _, target):\n        self.install(target, update=True)\n\n    def remove(self, package):\n        # If we have a VCS package, remove its source directory\n        if package.source_type == \"git\":\n            src_dir = self._env.path / \"src\" / package.name\n            if src_dir.exists():\n                safe_rmtree(str(src_dir))\n\n        try:\n            self.run(\"uninstall\", package.name, \"-y\")\n        except CalledProcessError as e:\n            if \"not installed\" in str(e):\n                return\n\n            raise\n\n    def run(self, *args, **kwargs):  # type: (...) -> str\n        return self._env.run(\"pip\", *args, **kwargs)\n\n    def requirement(self, package, formatted=False):\n        if formatted and not package.source_type:\n            req = \"{}=={}\".format(package.name, package.version)\n            for h in package.hashes:\n                req += \" --hash sha256:{}\".format(h)\n\n            req += \"\\n\"\n\n            return req\n\n        if package.source_type in [\"file\", \"directory\"]:\n            if package.root_dir:\n                req = os.path.join(package.root_dir, package.source_url)\n            else:\n                req = os.path.realpath(package.source_url)\n\n            if package.develop and package.source_type == \"directory\":\n                req = [\"-e\", req]\n\n            return req\n\n        if package.source_type == \"git\":\n            return \"git+{}@{}#egg={}\".format(\n                package.source_url, package.source_reference, package.name\n            )\n\n        return \"{}=={}\".format(package.name, package.version)\n\n    def create_temporary_requirement(self, package):\n        fd, name = tempfile.mkstemp(\n            \"reqs.txt\", \"{}-{}\".format(package.name, package.version)\n        )\n\n        try:\n            os.write(fd, encode(self.requirement(package, formatted=True)))\n        finally:\n            os.close(fd)\n\n        return name\n\n    def install_directory(self, package):\n        from poetry.io import NullIO\n        from poetry.masonry.builder import SdistBuilder\n        from poetry.poetry import Poetry\n        from poetry.utils._compat import decode\n        from poetry.utils.env import NullEnv\n        from poetry.utils.toml_file import TomlFile\n\n        if package.root_dir:\n            req = os.path.join(package.root_dir, package.source_url)\n        else:\n            req = os.path.realpath(package.source_url)\n\n        args = [\"install\", \"--no-deps\", \"-U\"]\n\n        pyproject = TomlFile(os.path.join(req, \"pyproject.toml\"))\n\n        has_poetry = False\n        has_build_system = False\n        if pyproject.exists():\n            pyproject_content = pyproject.read()\n            has_poetry = (\n                \"tool\" in pyproject_content and \"poetry\" in pyproject_content[\"tool\"]\n            )\n            # Even if there is a build system specified\n            # pip as of right now does not support it fully\n            # TODO: Check for pip version when proper PEP-517 support lands\n            # has_build_system = (\"build-system\" in pyproject_content)\n\n        setup = os.path.join(req, \"setup.py\")\n        has_setup = os.path.exists(setup)\n        if not has_setup and has_poetry and (package.develop or not has_build_system):\n            # We actually need to rely on creating a temporary setup.py\n            # file since pip, as of this comment, does not support\n            # build-system for editable packages\n            # We also need it for non-PEP-517 packages\n            builder = SdistBuilder(Poetry.create(pyproject.parent), NullEnv(), NullIO())\n\n            with open(setup, \"w\") as f:\n                f.write(decode(builder.build_setup()))\n\n        if package.develop:\n            args.append(\"-e\")\n\n        args.append(req)\n\n        try:\n            return self.run(*args)\n        finally:\n            if not has_setup and os.path.exists(setup):\n                os.remove(setup)\n\n    def install_git(self, package):\n        from poetry.packages import Package\n        from poetry.vcs import Git\n\n        src_dir = self._env.path / \"src\" / package.name\n        if src_dir.exists():\n            safe_rmtree(str(src_dir))\n\n        src_dir.parent.mkdir(exist_ok=True)\n\n        git = Git()\n        git.clone(package.source_url, src_dir)\n        git.checkout(package.source_reference, src_dir)\n\n        # Now we just need to install from the source directory\n        pkg = Package(package.name, package.version)\n        pkg.source_type = \"directory\"\n        pkg.source_url = str(src_dir)\n        pkg.develop = True\n\n        self.install_directory(pkg)\n", "path": "poetry/installation/pip_installer.py"}], "after_files": [{"content": "import os\nimport shutil\nimport tempfile\n\nfrom subprocess import CalledProcessError\n\nfrom poetry.config import Config\nfrom poetry.utils.helpers import get_http_basic_auth\nfrom poetry.utils.helpers import safe_rmtree\n\n\ntry:\n    import urllib.parse as urlparse\nexcept ImportError:\n    import urlparse\n\nfrom poetry.utils._compat import encode\nfrom poetry.utils.env import Env\n\nfrom .base_installer import BaseInstaller\n\n\nclass PipInstaller(BaseInstaller):\n    def __init__(self, env, io):  # type: (Env, ...) -> None\n        self._env = env\n        self._io = io\n\n    def install(self, package, update=False):\n        if package.source_type == \"directory\":\n            self.install_directory(package)\n\n            return\n\n        if package.source_type == \"git\":\n            self.install_git(package)\n\n            return\n\n        args = [\"install\", \"--no-deps\"]\n\n        if package.source_type == \"legacy\" and package.source_url:\n            parsed = urlparse.urlparse(package.source_url)\n            if parsed.scheme == \"http\":\n                self._io.write_error(\n                    \"    <warning>Installing from unsecure host: {}</warning>\".format(\n                        parsed.hostname\n                    )\n                )\n                args += [\"--trusted-host\", parsed.hostname]\n\n            auth = get_http_basic_auth(\n                Config.create(\"auth.toml\"), package.source_reference\n            )\n            if auth:\n                index_url = \"{scheme}://{username}:{password}@{netloc}{path}\".format(\n                    scheme=parsed.scheme,\n                    username=auth[0],\n                    password=auth[1],\n                    netloc=parsed.netloc,\n                    path=parsed.path,\n                )\n            else:\n                index_url = package.source_url\n\n            args += [\"--index-url\", index_url]\n\n        if update:\n            args.append(\"-U\")\n\n        if package.hashes and not package.source_type:\n            # Format as a requirements.txt\n            # We need to create a requirements.txt file\n            # for each package in order to check hashes.\n            # This is far from optimal but we do not have any\n            # other choice since this is the only way for pip\n            # to verify hashes.\n            req = self.create_temporary_requirement(package)\n            args += [\"-r\", req]\n\n            try:\n                self.run(*args)\n            finally:\n                os.unlink(req)\n        else:\n            req = self.requirement(package)\n            if not isinstance(req, list):\n                args.append(req)\n            else:\n                args += req\n\n            self.run(*args)\n\n    def update(self, _, target):\n        self.install(target, update=True)\n\n    def remove(self, package):\n        # If we have a VCS package, remove its source directory\n        if package.source_type == \"git\":\n            src_dir = self._env.path / \"src\" / package.name\n            if src_dir.exists():\n                safe_rmtree(str(src_dir))\n\n        try:\n            self.run(\"uninstall\", package.name, \"-y\")\n        except CalledProcessError as e:\n            if \"not installed\" in str(e):\n                return\n\n            raise\n\n    def run(self, *args, **kwargs):  # type: (...) -> str\n        return self._env.run(\"python\", \"-m\", \"pip\", *args, **kwargs)\n\n    def requirement(self, package, formatted=False):\n        if formatted and not package.source_type:\n            req = \"{}=={}\".format(package.name, package.version)\n            for h in package.hashes:\n                req += \" --hash sha256:{}\".format(h)\n\n            req += \"\\n\"\n\n            return req\n\n        if package.source_type in [\"file\", \"directory\"]:\n            if package.root_dir:\n                req = os.path.join(package.root_dir, package.source_url)\n            else:\n                req = os.path.realpath(package.source_url)\n\n            if package.develop and package.source_type == \"directory\":\n                req = [\"-e\", req]\n\n            return req\n\n        if package.source_type == \"git\":\n            return \"git+{}@{}#egg={}\".format(\n                package.source_url, package.source_reference, package.name\n            )\n\n        return \"{}=={}\".format(package.name, package.version)\n\n    def create_temporary_requirement(self, package):\n        fd, name = tempfile.mkstemp(\n            \"reqs.txt\", \"{}-{}\".format(package.name, package.version)\n        )\n\n        try:\n            os.write(fd, encode(self.requirement(package, formatted=True)))\n        finally:\n            os.close(fd)\n\n        return name\n\n    def install_directory(self, package):\n        from poetry.io import NullIO\n        from poetry.masonry.builder import SdistBuilder\n        from poetry.poetry import Poetry\n        from poetry.utils._compat import decode\n        from poetry.utils.env import NullEnv\n        from poetry.utils.toml_file import TomlFile\n\n        if package.root_dir:\n            req = os.path.join(package.root_dir, package.source_url)\n        else:\n            req = os.path.realpath(package.source_url)\n\n        args = [\"install\", \"--no-deps\", \"-U\"]\n\n        pyproject = TomlFile(os.path.join(req, \"pyproject.toml\"))\n\n        has_poetry = False\n        has_build_system = False\n        if pyproject.exists():\n            pyproject_content = pyproject.read()\n            has_poetry = (\n                \"tool\" in pyproject_content and \"poetry\" in pyproject_content[\"tool\"]\n            )\n            # Even if there is a build system specified\n            # pip as of right now does not support it fully\n            # TODO: Check for pip version when proper PEP-517 support lands\n            # has_build_system = (\"build-system\" in pyproject_content)\n\n        setup = os.path.join(req, \"setup.py\")\n        has_setup = os.path.exists(setup)\n        if not has_setup and has_poetry and (package.develop or not has_build_system):\n            # We actually need to rely on creating a temporary setup.py\n            # file since pip, as of this comment, does not support\n            # build-system for editable packages\n            # We also need it for non-PEP-517 packages\n            builder = SdistBuilder(Poetry.create(pyproject.parent), NullEnv(), NullIO())\n\n            with open(setup, \"w\") as f:\n                f.write(decode(builder.build_setup()))\n\n        if package.develop:\n            args.append(\"-e\")\n\n        args.append(req)\n\n        try:\n            return self.run(*args)\n        finally:\n            if not has_setup and os.path.exists(setup):\n                os.remove(setup)\n\n    def install_git(self, package):\n        from poetry.packages import Package\n        from poetry.vcs import Git\n\n        src_dir = self._env.path / \"src\" / package.name\n        if src_dir.exists():\n            safe_rmtree(str(src_dir))\n\n        src_dir.parent.mkdir(exist_ok=True)\n\n        git = Git()\n        git.clone(package.source_url, src_dir)\n        git.checkout(package.source_reference, src_dir)\n\n        # Now we just need to install from the source directory\n        pkg = Package(package.name, package.version)\n        pkg.source_type = \"directory\"\n        pkg.source_url = str(src_dir)\n        pkg.develop = True\n\n        self.install_directory(pkg)\n", "path": "poetry/installation/pip_installer.py"}]}