Skip to content

Commit

Permalink
dependency: mark unstable releases as prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Apr 22, 2021
1 parent 44167a5 commit 0fd722c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
29 changes: 16 additions & 13 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
from typing import Optional
from typing import Union

from poetry.core.packages.constraints import (
parse_constraint as parse_generic_constraint,
)
from poetry.core.packages.specification import PackageSpecification
from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version_range_constraint import VersionRangeConstraint
from poetry.core.version.markers import parse_marker

from .constraints import parse_constraint as parse_generic_constraint
from .specification import PackageSpecification


if TYPE_CHECKING:
from poetry.core.semver.helpers import VersionTypes # noqa
from poetry.core.version.markers import BaseMarker # noqa

from .constraints import BaseConstraint # noqa
from .directory_dependency import DirectoryDependency # noqa
from .file_dependency import FileDependency # noqa
from .package import Package
from .types import DependencyTypes
from poetry.core.packages.constraints import BaseConstraint
from poetry.core.packages.directory_dependency import DirectoryDependency
from poetry.core.packages.file_dependency import FileDependency
from poetry.core.packages.package import Package
from poetry.core.packages.types import DependencyTypes
from poetry.core.semver.helpers import VersionTypes
from poetry.core.version.markers import BaseMarker


class Dependency(PackageSpecification):
Expand All @@ -41,7 +42,6 @@ def __init__(
source_reference: Optional[str] = None,
source_resolved_reference: Optional[str] = None,
):
from poetry.core.semver.version_range import VersionRange
from poetry.core.version.markers import AnyMarker

super(Dependency, self).__init__(
Expand All @@ -60,7 +60,10 @@ def __init__(
self._optional = optional
self._category = category

if isinstance(self._constraint, VersionRange) and self._constraint.min:
if (
isinstance(self._constraint, VersionRangeConstraint)
and self._constraint.min
):
allows_prereleases = (
allows_prereleases or self._constraint.min.is_unstable()
)
Expand Down
17 changes: 17 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ def test_accepts():
assert dependency.accepts(package)


@pytest.mark.parametrize(
"constraint,result",
[
("^1.0", False),
("^1.0.dev0", True),
("^1.0.0", False),
("^1.0.0.dev0", True),
("^1.0.0.alpha0", True),
("^1.0.0.alpha0+local", True),
("^1.0.0.rc0+local", True),
("^1.0.0-1", False),
],
)
def test_allows_prerelease(constraint, result):
assert Dependency("A", constraint).allows_prereleases() == result


def test_accepts_prerelease():
dependency = Dependency("A", "^1.0", allows_prereleases=True)
package = Package("A", "1.4-beta.1")
Expand Down

0 comments on commit 0fd722c

Please sign in to comment.