Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Sep 4, 2023
1 parent cb3b3be commit 1fac057
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
35 changes: 17 additions & 18 deletions src/stubber/tools/manifestfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,26 +406,25 @@ def require(self, name, version=None, unix_ffi=False, pypi=None, **kwargs):
self._pypi_dependencies.append(pypi)
return

if self._path_vars["MPY_LIB_DIR"]:
lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
if unix_ffi:
# Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
# take precedence.
lib_dirs = ["unix-ffi"] + lib_dirs

for lib_dir in lib_dirs:
# Search for {lib_dir}/**/{name}/manifest.py.
for root, dirnames, filenames in os.walk(
os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)
):
if os.path.basename(root) == name and "manifest.py" in filenames:
self.include(root, is_require=True, **kwargs)
return

raise ValueError("Library not found in local micropython-lib: {}".format(name))
else:
if not self._path_vars["MPY_LIB_DIR"]:
# TODO: HTTP request to obtain URLs from manifest.json.
raise ValueError("micropython-lib not available for require('{}').", name)
lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
if unix_ffi:
# Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
# take precedence.
lib_dirs = ["unix-ffi"] + lib_dirs

for lib_dir in lib_dirs:
# Search for {lib_dir}/**/{name}/manifest.py.
for root, dirnames, filenames in os.walk(
os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)
):
if os.path.basename(root) == name and "manifest.py" in filenames:
self.include(root, is_require=True, **kwargs)
return

raise ValueError("Library not found in local micropython-lib: {}".format(name))

def package(self, package_path, files=None, base_path=".", opt=None):
"""
Expand Down
7 changes: 2 additions & 5 deletions src/stubber/utils/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def read_micropython_lib_commits(filename: str = "data/micropython_tags.csv"):

def match_lib_with_mpy(version_tag: str, lib_path: Path):
micropython_lib_commits = read_micropython_lib_commits()
# Make sure that the correct micropython-lib release is checked out
# check if micropython-lib has matching tags
if Version(version_tag) >= Version("v1.20.0"):
# TODO:if version is v1.12.0 or newer
# then use submodules to checkout the correct version of micropython-lib
Expand All @@ -84,9 +82,8 @@ def match_lib_with_mpy(version_tag: str, lib_path: Path):
# git submodule foreach --recursive git clean -xfd
# use the micropython_tags.csv to find the correct commit hash
return git.checkout_tag(version_tag, lib_path)
else:
log.info(f"Matching repo's: Micropython {version_tag} needs micropython-lib:{micropython_lib_commits[version_tag]}")
return git.checkout_commit(micropython_lib_commits[version_tag], lib_path)
log.info(f"Matching repo's: Micropython {version_tag} needs micropython-lib:{micropython_lib_commits[version_tag]}")
return git.checkout_commit(micropython_lib_commits[version_tag], lib_path)


def fetch_repos(tag: str, mpy_path: Path, mpy_lib_path: Path):
Expand Down

0 comments on commit 1fac057

Please sign in to comment.