Skip to content

absolute paths in currentdir (conditionmanager) #178

Open

Description

@sivogel

Sometimes, instead of changing to a directory via os.chdir(), I set the current directory of the control manager to an absolute path. This is especially helpful when copying models from one directory to another.
However, it is not intended for absolute paths to be used. When condition files are saved, the control file that is generated is linked in the control check. In the case of absolute paths, this should be a raw string, but it is not.

As an example: This is part of the condition file as an outcome of setting absolute paths in the control manager:

controlcheck(projectdir=r"weisse_elster", controldir="G:\fis2408407\04_Reali\04_HydPy_Modelle\operational_models\202511.1\weisse_elster\model\control\default", stepsize="1h")

Activity

  1. tyralla commented on Jan 20, 2026

    @tyralla
    Member

    I am unsure about the desired behaviour. I think controlcheck currently only works for the standard project directory structure.

    Maybe we could support two different signatures:

    @overload
    def controlcheck(
        controldirname: str = "default",   # minor breaking change
        projectdir: str | None = None,
        controlfile: str | None = None,
        firstdate: timetools.DateConstrArg | None = None,
        stepsize: timetools.PeriodConstrArg | None = None,
    ) -> None:
    
    @overload
    def controlcheck(
        controldirpath: str,
        controlfile: str | None = None,
        firstdate: timetools.DateConstrArg | None = None,
        stepsize: timetools.PeriodConstrArg | None = None,
    ) -> None:

    Model.save_conditions could then use the first version if pub.controlmanager.currentdir is a simple directory name or a complete path that points to the "normal" location of condition files. And it could use the second version if pub.controlmanager.currentdir is a full path pointing to a "special" location.

    There are likely cases where this heuristic would not yield the desired results. Users may sometimes be unsure if and how they will move directories later. So, we should probably also add something like an omit_controlcheck option to Model.save_conditions and HydPy.save_conditions.

    Any objections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions