Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Library Installation from depends field in library.properties #205

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5334309
feat: Add lib dependencies from library.properties
aliphys Nov 18, 2023
0119c70
fix: add missing `:`
aliphys Nov 18, 2023
aad9e23
chore: use " instead of '
aliphys Nov 18, 2023
05f82d8
docs: correct dependencies spelling
aliphys Nov 18, 2023
cb8bb24
fix: add `self` to access shared attributes
aliphys Nov 18, 2023
dea4a23
style: dependsLibrary -> depends_library
aliphys Nov 18, 2023
8e9414e
fix: correct definition with `self`
aliphys Nov 18, 2023
1820c94
style: change `'` to `"`
aliphys Nov 18, 2023
1a8131d
fix: use os.environ["GITHUB_REPOSITORY"]
aliphys Nov 18, 2023
e28d54a
Merge branch 'main' into addLibrary
aliphys Dec 6, 2023
6bddc58
Merge branch 'main' into addLibrary
aliphys Jan 30, 2024
2082a83
Merge branch 'main' into addLibrary
aliphys Feb 1, 2024
3234550
Merge branch 'arduino:main' into addLibrary
aliphys Feb 6, 2024
291340c
Add tests for `get_dependancies_from_properties_file`
aliphys Feb 6, 2024
9266584
check director exists
aliphys Feb 6, 2024
2fb2193
Add os.getcwd()
aliphys Feb 6, 2024
647369d
Add os.getcwd() for all three mock locations
aliphys Feb 6, 2024
8e02abc
Fix mock assert for get_dependencies_from_properties_file
aliphys Feb 6, 2024
dc0e8ee
Add tests for `get_library_dependencies`
aliphys Feb 6, 2024
6ed3f23
Cleanup library.properties from previous test
aliphys Feb 6, 2024
9f6cf87
Add blank lines for linter
aliphys Feb 6, 2024
5275f33
Add blank lines
aliphys Feb 6, 2024
1fe58de
Merge branch 'main' into addLibrary
aliphys Feb 13, 2024
1ec0bae
Merge branch 'main' into addLibrary
aliphys Feb 17, 2024
5fa7818
Merge branch 'main' into addLibrary
aliphys Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions compilesketches/compilesketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,26 @@ def install_libraries(self):
if len(library_list.download) > 0:
self.install_libraries_from_download(library_list=library_list.download)

def get_dependencies_from_properties_file(self, properties_file_path):
"""extract library names from `depends` key"""
dependencies = []
with open(properties_file_path, "r") as file:
content = file.read()
match = re.search(r"depends=(.*)", content)
if match:
# only works with "," (comma) deliminator
depends = match.group(1)
if depends:
dependencies = depends.split(",")
return dependencies

def get_library_dependencies(self, library_path):
"""if library.properties is present, extract dependencies"""
properties_file_path = os.path.join(library_path, "library.properties")
if os.path.exists(properties_file_path):
return self.get_dependencies_from_properties_file(properties_file_path)
return []

def install_libraries_from_library_manager(self, library_list):
"""Install libraries using the Arduino Library Manager

Expand All @@ -778,6 +798,10 @@ def install_libraries_from_library_manager(self, library_list):
lib_install_command.append(self.get_manager_dependency_name(library))
self.run_arduino_cli_command(command=lib_install_command, enable_output=self.get_run_command_output_level())

dependencies = self.get_library_dependencies(os.environ["GITHUB_REPOSITORY"])
for depends_library in dependencies:
lib_install_command.extend(depends_library)

def install_libraries_from_path(self, library_list):
"""Install libraries from local paths

Expand Down
64 changes: 64 additions & 0 deletions compilesketches/tests/test_compilesketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,3 +3182,67 @@ def rev_parse(self):
mocker.patch.object(Repo, "rev_parse", return_value="push-head-sha")

assert compilesketches.get_head_commit_hash() == expected_hash


# Automated library parsing from the library.properties file
def test_get_dependencies_from_properties_file_with_dependencies():
properties_file = os.path.join(os.getcwd(), "library.properties")
with open(properties_file, "w") as file:
file.write("depends=Library1,Library2,Library3")

compilesketches_object = get_compilesketches_object()
dependencies = compilesketches_object.get_dependencies_from_properties_file(properties_file)

assert dependencies == ["Library1", "Library2", "Library3"]


# Empty library.properties file should not return any dependencies
def test_get_dependencies_from_properties_file_without_dependencies():
properties_file = os.path.join(os.getcwd(), "library.properties")
with open(properties_file, "w") as file:
file.write("depends=")

compilesketches_object = get_compilesketches_object()
dependencies = compilesketches_object.get_dependencies_from_properties_file(properties_file)

assert dependencies == []


# No depends key inside library.properties, should not return any dependencies
def test_get_dependencies_from_properties_file_no_depends_key():
properties_file = os.path.join(os.getcwd(), "library.properties")
with open(properties_file, "w") as file:
file.write("key=value")

compilesketches_object = get_compilesketches_object()
dependencies = compilesketches_object.get_dependencies_from_properties_file(properties_file)

assert dependencies == []


# dependencies correctly extracted from a properties file within a library
def test_get_library_dependencies_with_properties_file():
library_path = os.path.join(os.getcwd(), "library")
os.makedirs(library_path, exist_ok=True)
properties_file = os.path.join(library_path, "library.properties")
with open(properties_file, "w") as file:
file.write("depends=Library1,Library2,Library3")

compilesketches_object = get_compilesketches_object()
dependencies = compilesketches_object.get_library_dependencies(library_path)

assert dependencies == ["Library1", "Library2", "Library3"]


# no dependencies when the library does not contain a properties file
def test_get_library_dependencies_without_properties_file():
library_path = os.path.join(os.getcwd(), "library")
os.makedirs(library_path, exist_ok=True)
properties_file = os.path.join(library_path, "library.properties")
if os.path.exists(properties_file):
os.remove(properties_file) # properties file is removed

compilesketches_object = get_compilesketches_object()
dependencies = compilesketches_object.get_library_dependencies(library_path)

assert dependencies == []
Loading