Skip to content
6 changes: 3 additions & 3 deletions asab/library/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ class LibraryItem:
Attributes:
name (str): The absolute path of the Item. It can be directly fed into `LibraryService.read(...)`.
type (str): Can be either `dir` if the Item is a directory or `item` if Item is of any other type.
layer (int): The number of highest layer in which this Item is found. The higher the number, the lower the layer is.
layers (list[str]): Identifiers of layers in which this item was found.
Examples only as strings, e.g. "0", "1", "0:global", "0:tenant", "0:personal".
providers (list): List of `LibraryProvider` objects containing this Item.
disabled (bool): `True` if the Item is disabled, `False` otherwise. If the Item is disabled, `LibraryService.read(...)` will return `None`.
favorite (bool): True if the Item is marked as a favorite.
override (int): If `True`, this item is marked as an override for the providers with the same Item name.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Docstring says "If True" but override is typed as int.

The docstring describes boolean semantics ("If True") while the field is override: int = 0. Either change the type to bool or update the doc to describe what the integer value represents (e.g., override count or priority).

🤖 Prompt for AI Agents
In `@asab/library/item.py` at line 18, The docstring for the Item field "override"
describes boolean semantics but the code declares override: int = 0; update the
declaration to a boolean and default to False (e.g., override: bool = False) in
the Item class, and adjust any code that relies on numeric values of override to
use True/False; alternatively, if numeric semantics are intended, update the
docstring to explain what the integer represents (e.g., count or priority) and
keep override: int = 0—refer to the Item class and the override field to
implement the chosen change consistently.

target (str): Specifies the target context, e.g., "tenant" or "global". Defaults to "global".
"""
name: str
type: str
layers: typing.List[int] # Now stores multiple layers in ascending order
layers: typing.List[str]
providers: list
disabled: bool = False
favorite: bool = False
Expand Down
2 changes: 1 addition & 1 deletion asab/library/providers/azurestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def list(self, path: str) -> list:
items.append(LibraryItem(
name=i.name,
type=i.type,
layers=[self.Layer],
layers=[str(self.Layer)],
providers=[self],
size=i.size if isinstance(i, AzureItem) else 0 # Include size
))
Expand Down
4 changes: 2 additions & 2 deletions asab/library/providers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _list(self, path: str):
items.append(LibraryItem(
name=fname,
type=ftype,
layers=[self.Layer],
layers=[str(self.Layer)],
providers=[self],
size=size # Include size attribute
))
Expand Down Expand Up @@ -154,7 +154,7 @@ def _recursive_find(self, path, filename, results):
item = LibraryItem(
name=path[len(self.BasePath):], # Store relative path
type="item", # or "dir" if applicable
layers=[self.Layer],
layers=[str(self.Layer)],
providers=[self],
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
results.append(item)
Expand Down
7 changes: 3 additions & 4 deletions asab/library/providers/zookeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ async def process_nodes(self, nodes, base_path, target="global"):
else:
layer_label = "0:{}".format(target)
else:
layer_label = self.Layer
layer_label = str(self.Layer)

items.append(LibraryItem(
name=fname,
Expand Down Expand Up @@ -591,7 +591,6 @@ async def _get_tenants(self) -> typing.List[str]:
tenants = []
return tenants


async def find(self, filename: str) -> list:
"""
Recursively search for files ending with a specific name in ZooKeeper nodes, starting from the base path.
Expand All @@ -613,14 +612,14 @@ async def _recursive_find(self, path, filename, results):
:param results: The list where results are accumulated
"""
try:
children = await self.Zookeeper.get_children(path)
children = await self.Zookeeper.get_children(path) or []
for child in children:
full_path = "{}/{}".format(path, child).rstrip('/')
if full_path.endswith(filename):
item = LibraryItem(
name=full_path[len(self.BasePath):],
type="item", # or "dir" if applicable
layers=[self.Layer],
layers=[str(self.Layer)],
providers=[self],
)
results.append(item)
Expand Down
2 changes: 1 addition & 1 deletion asab/library/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ async def _list(self, path, providers):
item.disabled = self.check_disabled(item.name)
item.favorite = self.check_favorite(item.name)
# Use the layers as provided by the provider; if empty, fall back to outer_layer.
provider_layers = item.layers if item.layers else [outer_layer]
provider_layers = item.layers if item.layers else [str(outer_layer)]

if item.name in unique_items:
existing_item = unique_items[item.name]
Expand Down