From 1b561afde945897bb04b019f2af1c4ef573cb9b9 Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Thu, 22 Jun 2023 18:00:16 -0700 Subject: [PATCH] Update compute_directory_fingerprints #118 Signed-off-by: Jono Yang --- matchcode-toolkit/CHANGELOG.rst | 5 +++++ matchcode-toolkit/setup.cfg | 2 +- .../src/matchcode_toolkit/fingerprinting.py | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/matchcode-toolkit/CHANGELOG.rst b/matchcode-toolkit/CHANGELOG.rst index 41cf3e53..123c5fd8 100644 --- a/matchcode-toolkit/CHANGELOG.rst +++ b/matchcode-toolkit/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +v1.1.0 +------ + +*2023-06-22* -- Rename ``compute_directory_fingerprints`` to ``compute_codebase_directory_fingerprints`` and create a new version of ``compute_directory_fingerprints`` that works on Resource objects instead of codebases. + v1.0.0 ------ diff --git a/matchcode-toolkit/setup.cfg b/matchcode-toolkit/setup.cfg index eb9c6162..7058803d 100644 --- a/matchcode-toolkit/setup.cfg +++ b/matchcode-toolkit/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = matchcode-toolkit -version = 1.0.0 +version = 1.1.0 license = Apache-2.0 # description must be on ONE line https://github.com/pypa/setuptools/issues/1390 diff --git a/matchcode-toolkit/src/matchcode_toolkit/fingerprinting.py b/matchcode-toolkit/src/matchcode_toolkit/fingerprinting.py index 19e6a03b..1d9df4a6 100644 --- a/matchcode-toolkit/src/matchcode_toolkit/fingerprinting.py +++ b/matchcode-toolkit/src/matchcode_toolkit/fingerprinting.py @@ -69,7 +69,7 @@ def create_structure_fingerprint(directory, children): return _create_directory_fingerprint(features) -def compute_directory_fingerprints(directory, codebase): +def _compute_directory_fingerprints(directory, codebase): """ Compute fingerprints for `directory` from `codebase` """ @@ -87,12 +87,23 @@ def compute_directory_fingerprints(directory, codebase): if hasattr(directory, 'directory_structure_fingerprint'): directory.directory_structure_fingerprint = directory_structure_fingerprint else: - directory.extra_data['directory_structure'] = create_structure_fingerprint(directory, children) + directory.extra_data['directory_structure'] = directory_structure_fingerprint directory.save(codebase) return directory +def compute_directory_fingerprints(directory, codebase): + """ + Recursivly compute fingerprints for `directory` from `codebase` + """ + for resource in directory.walk(codebase, topdown=False): + if resource.is_file: + continue + _ = _compute_directory_fingerprints(resource, codebase) + return directory + + def compute_codebase_directory_fingerprints(codebase): """ Compute fingerprints for directories from `codebase` @@ -100,7 +111,7 @@ def compute_codebase_directory_fingerprints(codebase): for resource in codebase.walk(topdown=False): if resource.is_file or not resource.path: continue - _ = compute_directory_fingerprints(resource, codebase) + _ = _compute_directory_fingerprints(resource, codebase) return codebase