Skip to content

setenv: preserve OMNeT++'s bin/ and python/ after venv activation#5

Open
tabgab wants to merge 1 commit intoomnetpp:mainfrom
tabgab:fix/setenv-preserve-omnetpp-path
Open

setenv: preserve OMNeT++'s bin/ and python/ after venv activation#5
tabgab wants to merge 1 commit intoomnetpp:mainfrom
tabgab:fix/setenv-preserve-omnetpp-path

Conversation

@tabgab
Copy link
Copy Markdown
Contributor

@tabgab tabgab commented Apr 24, 2026

Summary

opp_repl's setenv activates the project's .venv near the top:

if [ -f "$OPP_REPL_ROOT/.venv/bin/activate" ]; then
    . "$OPP_REPL_ROOT/.venv/bin/activate"
fi

bin/activate restores a snapshot of $PATH taken when the venv was
created. For most users that snapshot does NOT include OMNeT++'s
bin/, so after:

source ~/omnetpp/setenv -q         # puts OMNeT++ bin on PATH
source ~/opp_repl/setenv           # venv activate erases it

opp_makemake, opp_run, opp_scavetool and every other OMNeT++
binary falls off PATH, even though the user sourced things in the
"natural" order (dependency first, then dependent). Typical symptom:

$ opp_makemake --help
bash: opp_makemake: command not found

The workaround is to source opp_repl/setenv first — counter-intuitive
since opp_repl depends on OMNeT++, not the other way around.

Change

Capture $__omnetpp_root_dir/{bin,python} BEFORE the venv activation,
then re-prepend them to $PATH / $PYTHONPATH AFTER activation (only
if not already present). Result: both sourcing orders work.

Verified

$ env -i HOME=$HOME PATH=/usr/bin:/bin bash
$ source ~/omnetpp/setenv -q
$ source ~/omnetpp/misc/opp_repl/setenv    # patched
$ command -v opp_makemake opp_run opp_repl
/home/gabor/omnetpp-aipre/bin/opp_makemake
/home/gabor/omnetpp-aipre/bin/opp_run
/home/gabor/omnetpp-aipre/misc/opp_repl/.venv/bin/opp_repl

All three resolve, and opp_repl's own bin/ is still prepended on top
(so opp_repl, opp_run_simulations etc. take precedence for opp_repl-owned
tools).

Context

Found while verifying an Agent Skills pack
(tabgab/opp_repl-skill) that
walks agents through testprompt.txt-style end-to-end scenarios. This
PATH bug was one of the three remaining friction points weak models
couldn't navigate on their own.

The 'source $OPP_REPL_ROOT/.venv/bin/activate' call near the top of
setenv saves a snapshot of $PATH taken when the venv was created and
restores it on each activation.  For most users that snapshot does NOT
include OMNeT++'s bin/ directory, so after:

    source ~/omnetpp/setenv -q         # puts OMNeT++ bin on PATH
    source ~/opp_repl/setenv           # venv activate erases it

`opp_makemake`, `opp_run`, `opp_scavetool` and every other OMNeT++
binary falls off PATH, even though the user sourced things "the right
way around".  Typical symptom:

    $ opp_makemake --help
    bash: opp_makemake: command not found

The workaround was to source opp_repl's setenv FIRST, which is
counter-intuitive since opp_repl depends on OMNeT++ and not the other
way around.  Order independence is what users reasonably expect.

This patch captures $__omnetpp_root_dir's bin/ and python/ paths
BEFORE the venv activation runs, then re-inserts them into $PATH /
$PYTHONPATH AFTER activation (only if they aren't already present).
Result: both sourcing orders give a working environment.

Verified on Ubuntu 24.04 / Python 3.12, OMNeT++ aipre:

    $ env -i HOME=$HOME PATH=/usr/bin:/bin bash
    $ source ~/omnetpp/setenv -q
    $ source ~/omnetpp/misc/opp_repl/setenv   # patched
    $ command -v opp_makemake opp_run opp_repl
    /home/gabor/omnetpp-aipre/bin/opp_makemake
    /home/gabor/omnetpp-aipre/bin/opp_run
    /home/gabor/omnetpp-aipre/misc/opp_repl/.venv/bin/opp_repl

All three resolve, in both sourcing orders.
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