Skip to content
Merged
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
3 changes: 2 additions & 1 deletion brevia/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def cleanup_jobs(before_date: datetime, dry_run: bool):
num = cleanup_async_jobs(before_date=before_date, dry_run=dry_run)

if dry_run:
click.echo(f"Dry run completed. {num} {'job' if num == 1 else 'jobs'} would be deleted.")
njob = f"{num} {'job' if num == 1 else 'jobs'}"
click.echo(f"Dry run completed. {njob} would be deleted.")
elif num == 0:
click.echo("No async jobs to delete.")
else:
Expand Down
7 changes: 5 additions & 2 deletions brevia/utilities/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def file_url(self, filename: str):
"""
# Generate the output URL
base_url = get_settings().file_output_base_url
if self.job_id:
base_url = f"{base_url}/{self.job_id}"

return f'{base_url}/{filename}'

def _s3_upload(self, file_path: str, bucket_name: str, object_name: str):
Expand Down Expand Up @@ -74,13 +77,13 @@ def write(self, content: str, filename: str):
with open(output_path, 'w', encoding='utf-8') as file:
file.write(content)

if self.job_id:
filename = f"{self.job_id}/{filename}"
base_path = get_settings().file_output_base_path
if base_path.startswith('s3://'):
# Extract bucket name and object name from S3 path
bucket_name = base_path.split('/')[2]
object_name = '/'.join(base_path.split('/')[3:]).lstrip('/')
if self.job_id:
object_name += f"/{self.job_id}"
object_name += f"/{filename}"
Comment on lines +85 to 87
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The job_id is being appended to object_name after it's already constructed from the base path. This could result in double slashes or inconsistent path formatting. Consider building the complete object path more systematically, similar to how it's done in the file_url() method.

Copilot uses AI. Check for mistakes.
self._s3_upload(output_path, bucket_name, object_name.lstrip('/'))
# Remove the local temp file
Expand Down
5 changes: 5 additions & 0 deletions tests/utilities/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def test_file_url():

assert file_url == '/download/test.txt'

output = LinkedFileOutput(job_id='123456789')
file_url = output.file_url('test.txt')

assert file_url == '/download/123456789/test.txt'


def test_write_local_file():
"""Test write method for local file writing."""
Expand Down
Loading