Skip to content

feat: add pattern-filtered staging upload helper (#60)#64

Merged
underchemist merged 2 commits into
developfrom
60-staging-upload
Jul 7, 2026
Merged

feat: add pattern-filtered staging upload helper (#60)#64
underchemist merged 2 commits into
developfrom
60-staging-upload

Conversation

@underchemist

Copy link
Copy Markdown
Collaborator

Summary

Implements #60 — the staging upload helper for the end-to-end ingest workflow (parent #56).

Adds upload_source_files, which uploads only the local files a source file set's pattern selects, preserving each file's path relative to its location so the spec's pattern keeps matching after the files move to S3.

What's included

  • prescient_sdk/upload.py:
    • upload_source_files(local_dir, dest_prefix, pattern, session, on_file=None, overwrite=True) — selects files whose posix path relative to local_dir matches pattern (anchored re.match, matching the Ingest API's own selection), and uploads each to dest_prefix + that relative path verbatim. It deliberately does not inject the local directory name into the key (that would shift relative paths and break pattern matching). Reuses the existing iter_files and _upload. The on_file(index, total, path) callback enables progress display without coupling the upload layer to Rich.
    • _split_s3_uri — parses an s3://bucket/key/prefix URI into (bucket, key_prefix).
  • prescient_sdk/config.py — optional prescient_upload_prefix setting for composing destination prefixes under the upload bucket.

dest_prefix is a full s3://… URI so the same value can be reused as the rewritten location.path when staging an IngestSpec (#61) — one source of truth for where files land and where the spec points.

Acceptance criteria

  • Helper uploads only files matching the pattern (anchored, relative posix path); non-matching files skipped
  • Object keys are exactly {dest_prefix}{relative_path} with no injected directory-name segment
  • on_file callback fires once per uploaded file with (index, total, path)
  • prescient_upload_prefix added to settings (optional)
  • moto-backed tests assert the uploaded key set and the re.match semantics

Testing

  • uv run pytest — 123 passed
  • uv run ruff check prescient_sdk/ tests/ — clean; files formatted with ruff format

Closes #60

🤖 Generated with Claude Code

underchemist and others added 2 commits July 2, 2026 13:45
Add upload_source_files() for staging local source files into the upload
bucket ahead of ingestion.

- upload_source_files(local_dir, dest_prefix, pattern, session, on_file,
  overwrite): uploads only files whose posix path relative to local_dir
  matches the pattern (re.match, anchored — the same selection the Ingest
  API performs), writing each to dest_prefix + relative_path verbatim. It
  does NOT inject the local directory name into the key, so each file's
  path relative to its location is preserved and the spec's pattern still
  matches after the move to S3. An on_file(index, total, path) callback
  supports progress display without coupling the upload layer to a display
  library.
- _split_s3_uri() parses an s3:// destination URI into (bucket, key_prefix).
- Add optional prescient_upload_prefix setting for composing destination
  prefixes under the upload bucket.

dest_prefix is a full s3:// URI so the same value can be reused as the
rewritten location.path when staging an IngestSpec (#61).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Factor the relative-key computation out of upload_source_files into
_relative_posix() so the cross-platform separator handling is explicit and
unit-testable, and route both the pattern match and the object key through it.

Add tests asserting that a Windows source tree yields forward-slash S3 keys
(keys never contain backslashes) and that a forward-slash spec pattern matches
nested files regardless of local OS separator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@michaelconnor00 michaelconnor00 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@underchemist
underchemist merged commit e7bab11 into develop Jul 7, 2026
4 checks passed
@underchemist
underchemist deleted the 60-staging-upload branch July 7, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants