Skip to content

SimulationProject.get_name() prefers the declared name over the directory basename#4

Open
tabgab wants to merge 1 commit intoomnetpp:mainfrom
tabgab:fix/get-name-use-name-attr
Open

SimulationProject.get_name() prefers the declared name over the directory basename#4
tabgab wants to merge 1 commit intoomnetpp:mainfrom
tabgab:fix/get-name-use-name-attr

Conversation

@tabgab
Copy link
Copy Markdown
Contributor

@tabgab tabgab commented Apr 24, 2026

Summary

SimulationProject.get_name() currently returns the directory basename,
not the project's declared name= attribute. When the .opp file sits in
a directory whose name differs from name=, every log and error line
referring to the project uses the wrong identifier.

Real-world symptom (from an agent walking through testprompt.txt in a
new skill pack I built for opp_repl):

Exception: Building mm1k-verify failed      # the project IS named "mm1k"

because /tmp/mm1k-verify/mm1k.opp declares name="mm1k" but the
directory is mm1k-verify.

Change

Two lines in opp_repl/simulation/project.py:

def get_name(self):
    if self.name:
        return self.name
    return os.path.basename(self.get_full_path("."))

Falls back to the directory basename only when no explicit name was
provided (e.g. an OmnetppProject defined purely by root_folder),
preserving existing behaviour for that case.

Reproducer

mkdir /tmp/foo && cd /tmp/foo
cat > myproj.opp <<'OPP'
SimulationProject(
    name="myproj",
    root_folder=".",
    build_types=["executable"],
    executables=["myproj"],
    ned_folders=["."],
    ini_file_folders=["."],
)
OPP
>>> load_opp_file("./myproj.opp")
>>> p = get_simulation_project("myproj")
>>> p.name
'myproj'
>>> p.get_name()
'foo'          # before this change — should be 'myproj'

Context

I maintain tabgab/opp_repl-skill,
a pack of Anthropic-format Agent Skills for driving opp_repl from AI
agents. While verifying the skills end-to-end I hit this issue and
wrote it up. Happy to iterate on the fix if you prefer a different
fallback policy.

…tory basename

When a SimulationProject is loaded from a '.opp' file that explicitly
sets name="mm1k" but the file sits in a directory called 'mm1k-verify',
get_name() currently returns 'mm1k-verify' — the directory basename —
because it only uses os.path.basename(self.get_full_path(".")).

This makes log / error lines confusing:

    Exception: Building mm1k-verify failed   # the project IS named mm1k

With this change, get_name() returns self.name when set, falling back
to the directory basename only when no explicit name was provided
(e.g. for an OmnetppProject defined purely by root_folder).

Reproducer (on any version of main prior to this fix):

    # In a dir /tmp/foo:
    cat > myproj.opp <<'OPP'
    SimulationProject(
        name="myproj",
        root_folder=".",
        build_types=["executable"],
        executables=["myproj"],
        ned_folders=["."],
        ini_file_folders=["."],
    )
    OPP
    # From Python:
    >>> load_opp_file("./myproj.opp")
    >>> p = get_simulation_project("myproj")
    >>> p.name
    'myproj'
    >>> p.get_name()
    'foo'        # <-- should be 'myproj'
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.

1 participant