Repository: python-poetry/poetry

Issue:
Save canonical PyPi names in pyproject.toml
<!--
  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/python-poetry/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/python-poetry/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**: <!-- Replace with version + name -->
- **Poetry version**: <!-- Replace with version -->
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: <!-- Gist Link Here -->

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

When running `poetry add` (& other commands) the package names is saved verbatim from the command line instead of the canonical normalised PyPi name.

Current:
`$ poetry add dJaNgO`

`pyproject.toml` contents:
```[tool.poetry]
name = "testproject"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.7"
dJaNgO = "^3.0.3"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```

Expected:
`$ poetry add dJaNgO`

`pyproject.toml` contents:
```[tool.poetry]
name = "testproject"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.7"
Django = "^3.0.3"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```


Discussion:

Resolving patch:
diff --git a/poetry/repositories/pypi_repository.py b/poetry/repositories/pypi_repository.py
--- a/poetry/repositories/pypi_repository.py
+++ b/poetry/repositories/pypi_repository.py
@@ -123,7 +123,7 @@ def find_packages(
                 continue
 
             try:
-                package = Package(name, version)
+                package = Package(info["info"]["name"], version)
             except ParseVersionError:
                 self._log(
                     'Unable to parse version "{}" for the {} package, skipping'.format(


Test patch:
diff --git a/tests/repositories/test_pypi_repository.py b/tests/repositories/test_pypi_repository.py
--- a/tests/repositories/test_pypi_repository.py
+++ b/tests/repositories/test_pypi_repository.py
@@ -215,3 +215,11 @@ def test_urls():
 
     assert "https://pypi.org/simple/" == repository.url
     assert "https://pypi.org/simple/" == repository.authenticated_url
+
+
+def test_use_pypi_pretty_name():
+    repo = MockRepository(fallback=True)
+
+    package = repo.find_packages("twisted")
+    assert len(package) == 1
+    assert package[0].pretty_name == "Twisted"