Skip to content

Commit 2127988

Browse files
committed
Create the libraries folder on demand in install_libraries_from_path()
It is necessary to make the parent folder in install_platforms_from_path(), since the folder will be different for every platform, so it makes sense to mirror that behavior in the equivalent libraries function. The other installation methods already will create the parent folder if it doesn't already exist, so it's only necessary to add this to install_libraries_from_path() after removing it from install_libraries().
1 parent a94f1e8 commit 2127988

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compilesketches/compilesketches.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,6 @@ def clone_repository(self, url, git_ref, destination_path):
539539

540540
def install_libraries(self):
541541
"""Install Arduino libraries."""
542-
self.libraries_path.mkdir(parents=True, exist_ok=True)
543-
544542
libraries = yaml.load(stream="", Loader=yaml.SafeLoader)
545543
try:
546544
libraries = yaml.load(stream=self.libraries, Loader=yaml.SafeLoader)
@@ -611,6 +609,9 @@ def install_libraries_from_path(self, library_list):
611609
# Use the existing folder name
612610
destination_name = source_path.name
613611

612+
# Create the parent path if it doesn't exist already
613+
self.libraries_path.mkdir(parents=True, exist_ok=True)
614+
614615
# Install the library by creating a symlink in the sketchbook
615616
library_symlink_path = self.libraries_path.joinpath(destination_name)
616617
library_symlink_path.symlink_to(target=source_path, target_is_directory=True)

compilesketches/tests/test_compilesketches.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,17 +743,13 @@ def test_install_libraries(monkeypatch, mocker, libraries, expected_manager, exp
743743
compile_sketches = get_compilesketches_object(libraries=libraries)
744744
compile_sketches.libraries_path = libraries_path
745745

746-
mocker.patch.object(pathlib.Path, "mkdir", autospec=True)
747746
mocker.patch("compilesketches.CompileSketches.install_libraries_from_library_manager", autospec=True)
748747
mocker.patch("compilesketches.CompileSketches.install_libraries_from_path", autospec=True)
749748
mocker.patch("compilesketches.CompileSketches.install_libraries_from_repository", autospec=True)
750749
mocker.patch("compilesketches.CompileSketches.install_libraries_from_download", autospec=True)
751750

752751
compile_sketches.install_libraries()
753752

754-
# noinspection PyUnresolvedReferences
755-
pathlib.Path.mkdir.assert_called_with(libraries_path, parents=True, exist_ok=True)
756-
757753
if len(expected_manager) > 0:
758754
compile_sketches.install_libraries_from_library_manager.assert_called_once_with(
759755
compile_sketches,
@@ -824,6 +820,7 @@ def test_install_libraries_from_path(capsys, monkeypatch, mocker, path_exists, l
824820
compile_sketches.libraries_path = libraries_path
825821

826822
mocker.patch.object(pathlib.Path, "exists", autospec=True, return_value=path_exists)
823+
mocker.patch.object(pathlib.Path, "mkdir", autospec=True)
827824
mocker.patch.object(pathlib.Path, "joinpath", autospec=True, return_value=symlink_source_path)
828825
mocker.patch.object(pathlib.Path, "symlink_to", autospec=True)
829826

@@ -839,15 +836,19 @@ def test_install_libraries_from_path(capsys, monkeypatch, mocker, path_exists, l
839836
else:
840837
compile_sketches.install_libraries_from_path(library_list=library_list)
841838

839+
mkdir_calls = []
842840
joinpath_calls = []
843841
symlink_to_calls = []
844842
for library, expected_destination_name in zip(library_list, expected_destination_name_list):
843+
mkdir_calls.append(unittest.mock.call(libraries_path, parents=True, exist_ok=True))
845844
joinpath_calls.append(unittest.mock.call(libraries_path, expected_destination_name))
846845
symlink_to_calls.append(
847846
unittest.mock.call(symlink_source_path,
848847
target=library[compilesketches.CompileSketches.dependency_source_path_key],
849848
target_is_directory=True))
850849

850+
# noinspection PyUnresolvedReferences
851+
pathlib.Path.mkdir.assert_has_calls(calls=mkdir_calls)
851852
# noinspection PyUnresolvedReferences
852853
pathlib.Path.joinpath.assert_has_calls(calls=joinpath_calls)
853854
pathlib.Path.symlink_to.assert_has_calls(calls=symlink_to_calls)

0 commit comments

Comments
 (0)