Skip to content

Commit 43fa576

Browse files
committed
ruff checks
Signed-off-by: Drew Cain <[email protected]>
1 parent fb1350b commit 43fa576

File tree

12 files changed

+212
-202
lines changed

12 files changed

+212
-202
lines changed

src/basic_memory/api/routers/project_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def update_project(
5151
# Validate that path is absolute if provided
5252
if path and not os.path.isabs(path):
5353
raise HTTPException(status_code=400, detail="Path must be absolute")
54-
54+
5555
# Get original project info for the response
5656
old_project_info = ProjectItem(
5757
name=name,

src/basic_memory/cli/commands/project.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,33 @@ def move_project(
157157
"""Move a project to a new location."""
158158
# Resolve to absolute path
159159
resolved_path = os.path.abspath(os.path.expanduser(new_path))
160-
160+
161161
try:
162162
data = {"path": resolved_path}
163163
project_name = generate_permalink(name)
164-
164+
165165
current_project = session.get_current_project()
166-
response = asyncio.run(call_patch(client, f"/{current_project}/project/{project_name}", json=data))
166+
response = asyncio.run(
167+
call_patch(client, f"/{current_project}/project/{project_name}", json=data)
168+
)
167169
result = ProjectStatusResponse.model_validate(response.json())
168-
170+
169171
console.print(f"[green]{result.message}[/green]")
170-
172+
171173
# Show important file movement reminder
172174
console.print() # Empty line for spacing
173-
console.print(Panel(
174-
"[bold red]IMPORTANT:[/bold red] Project configuration updated successfully.\n\n"
175-
"[yellow]You must manually move your project files from the old location to:[/yellow]\n"
176-
f"[cyan]{resolved_path}[/cyan]\n\n"
177-
"[dim]Basic Memory has only updated the configuration - your files remain in their original location.[/dim]",
178-
title="⚠️ Manual File Movement Required",
179-
border_style="yellow",
180-
expand=False
181-
))
182-
175+
console.print(
176+
Panel(
177+
"[bold red]IMPORTANT:[/bold red] Project configuration updated successfully.\n\n"
178+
"[yellow]You must manually move your project files from the old location to:[/yellow]\n"
179+
f"[cyan]{resolved_path}[/cyan]\n\n"
180+
"[dim]Basic Memory has only updated the configuration - your files remain in their original location.[/dim]",
181+
title="⚠️ Manual File Movement Required",
182+
border_style="yellow",
183+
expand=False,
184+
)
185+
)
186+
183187
except Exception as e:
184188
console.print(f"[red]Error moving project: {str(e)}[/red]")
185189
raise typer.Exit(1)

src/basic_memory/importers/chatgpt_importer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,24 @@ def _traverse_messages(
209209

210210
# Use iterative approach with stack to avoid recursion depth issues
211211
stack = [root_id]
212-
212+
213213
while stack:
214214
node_id = stack.pop()
215215
if not node_id:
216216
continue
217-
217+
218218
node = mapping.get(node_id)
219219
if not node:
220220
continue
221-
221+
222222
# Process current node if it has a message and hasn't been seen
223223
if node["id"] not in seen and node.get("message"):
224224
seen.add(node["id"])
225225
messages.append(node["message"])
226-
226+
227227
# Add children to stack in reverse order to maintain conversation flow
228228
children = node.get("children", [])
229229
for child_id in reversed(children):
230230
stack.append(child_id)
231-
231+
232232
return messages

src/basic_memory/repository/project_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ async def set_as_default(self, project_id: int) -> Optional[Project]:
8686

8787
async def update_path(self, project_id: int, new_path: str) -> Optional[Project]:
8888
"""Update project path.
89-
89+
9090
Args:
9191
project_id: ID of the project to update
9292
new_path: New filesystem path for the project
93-
93+
9494
Returns:
9595
The updated project if found, None otherwise
9696
"""

src/basic_memory/services/entity_service.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,35 @@ def __init__(
4747

4848
async def detect_file_path_conflicts(self, file_path: str) -> List[Entity]:
4949
"""Detect potential file path conflicts for a given file path.
50-
50+
5151
This checks for entities with similar file paths that might cause conflicts:
5252
- Case sensitivity differences (Finance/file.md vs finance/file.md)
5353
- Character encoding differences
5454
- Hyphen vs space differences
5555
- Unicode normalization differences
56-
56+
5757
Args:
5858
file_path: The file path to check for conflicts
59-
59+
6060
Returns:
6161
List of entities that might conflict with the given file path
6262
"""
6363
from basic_memory.utils import detect_potential_file_conflicts
64-
64+
6565
conflicts = []
66-
66+
6767
# Get all existing file paths
6868
all_entities = await self.repository.find_all()
6969
existing_paths = [entity.file_path for entity in all_entities]
70-
70+
7171
# Use the enhanced conflict detection utility
7272
conflicting_paths = detect_potential_file_conflicts(file_path, existing_paths)
73-
73+
7474
# Find the entities corresponding to conflicting paths
7575
for entity in all_entities:
7676
if entity.file_path in conflicting_paths:
7777
conflicts.append(entity)
78-
78+
7979
return conflicts
8080

8181
async def resolve_permalink(
@@ -88,19 +88,19 @@ async def resolve_permalink(
8888
2. If markdown has permalink but it's used by another file -> make unique
8989
3. For existing files, keep current permalink from db
9090
4. Generate new unique permalink from file path
91-
91+
9292
Enhanced to detect and handle character-related conflicts.
9393
"""
9494
file_path_str = str(file_path)
95-
95+
9696
# Check for potential file path conflicts before resolving permalink
9797
conflicts = await self.detect_file_path_conflicts(file_path_str)
9898
if conflicts:
9999
logger.warning(
100100
f"Detected potential file path conflicts for '{file_path_str}': "
101101
f"{[entity.file_path for entity in conflicts]}"
102102
)
103-
103+
104104
# If markdown has explicit permalink, try to validate it
105105
if markdown and markdown.frontmatter.permalink:
106106
desired_permalink = markdown.frontmatter.permalink

src/basic_memory/services/project_service.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,33 +311,33 @@ async def synchronize_projects(self) -> None: # pragma: no cover
311311

312312
async def move_project(self, name: str, new_path: str) -> None:
313313
"""Move a project to a new location.
314-
314+
315315
Args:
316316
name: The name of the project to move
317317
new_path: The new absolute path for the project
318-
318+
319319
Raises:
320320
ValueError: If the project doesn't exist or repository isn't initialized
321321
"""
322322
if not self.repository:
323323
raise ValueError("Repository is required for move_project")
324-
324+
325325
# Resolve to absolute path
326326
resolved_path = os.path.abspath(os.path.expanduser(new_path))
327-
327+
328328
# Validate project exists in config
329329
if name not in self.config_manager.projects:
330330
raise ValueError(f"Project '{name}' not found in configuration")
331-
331+
332332
# Create the new directory if it doesn't exist
333333
Path(resolved_path).mkdir(parents=True, exist_ok=True)
334-
334+
335335
# Update in configuration
336336
config = self.config_manager.load_config()
337337
old_path = config.projects[name]
338338
config.projects[name] = resolved_path
339339
self.config_manager.save_config(config)
340-
340+
341341
# Update in database
342342
project = await self.repository.get_by_name(name)
343343
if project:

src/basic_memory/sync/sync_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ async def handle_move(self, old_path, new_path):
462462
f"entity_id={entity.id} trying to move from '{old_path}' to '{new_path}', "
463463
f"but entity_id={existing_at_destination.id} already occupies '{new_path}'"
464464
)
465-
465+
466466
# Check if this is a file swap (the destination entity is being moved to our old path)
467467
# This would indicate a simultaneous move operation
468468
old_path_after_swap = await self.entity_repository.get_by_file_path(old_path)

src/basic_memory/utils.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,74 +183,74 @@ def setup_logging(
183183

184184
def normalize_file_path_for_comparison(file_path: str) -> str:
185185
"""Normalize a file path for conflict detection.
186-
186+
187187
This function normalizes file paths to help detect potential conflicts:
188188
- Converts to lowercase for case-insensitive comparison
189189
- Normalizes Unicode characters
190190
- Handles path separators consistently
191-
191+
192192
Args:
193193
file_path: The file path to normalize
194-
194+
195195
Returns:
196196
Normalized file path for comparison purposes
197197
"""
198198
import unicodedata
199-
199+
200200
# Convert to lowercase for case-insensitive comparison
201201
normalized = file_path.lower()
202-
202+
203203
# Normalize Unicode characters (NFD normalization)
204-
normalized = unicodedata.normalize('NFD', normalized)
205-
204+
normalized = unicodedata.normalize("NFD", normalized)
205+
206206
# Replace path separators with forward slashes
207-
normalized = normalized.replace('\\', '/')
208-
207+
normalized = normalized.replace("\\", "/")
208+
209209
# Remove multiple slashes
210-
normalized = re.sub(r'/+', '/', normalized)
211-
210+
normalized = re.sub(r"/+", "/", normalized)
211+
212212
return normalized
213213

214214

215215
def detect_potential_file_conflicts(file_path: str, existing_paths: List[str]) -> List[str]:
216216
"""Detect potential conflicts between a file path and existing paths.
217-
217+
218218
This function checks for various types of conflicts:
219219
- Case sensitivity differences
220220
- Unicode normalization differences
221221
- Path separator differences
222222
- Permalink generation conflicts
223-
223+
224224
Args:
225225
file_path: The file path to check
226226
existing_paths: List of existing file paths to check against
227-
227+
228228
Returns:
229229
List of existing paths that might conflict with the given file path
230230
"""
231231
conflicts = []
232-
232+
233233
# Normalize the input file path
234234
normalized_input = normalize_file_path_for_comparison(file_path)
235235
input_permalink = generate_permalink(file_path)
236-
236+
237237
for existing_path in existing_paths:
238238
# Skip identical paths
239239
if existing_path == file_path:
240240
continue
241-
241+
242242
# Check for case-insensitive path conflicts
243243
normalized_existing = normalize_file_path_for_comparison(existing_path)
244244
if normalized_input == normalized_existing:
245245
conflicts.append(existing_path)
246246
continue
247-
247+
248248
# Check for permalink conflicts
249249
existing_permalink = generate_permalink(existing_path)
250250
if input_permalink == existing_permalink:
251251
conflicts.append(existing_path)
252252
continue
253-
253+
254254
return conflicts
255255

256256

0 commit comments

Comments
 (0)