From b29414d26efcaa217fcd3749062142f0dfcc2dde Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 4 Nov 2023 11:10:33 -0500 Subject: [PATCH 1/3] check for and install circup_dependencies from pyproject.toml --- circup/__init__.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index 487da42..a6999b2 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -22,6 +22,7 @@ import findimports import pkg_resources import requests +import toml from semver import VersionInfo import update_checker @@ -128,7 +129,7 @@ def lib_dir(self, platform): "lib", ) - def requirements_for(self, library_name): + def requirements_for(self, library_name, toml_file=False): """ The requirements file for this library. @@ -137,15 +138,16 @@ def requirements_for(self, library_name): """ platform = "py" tag = self.current_tag - requirements_txt = os.path.join( + found_file = os.path.join( self.dir.format(platform=platform), self.basename.format(platform=PLATFORMS[platform], tag=tag), "requirements", library_name, - "requirements.txt", + "requirements.txt" if not toml_file else "pyproject.toml", ) - if os.path.isfile(requirements_txt): - with open(requirements_txt, "r", encoding="utf-8") as read_this: + print(f"found_file: {found_file}") + if os.path.isfile(found_file): + with open(found_file, "r", encoding="utf-8") as read_this: return read_this.read() return None @@ -901,6 +903,11 @@ def get_dependencies(*requested_libraries, mod_names, to_install=()): _requested_libraries.extend( libraries_from_requirements(requirements_txt) ) + + circup_dependencies = get_circup_dependencies(bundle, library) + for circup_dependency in circup_dependencies: + _requested_libraries.append(circup_dependency) + # we've processed this library, remove it from the list _requested_libraries.remove(library) @@ -909,6 +916,28 @@ def get_dependencies(*requested_libraries, mod_names, to_install=()): ) +def get_circup_dependencies(bundle, library): + """ + something + """ + try: + pyproj_toml = bundle.requirements_for(library, toml_file=True) + if pyproj_toml: + pyproj_toml_data = toml.loads(pyproj_toml) + dependencies = pyproj_toml_data["circup"]["circup_dependencies"] + if isinstance(dependencies, list): + return dependencies + + if isinstance(dependencies, str): + return (dependencies,) + + return tuple() + + except KeyError: + # no circup_dependencies in pyproject.toml + return tuple() + + def get_device_versions(device_path): """ Returns a dictionary of metadata from modules on the connected device. From 7bfda3b5a58be8ef6cf2f8f7ed2cacfb1e1c8b06 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 4 Nov 2023 11:11:32 -0500 Subject: [PATCH 2/3] remove debugging print --- circup/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index a6999b2..63fa808 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -145,7 +145,6 @@ def requirements_for(self, library_name, toml_file=False): library_name, "requirements.txt" if not toml_file else "pyproject.toml", ) - print(f"found_file: {found_file}") if os.path.isfile(found_file): with open(found_file, "r", encoding="utf-8") as read_this: return read_this.read() From b30e2a92e196c9f503eb0f8f7898bf32289bbf48 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 4 Nov 2023 11:15:55 -0500 Subject: [PATCH 3/3] function docstring --- circup/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index 63fa808..568d8e4 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -917,7 +917,15 @@ def get_dependencies(*requested_libraries, mod_names, to_install=()): def get_circup_dependencies(bundle, library): """ - something + Get the list of circup dependencies from pyproject.toml + e.g. + [circup] + circup_dependencies = ["dependency_name_here"] + + :param bundle: The Bundle to look within + :param library: The Library to find pyproject.toml for and get dependencies from + + :return: The list of dependency libraries that were found """ try: pyproj_toml = bundle.requirements_for(library, toml_file=True)