Skip to content

remove traces of camelCase in API #212

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ 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).

### 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

### Added
Expand Down
33 changes: 16 additions & 17 deletions libzim/libzim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1334,4 +1334,3 @@ class ModuleFinder(importlib.abc.MetaPathFinder):
sys.meta_path.insert(0, ModuleFinder())

__all__ = ["writer", "reader", "search", "suggestion", "version"]

4 changes: 2 additions & 2 deletions libzim/search.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
6 changes: 2 additions & 4 deletions libzim/suggestion.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
8 changes: 4 additions & 4 deletions libzim/writer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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: ...
Expand Down
30 changes: 15 additions & 15 deletions tests/test_libzim_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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())
)


Expand Down Expand Up @@ -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}))
Expand All @@ -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)]),
Expand All @@ -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 ""
Expand All @@ -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():
Expand Down Expand Up @@ -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"]
8 changes: 4 additions & 4 deletions tests/test_libzim_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading