From 346ef3aa926cbd96be25af5c1ec50e272b42b299 Mon Sep 17 00:00:00 2001 From: Uchechukwu Orji Date: Fri, 29 Nov 2024 15:59:01 +0100 Subject: [PATCH 1/2] remove traces of camelCase in API --- CHANGELOG.md | 4 ++++ libzim/libzim.pyx | 33 ++++++++++++++++----------------- libzim/search.pyi | 4 ++-- libzim/suggestion.pyi | 6 ++---- libzim/writer.pyi | 8 ++++---- tests/test_libzim_creator.py | 30 +++++++++++++++--------------- tests/test_libzim_reader.py | 8 ++++---- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5d205..fd55bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Remove traces of camelCase in API (#200) + ## [3.6.0] - 2024-10-15 ### Added diff --git a/libzim/libzim.pyx b/libzim/libzim.pyx index c309b13..88d50f8 100644 --- a/libzim/libzim.pyx +++ b/libzim/libzim.pyx @@ -314,16 +314,16 @@ cdef class _Creator: self.c_creator.configIndexing(indexing, language.encode('UTF-8')) return self - def config_nbworkers(self, int nbWorkers: pyint) -> Creator: + def config_nbworkers(self, int nb_workers: pyint) -> Creator: """Number of thread to use for internal worker""" if self._started: raise RuntimeError("Creator started") - self.c_creator.configNbWorkers(nbWorkers) + self.c_creator.configNbWorkers(nb_workers) return self - def set_mainpath(self, str mainPath: str) -> Creator: + def set_mainpath(self, str main_path: str) -> Creator: """Set path of the main entry""" - self.c_creator.setMainPath(mainPath.encode('UTF-8')) + self.c_creator.setMainPath(main_path.encode('UTF-8')) return self def add_illustration(self, int size: pyint, content: bytes): @@ -381,7 +381,7 @@ cdef class _Creator: with nogil: self.c_creator.addMetadata(_name, _content, _mimetype) - def add_redirection(self, str path: str, str title: str, str targetPath: str, dict hints: Dict[Hint, pyint]): + def add_redirection(self, str path: str, str title: str, str target_path: str, dict hints: Dict[Hint, pyint]): """Add redirection entry to Archive https://wiki.openzim.org/wiki/ZIM_file_format#Redirect_Entry @@ -396,25 +396,25 @@ cdef class _Creator: cdef string _path = path.encode('UTF-8') cdef string _title = title.encode('UTF-8') - cdef string _targetPath = targetPath.encode('UTF-8') + cdef string _targetPath = target_path.encode('UTF-8') cdef map[zim.HintKeys, uint64_t] _hints = convertToCppHints(hints) with nogil: self.c_creator.addRedirection(_path, _title, _targetPath, _hints) - def add_alias(self, str path: str, str title: str, str targetPath: str, dict hints: Dict[Hint, pyint]): - """Alias the (existing) entry `targetPath` as a new entry `path`. + def add_alias(self, str path: str, str title: str, str target_path: str, dict hints: Dict[Hint, pyint]): + """Alias the (existing) entry `target_path` as a new entry `path`. Raises ------ RuntimeError - If `targetPath` entry doesn't exist. + If `target_path` entry doesn't exist. """ if not self._started: raise RuntimeError("Creator not started") cdef string _path = path.encode('UTF-8') cdef string _title = title.encode('UTF-8') - cdef string _targetPath = targetPath.encode('UTF-8') + cdef string _targetPath = target_path.encode('UTF-8') cdef map[zim.HintKeys, uint64_t] _hints = convertToCppHints(hints) with nogil: self.c_creator.addAlias(_path, _title, _targetPath, _hints) @@ -1110,11 +1110,11 @@ cdef class Search: search.c_search = move(_search) return search - def getEstimatedMatches(self) -> pyint: + def get_estimated_matches(self) -> pyint: """Estimated number of results in Archive for the search""" return self.c_search.getEstimatedMatches() - def getResults(self, start: pyint, count: pyint) -> SearchResultSet: + def get_results(self, start: pyint, count: pyint) -> SearchResultSet: """Iterator over Entry paths found in Archive for the search""" return SearchResultSet.from_resultset(move(self.c_search.getResults(start, count))) @@ -1155,7 +1155,7 @@ archive = libzim.reader.Archive(fpath) searcher = Searcher(archive) query = Query().set_query("foo") search = searcher.search(query) -for path in search.getResults(10, 10) # get result from 10 to 20 (10 results) +for path in search.get_results(10, 10) # get result from 10 to 20 (10 results) print(path, archive.get_entry_by_path(path).title)""" search_public_objects = [ Query, @@ -1212,11 +1212,11 @@ cdef class SuggestionSearch: search.c_search = move(_search) return search - def getEstimatedMatches(self) -> pyint: + def get_estimated_matches(self) -> pyint: """Estimated number of results in Archive for the suggestion search""" return self.c_search.getEstimatedMatches() - def getResults(self, start: pyint, count: pyint) -> SuggestionResultSet: + def get_results(self, start: pyint, count: pyint) -> SuggestionResultSet: """Iterator over Entry paths found in Archive for the suggestion search""" return SuggestionResultSet.from_resultset(move(self.c_search.getResults(start, count))) @@ -1255,7 +1255,7 @@ Usage: archive = Archive(fpath) suggestion_searcher = SuggestionSearcher(archive) suggestions = suggestion_searcher.suggest("foo") -for path in suggestion.getResults(10, 10) # get result from 10 to 20 (10 results) +for path in suggestion.get_results(10, 10) # get result from 10 to 20 (10 results) print(path, archive.get_entry_by_path(path).title)""" suggestion_public_objects = [ SuggestionSearcher @@ -1334,4 +1334,3 @@ class ModuleFinder(importlib.abc.MetaPathFinder): sys.meta_path.insert(0, ModuleFinder()) __all__ = ["writer", "reader", "search", "suggestion", "version"] - diff --git a/libzim/search.pyi b/libzim/search.pyi index b0d7136..6c53c75 100644 --- a/libzim/search.pyi +++ b/libzim/search.pyi @@ -12,8 +12,8 @@ class SearchResultSet: def __iter__(self) -> Iterator[str]: ... class Search: - def getEstimatedMatches(self) -> int: ... # noqa: N802 - def getResults(self, start: int, count: int) -> SearchResultSet: ... # noqa: N802 + def get_estimated_matches(self) -> int: ... + def get_results(self, start: int, count: int) -> SearchResultSet: ... class Searcher: def __init__(self, archive: Archive) -> None: ... diff --git a/libzim/suggestion.pyi b/libzim/suggestion.pyi index ce537ea..f09b816 100644 --- a/libzim/suggestion.pyi +++ b/libzim/suggestion.pyi @@ -8,10 +8,8 @@ class SuggestionResultSet: def __iter__(self) -> Iterator[str]: ... class SuggestionSearch: - def getEstimatedMatches(self) -> int: ... # noqa: N802 - def getResults( # noqa: N802 - self, start: int, count: int - ) -> SuggestionResultSet: ... + def get_estimated_matches(self) -> int: ... + def get_results(self, start: int, count: int) -> SuggestionResultSet: ... class SuggestionSearcher: def __init__(self, archive: Archive) -> None: ... diff --git a/libzim/writer.pyi b/libzim/writer.pyi index 5288e7a..7fe0cde 100644 --- a/libzim/writer.pyi +++ b/libzim/writer.pyi @@ -58,8 +58,8 @@ class Creator: def config_compression(self, compression: Compression | str) -> Self: ... def config_clustersize(self, size: int) -> Self: ... def config_indexing(self, indexing: bool, language: str) -> Self: ... - def config_nbworkers(self, nbWorkers: int) -> Self: ... # noqa: N803 - def set_mainpath(self, mainPath: str) -> Self: ... # noqa: N803 + def config_nbworkers(self, nb_workers: int) -> Self: ... + def set_mainpath(self, main_path: str) -> Self: ... def add_illustration(self, size: int, content: bytes) -> None: ... def add_item(self, writer_item: Item) -> None: ... def add_metadata( @@ -72,14 +72,14 @@ class Creator: self, path: str, title: str, - targetPath: str, # noqa: N803 + target_path: str, hints: dict[Hint, int], ) -> None: ... def add_alias( self, path: str, title: str, - targetPath: str, # noqa: N803 + target_path: str, hints: dict[Hint, int], ) -> None: ... def __enter__(self) -> Self: ... diff --git a/tests/test_libzim_creator.py b/tests/test_libzim_creator.py index cc9ef27..a8d11a3 100644 --- a/tests/test_libzim_creator.py +++ b/tests/test_libzim_creator.py @@ -244,7 +244,7 @@ def test_creator_indexing(fpath, lipsum_item, indexing, language, expected): query = Query().set_query("standard") searcher = Searcher(zim) search = searcher.search(query) - assert search.getEstimatedMatches() == expected + assert search.get_estimated_matches() == expected @pytest.mark.parametrize("nb_workers", [1, 2, 3, 5]) @@ -472,10 +472,10 @@ def test_creator_redirection(fpath, lipsum_item): # suggestions sugg_searcher = SuggestionSearcher(zim) sugg_hello = sugg_searcher.suggest("hello") - assert "home" in list(sugg_hello.getResults(0, sugg_hello.getEstimatedMatches())) + assert "home" in list(sugg_hello.get_results(0, sugg_hello.get_estimated_matches())) sugg_bonjour = sugg_searcher.suggest("bonjour") assert "accueil" in list( - sugg_bonjour.getResults(0, sugg_hello.getEstimatedMatches()) + sugg_bonjour.get_results(0, sugg_hello.get_estimated_matches()) ) @@ -659,7 +659,7 @@ def test_hints_values(fpath): # Hint values are casted to bool c.add_item(StaticItem(path="3", title="", hints={Hint.FRONT_ARTICLE: "world"})) c.add_redirection( - path="4", title="", targetPath="0", hints={Hint.COMPRESS: True} + path="4", title="", target_path="0", hints={Hint.COMPRESS: True} ) # filtered-out values c.add_item(StaticItem(path="5", title="", hints={5: True})) @@ -683,13 +683,13 @@ def test_hints_values(fpath): c.add_redirection( # pyright: ignore [reportCallIssue] path="5", title="", - targetPath="0", + target_path="0", hints={Hint.YOLO: True}, # pyright: ignore [reportAttributeAccessIssue] ) @pytest.mark.parametrize( - "indexData, customContent, search_expected", + "index_data, custom_content, search_expected", [ (None, "", [("standard", 1), ("home", 0), ("computer", 0)]), (False, "", [("standard", 1), ("home", 0), ("computer", 0)]), @@ -699,22 +699,22 @@ def test_hints_values(fpath): ], ) def test_custom_indexdata( - fpath, lipsum_item, lipsum, indexData, customContent, search_expected + fpath, lipsum_item, lipsum, index_data, custom_content, search_expected ): item = StaticItem(path=HOME_PATH + "custom", content=lipsum, mimetype="text/html") - if indexData is None: + if index_data is None: item.get_indexdata = lambda: None else: class CustomIndexData(IndexData): def has_indexdata(self): - return indexData + return index_data def get_title(self): return "" def get_content(self): - return customContent + return custom_content def get_keywords(self): return "" @@ -733,7 +733,7 @@ def get_wordcount(self): for search_query, expected in search_expected: query = Query().set_query(search_query) search = searcher.search(query) - assert search.getEstimatedMatches() == expected + assert search.get_estimated_matches() == expected def test_indexdata_interface(): @@ -871,11 +871,11 @@ def test_accented_search_from_libzim(fpath): ascii_query = Query().set_query("test article") ascii_searcher = Searcher(zim) ascii_search = ascii_searcher.search(ascii_query) - assert ascii_search.getEstimatedMatches() == zim.article_count - assert list(ascii_search.getResults(0, zim.article_count)) == ["path0", "path1"] + assert ascii_search.get_estimated_matches() == zim.article_count + assert list(ascii_search.get_results(0, zim.article_count)) == ["path0", "path1"] accented_query = Query().set_query("test àrticlé") accented_searcher = Searcher(zim) accented_search = accented_searcher.search(accented_query) - assert accented_search.getEstimatedMatches() == zim.article_count - assert list(accented_search.getResults(0, zim.article_count)) == ["path0", "path1"] + assert accented_search.get_estimated_matches() == zim.article_count + assert list(accented_search.get_results(0, zim.article_count)) == ["path0", "path1"] diff --git a/tests/test_libzim_reader.py b/tests/test_libzim_reader.py index 28da539..7db9a25 100644 --- a/tests/test_libzim_reader.py +++ b/tests/test_libzim_reader.py @@ -478,14 +478,14 @@ def test_reader_suggest_search( query = Query().set_query(search_string) searcher = Searcher(zim) search = searcher.search(query) - assert search.getEstimatedMatches() == search_count - assert list(search.getResults(0, search_count)) == search_result + assert search.get_estimated_matches() == search_count + assert list(search.get_results(0, search_count)) == search_result if suggestion_string is not None: suggestion_searcher = SuggestionSearcher(zim) suggestion = suggestion_searcher.suggest(suggestion_string) - assert suggestion.getEstimatedMatches() == suggestion_count - assert list(suggestion.getResults(0, suggestion_count)) == suggestion_result + assert suggestion.get_estimated_matches() == suggestion_count + assert list(suggestion.get_results(0, suggestion_count)) == suggestion_result @skip_if_offline From da46373d807e080d7480302f5caab6c0c1476edc Mon Sep 17 00:00:00 2001 From: Uchechukwu Orji Date: Mon, 2 Dec 2024 18:08:41 +0100 Subject: [PATCH 2/2] update entries as breaking changes in changelog --- CHANGELOG.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd55bf5..17ead87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] - -- Remove traces of camelCase in API (#200) +### Breaking Changes + +- [search] `Search.getEstimatedMatches()` renamed `Search.get_estimated_matches()` (#200) +- [search] `Search.getResults()` renamed `Search.get_results()` (#200) +- [suggestion] `SuggestionSearch.getEstimatedMatches()` renamed `SuggestionSearch.get_estimated_matches()` (#200) +- [suggestion] `SuggestionSearch.getResults()` renamed `SuggestionSearch.get_results()` (#200) +- [suggestion] `SuggestionSearch.getResults()` renamed `SuggestionSearch.get_results()` (#200) +- [writer] `Creator.config_nbworkers()` param `nbWorkers` renamed `nb_workers` (#200) +- [writer] `Creator.set_mainpath()` param `mainPath` renamed `main_path` (#200) +- [writer] `Creator.add_redirection()` param `targetPath` renamed `target_path` (#200) +- [writer] `Creator.add_alias()` param `targetPath` renamed `target_path` (#200) ## [3.6.0] - 2024-10-15