Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Feat] grass.temporal: Allow passing env instead of using os.environ #7737

Copy link
Copy link

Description

@wenzeslaus
Issue body actions

grass.temporal should behave like other parts of the grass package and allow passing env to allow not using os.environ.

Details and scope (generated with Claude Code)

Current state

tgis.init() resolves the session with gs.gisenv() and no env, then caches it in module-level globals in core.py (current_mapset, current_location, current_gisdbase, tgis_backend, tgis_database*, message_interface, c_library_interface, ...). None of the 64 grass.script calls in python/grass/temporal/ (50 run_command, 7 parse_command, 5 gisenv, 2 read_command) pass env=.

Elsewhere in the package the environment can be explicit: gs.run_command(env=...), Tools(session=session), gs.setup.init(..., env=...).

Describe the solution you'd like

tgis.init(env=session.env)
dbif = tgis.SQLDatabaseInterfaceConnection(env=session.env)

with env threaded through to the grass.script calls underneath. env=None would keep reading os.environ as it does now, so existing code and the global session stay valid.

It would also make it possible to use more than one session in a process, which the rest of the API allows.

Scope

This is not a small change. At minimum it needs:

  • init() to accept env and not rely on gs.gisenv() against the global environment,
  • the session carried on the objects which currently rely on the globals (SQLDatabaseInterfaceConnection, the AbstractDataset hierarchy, ...) rather than module-level state in core.py,
  • env passed at the 64 grass.script call sites,
  • the RPC-backed interfaces (CLibrariesInterface, the messenger), which spawn subprocesses that need the environment too.

So it probably wants to be staged.

Describe alternatives you've considered

A test which needs a session outside the global environment can mirror it into os.environ with monkeypatch, which is what #7732 does. It works, but every caller has to repeat it.

Additional context

This came up while debugging r.coin on the OSGeo4W CI (#7732).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.