Skip to content

Optionally store git metadata in RE md - #266

Merged
josephhanrahan merged 2 commits into
NSLS2:mainfrom
josephhanrahan:git-metadata
Aug 31, 2026
Merged

Optionally store git metadata in RE md#266
josephhanrahan merged 2 commits into
NSLS2:mainfrom
josephhanrahan:git-metadata

Conversation

@josephhanrahan

Copy link
Copy Markdown
Contributor

As part of an effort to have more provenance for blop agents, having the ability to link profile collection code back to an optimization run is important.

This PR adds an optional argument profile_collection_dir to configure_base() which when provided, stores the current ref, branch name, and dirty status to RE.md

@jwlodek

Copy link
Copy Markdown
Contributor

I like the idea, but could we use naming that isn't tied to profile_collection? Maybe startup_dir? It's possible (likely) we'll move away from profile-collections in the future.

@josephhanrahan
josephhanrahan marked this pull request as ready for review August 31, 2026 13:37
Copilot AI lite review requested due to automatic review settings August 31, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds support for recording git provenance for a startup/profile collection repository into the RunEngine’s metadata (RE.md) during nslsii.configure_base() setup, to improve traceability of optimization/profile collection runs.

Changes:

  • Add git_info() helper in nslsii/utils.py to retrieve commit SHA, branch, and dirty status for a local git working tree.
  • Extend configure_base() to optionally store that git metadata into RE.md when a directory is provided.
File summaries
File Description
nslsii/utils.py Adds git_info() helper that shells out to git to collect ref/branch/dirty state.
nslsii/init.py Adds an optional configure_base() argument and writes git metadata into RE.md.
Review details

Suppressed comments (3)

nslsii/init.py:126

  • The docstring parameter name should match the function signature. If the intent is to point at the startup/profile collection repository, document it under the same name (profile_collection_dir) and clarify it should be a git working tree.
    startup_dir : Path, optional
        None by default, path to the repository being used

nslsii/utils.py:135

  • subprocess.check_output(..., cwd=...) can raise other OSError subclasses (e.g. NotADirectoryError) if the provided directory is invalid. Catching OSError here would make git_info reliably return (None, None, None) for any filesystem/path issue, consistent with the current fallback behavior.
    except (subprocess.CalledProcessError, FileNotFoundError):
        return None, None, None

nslsii/init.py:321

  • Using if startup_dir: will skip storing metadata when the caller passes a valid but falsy path-like value (e.g. empty string meaning current directory). Prefer an explicit is not None check, and update the variable name to match the public parameter name. Also use the prevailing double-quote style in this module for consistency.
    # store startup code git repository metadata in RE
    if startup_dir:
        ref, branch, dirty = git_info(startup_dir)
        RE.md['startup_git_metadata'] = {'ref': ref, 'branch': branch, 'dirty': dirty}
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread nslsii/__init__.py
Comment on lines 49 to 53
redis_ssl=False,
redis_prefix="",
redis_db: int = 0,
startup_dir=None,
):
Comment thread nslsii/__init__.py
Comment on lines +318 to +321
# store startup code git repository metadata in RE
if startup_dir:
ref, branch, dirty = git_info(startup_dir)
RE.md['startup_git_metadata'] = {'ref': ref, 'branch': branch, 'dirty': dirty}
Comment thread nslsii/utils.py
return conn


def git_info(git_dir: Path) -> tuple[str, str, bool] | tuple[None, None, None]:
@josephhanrahan
josephhanrahan merged commit cf1fc74 into NSLS2:main Aug 31, 2026
3 checks passed
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.

3 participants