From 0e7e8208281670d36df937fc6bd42c4cea165b3b Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Thu, 28 Nov 2019 18:07:37 -0500 Subject: [PATCH 1/3] do not write empty or any markers --- poetry/version/markers.py | 10 ++++++++- tests/version/test_markers.py | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/poetry/version/markers.py b/poetry/version/markers.py index 28b0bb74861..f8437348c05 100644 --- a/poetry/version/markers.py +++ b/poetry/version/markers.py @@ -628,7 +628,15 @@ def __hash__(self): return h def __str__(self): - return " or ".join(str(m) for m in self._markers) + return " or ".join( + str(m) for m in self._markers if not m.is_any() and not m.is_empty() + ) + + def is_any(self): + return all(m.is_any() for m in self._markers) + + def is_empty(self): + return all(m.is_empty() for m in self._markers) def parse_marker(marker): diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 382890e2e06..edd6e174f9d 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -354,6 +354,46 @@ def test_marker_union_union_duplicates(): ) +def test_marker_union_all_any(): + union = MarkerUnion(parse_marker(""), parse_marker("")) + + assert union.is_any() + + +def test_marker_union_not_all_any(): + union = MarkerUnion(parse_marker(""), parse_marker(""), parse_marker("")) + + assert not union.is_any() + + +def test_marker_union_all_empty(): + union = MarkerUnion(parse_marker(""), parse_marker("")) + + assert union.is_empty() + + +def test_marker_union_not_all_empty(): + union = MarkerUnion( + parse_marker(""), parse_marker(""), parse_marker("") + ) + + assert not union.is_empty() + + +def test_marker_str_conversion_skips_empty_and_any(): + union = MarkerUnion( + parse_marker(""), + parse_marker( + 'sys_platform == "darwin" or python_version <= "3.6" or os_name == "Windows"' + ), + parse_marker(""), + ) + + assert str(union) == ( + 'sys_platform == "darwin" or python_version <= "3.6" or os_name == "Windows"' + ) + + def test_intersect_compacts_constraints(): m = parse_marker('python_version < "4.0"') From ac1aab10a6bc0522d2beaba9f3643112df17a295 Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Fri, 6 Dec 2019 11:39:12 -0500 Subject: [PATCH 2/3] Update poetry/version/markers.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Sébastien Eustace --- poetry/version/markers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry/version/markers.py b/poetry/version/markers.py index f8437348c05..d9d3b7d2767 100644 --- a/poetry/version/markers.py +++ b/poetry/version/markers.py @@ -633,7 +633,7 @@ def __str__(self): ) def is_any(self): - return all(m.is_any() for m in self._markers) + return any(m.is_any() for m in self._markers) def is_empty(self): return all(m.is_empty() for m in self._markers) From 9c61874e1318107e5a0b86efe56b8a1ba2f02842 Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Fri, 6 Dec 2019 11:40:04 -0500 Subject: [PATCH 3/3] Update test_markers.py --- tests/version/test_markers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index edd6e174f9d..b8ec7356d6c 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -363,7 +363,7 @@ def test_marker_union_all_any(): def test_marker_union_not_all_any(): union = MarkerUnion(parse_marker(""), parse_marker(""), parse_marker("")) - assert not union.is_any() + assert union.is_any() def test_marker_union_all_empty():