Skip to content

Make experiments directory handling more robust in linker.py #17

@swu4bnl

Description

@swu4bnl

Problem

In linker.py, line 59, the experiments directory is hard-coded and is joined with the proposal path as follows:

path_expr = path_proposal / "experiments"

This approach is error-prone, especially if users provide the experiments directory as "/experiments", "/", or with extra slashes. As a result, the path can become malformed or absolute when it should remain relative, leading to bugs or user confusion.

Proposal

  • Replace the hard-coded string and manual string manipulation with normalized pathlib.Path logic.
  • Ensure that if a user provides values like "/experiments", "experiments", or "/", the resulting path is always a relative segment joined to path_proposal (not absolute).
  • Optionally, provide a helper function using Path.parts to strip leading slashes or anchors and clarify the intent in code comments.

Example Fix

def make_relative_path(value):
    path = Path(value)
    return Path(*path.parts[1:]) if path.is_absolute() else path

experiments_dir = make_relative_path(doc.get("experiments_directory", "experiments"))
path_expr = path_proposal / experiments_dir

Similar normalization should be applied to the experiment_alias_directory or any other user path input being joined.

Benefits

  • More robust path handling
  • Avoids accidental absolute/incorrect paths
  • Future-proofs for directory configuration changes

Reference

Related to linker.py line 59 and user report.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions