From 54fed2ac689a9548875999da5741230741059a52 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Fri, 8 Feb 2019 22:03:14 +0100 Subject: [PATCH 1/3] Fix #221 Don't flattened_basedirs on Windows Splitting paths on Windows by : is not a good idea. Since it looks like this C:\\something. That is why we disable this feature on Windows. Signed-off-by: fliiiix --- docs/commandline.rst | 1 + radish/utils.py | 3 +++ tests/unit/test_utils.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/commandline.rst b/docs/commandline.rst index beb974c4..9aa11a33 100644 --- a/docs/commandline.rst +++ b/docs/commandline.rst @@ -40,6 +40,7 @@ containing steps and terrain functions from multiple locations: Since version v0.7.0 you can use multiple basedirs within one ``-b`` flag split by a colon (:). Similar to the possibilities you've got with ``$PATH``. +This feature will *not* work on windows. Run - Early exit diff --git a/radish/utils.py b/radish/utils.py index afee1804..a9bb7ca0 100644 --- a/radish/utils.py +++ b/radish/utils.py @@ -190,4 +190,7 @@ def flattened_basedirs(basedirs): Multiple basedirs can be specified within a single element split by a colon. """ + if os.name == "nt": + return basedirs + return list(x for x in itertools.chain(*(x.split(":") for x in basedirs)) if x) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 5aad50f7..8fe28c2b 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -18,22 +18,25 @@ @pytest.mark.parametrize( - "basedirs, expected_basedirs", + "basedirs, expected_basedirs, os_name", [ - (["foo", "bar"], ["foo", "bar"]), - (["foo:bar", "foobar"], ["foo", "bar", "foobar"]), + (["foo", "bar"], ["foo", "bar"], "posix"), + (["foo:bar", "foobar"], ["foo", "bar", "foobar"], "posix"), ( ["foo:bar", "foobar", "one:two:three"], ["foo", "bar", "foobar", "one", "two", "three"], + "posix" ), - (["foo:", ":bar"], ["foo", "bar"]), + (["foo:", ":bar"], ["foo", "bar"], "posix"), + (["C:\\windows\\radish"], ["C:\\windows\\radish"], "nt"), ], ) -def test_flattened_basedirs(basedirs, expected_basedirs): +def test_flattened_basedirs(mocker, basedirs, expected_basedirs, os_name): """ Test flatten basedirs """ # given & when + mocker.patch("os.name", os_name) actual_basedirs = utils.flattened_basedirs(basedirs) # then From 923e84d5115fc7b84d82cb659842e6fac4f5bd1c Mon Sep 17 00:00:00 2001 From: Timo Furrer Date: Sat, 9 Feb 2019 12:20:36 +0100 Subject: [PATCH 2/3] Update docs/commandline.rst Co-Authored-By: fliiiix --- docs/commandline.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/commandline.rst b/docs/commandline.rst index 9aa11a33..21d81753 100644 --- a/docs/commandline.rst +++ b/docs/commandline.rst @@ -40,7 +40,7 @@ containing steps and terrain functions from multiple locations: Since version v0.7.0 you can use multiple basedirs within one ``-b`` flag split by a colon (:). Similar to the possibilities you've got with ``$PATH``. -This feature will *not* work on windows. +This feature is not supported on Windows, because the colon (:) is used in almost any absolute path, e.g. ``C:\foo\bar``. Run - Early exit From b40c52327fd9d3182ea1f34387017af216e53b68 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Sat, 9 Feb 2019 12:35:16 +0100 Subject: [PATCH 3/3] Support ; to split basedirs on Windows --- docs/commandline.rst | 5 ++++- radish/utils.py | 6 ++---- tests/unit/test_utils.py | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/commandline.rst b/docs/commandline.rst index 21d81753..5f50396b 100644 --- a/docs/commandline.rst +++ b/docs/commandline.rst @@ -40,7 +40,10 @@ containing steps and terrain functions from multiple locations: Since version v0.7.0 you can use multiple basedirs within one ``-b`` flag split by a colon (:). Similar to the possibilities you've got with ``$PATH``. -This feature is not supported on Windows, because the colon (:) is used in almost any absolute path, e.g. ``C:\foo\bar``. +On Windows it is not possbile to use a colon (:) because it is used +in almost any absolute path, e.g. ``C:\foo\bar``. +Since version v0.11.2 you can use a semicolon (;) on Windows for +multiple basedirs. Run - Early exit diff --git a/radish/utils.py b/radish/utils.py index a9bb7ca0..5a35cd12 100644 --- a/radish/utils.py +++ b/radish/utils.py @@ -190,7 +190,5 @@ def flattened_basedirs(basedirs): Multiple basedirs can be specified within a single element split by a colon. """ - if os.name == "nt": - return basedirs - - return list(x for x in itertools.chain(*(x.split(":") for x in basedirs)) if x) + separator = ";" if os.name == "nt" else ":" + return list(x for x in itertools.chain(*(x.split(separator) for x in basedirs)) if x) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 8fe28c2b..21ffb725 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -29,6 +29,7 @@ ), (["foo:", ":bar"], ["foo", "bar"], "posix"), (["C:\\windows\\radish"], ["C:\\windows\\radish"], "nt"), + (["C:\\windows;radish"], ["C:\\windows", "radish"], "nt"), ], ) def test_flattened_basedirs(mocker, basedirs, expected_basedirs, os_name):