Skip to content

Commit

Permalink
Lock VCS dev-dependencies as category "dev" (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp authored and sdispater committed Dec 20, 2019
1 parent affe32d commit 9537309
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions poetry/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def add_dependency(
branch=constraint.get("branch", None),
tag=constraint.get("tag", None),
rev=constraint.get("rev", None),
category=category,
optional=optional,
)
elif "file" in constraint:
Expand Down
12 changes: 10 additions & 2 deletions poetry/packages/vcs_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ class VCSDependency(Dependency):
"""

def __init__(
self, name, vcs, source, branch=None, tag=None, rev=None, optional=False
self,
name,
vcs,
source,
branch=None,
tag=None,
rev=None,
category="main",
optional=False,
):
self._vcs = vcs
self._source = source
Expand All @@ -21,7 +29,7 @@ def __init__(
self._rev = rev

super(VCSDependency, self).__init__(
name, "*", optional=optional, allows_prereleases=True
name, "*", category=category, optional=optional, allows_prereleases=True
)

@property
Expand Down
23 changes: 23 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import pytest

from poetry.packages import Package


Expand All @@ -14,3 +16,24 @@ def test_package_authors():
package.authors.insert(0, "John Doe")
assert package.author_name == "John Doe"
assert package.author_email is None


@pytest.mark.parametrize("category", ["main", "dev"])
def test_package_add_dependency_vcs_category(category):
package = Package("foo", "0.1.0")

dependency = package.add_dependency(
"poetry",
constraint={"git": "https://github.com/python-poetry/poetry.git"},
category=category,
)
assert dependency.category == category


def test_package_add_dependency_vcs_category_default_main():
package = Package("foo", "0.1.0")

dependency = package.add_dependency(
"poetry", constraint={"git": "https://github.com/python-poetry/poetry.git"}
)
assert dependency.category == "main"
13 changes: 13 additions & 0 deletions tests/packages/test_vcs_dependency.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from poetry.packages.vcs_dependency import VCSDependency


Expand Down Expand Up @@ -49,3 +51,14 @@ def test_to_pep_508_in_extras():
expected = 'poetry @ git+https://github.com/python-poetry/poetry.git@b;ar; ; extra == "foo;"'

assert expected == dependency.to_pep_508()


@pytest.mark.parametrize("category", ["main", "dev"])
def test_category(category):
dependency = VCSDependency(
"poetry",
"git",
"https://github.com/python-poetry/poetry.git",
category=category,
)
assert category == dependency.category

0 comments on commit 9537309

Please sign in to comment.