Repository: python-poetry/poetry

Issue:
Optional URL dependency is locked as non-optional
<!--
  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**: Ubuntu 18.04
- **Poetry version**: 1.0.5
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: See reproduction below.

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

When adding an optional URL dependency to the project, I specify it like so:

```toml
[tool.poetry.dependencies]
rethinkdb = { optional = true, url = "https://github.com/tommilligan/rethinkdb-python/releases/download/v2.4.5.post1/rethinkdb-2.4.5.post1-py2.py3-none-any.whl" }
```

However, after locking, this results in a lockfile like:

```toml
[[package]]
category = "main"
description = "Python driver library for the RethinkDB database server."
name = "rethinkdb"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "2.4.5.post1"

[package.dependencies]
six = "*"
```

Note that the lock marks this package as **`optional = false`**. I would expect this to be **`true`**.





Discussion:

Resolving patch:
diff --git a/poetry/packages/package.py b/poetry/packages/package.py
--- a/poetry/packages/package.py
+++ b/poetry/packages/package.py
@@ -333,7 +333,9 @@ def add_dependency(
                         develop=constraint.get("develop", True),
                     )
             elif "url" in constraint:
-                dependency = URLDependency(name, constraint["url"], category=category)
+                dependency = URLDependency(
+                    name, constraint["url"], category=category, optional=optional
+                )
             else:
                 version = constraint["version"]
 


Test patch:
diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py
--- a/tests/packages/test_package.py
+++ b/tests/packages/test_package.py
@@ -49,3 +49,20 @@ def test_package_add_dependency_vcs_category_default_main():
         "poetry", constraint={"git": "https://github.com/python-poetry/poetry.git"}
     )
     assert dependency.category == "main"
+
+
+@pytest.mark.parametrize("category", ["main", "dev"])
+@pytest.mark.parametrize("optional", [True, False])
+def test_package_url_category_optional(category, optional):
+    package = Package("foo", "0.1.0")
+
+    dependency = package.add_dependency(
+        "poetry",
+        constraint={
+            "url": "https://github.com/python-poetry/poetry/releases/download/1.0.5/poetry-1.0.5-linux.tar.gz",
+            "optional": optional,
+        },
+        category=category,
+    )
+    assert dependency.category == category
+    assert dependency.is_optional() == optional