Skip to content

contributing: Replace manual env exports with generate-then-source pattern#7200

Open
wenzeslaus wants to merge 1 commit intoOSGeo:mainfrom
wenzeslaus:improve-agents-test-instructions
Open

contributing: Replace manual env exports with generate-then-source pattern#7200
wenzeslaus wants to merge 1 commit intoOSGeo:mainfrom
wenzeslaus:improve-agents-test-instructions

Conversation

@wenzeslaus
Copy link
Copy Markdown
Member

Instead of requiring command substitution on every test invocation,
document a pattern where resolved paths are written to a .grass_build_env
file once and sourced before each pytest call. Add the generated file
to .gitignore.

…ttern

Instead of requiring command substitution on every test invocation,
document a pattern where resolved paths are written to a .grass_build_env
file once and sourced before each pytest call. Add the generated file
to .gitignore.
@echoix
Copy link
Copy Markdown
Member

echoix commented Mar 19, 2026

So finally, you're reinventing the .env convention, but with another file name? There exist some tooling to help preventing .env commuting. There's also some conventions for how to name other production, staging, etc. .env files. Why not try that?

There's even some pytest plugins for that

@wenzeslaus
Copy link
Copy Markdown
Member Author

I meant to open as draft. What was your suggestion for .env?

@echoix
Copy link
Copy Markdown
Member

echoix commented Mar 19, 2026

For the name, either .env or .env.something, and the contents are plain KEY=Value lines. And it works on windows too. The contents of that file are already well defined and understood, across various programming languages/environments

@github-actions github-actions bot added docs markdown Related to markdown, markdown files labels Mar 19, 2026
@wenzeslaus
Copy link
Copy Markdown
Member Author

I'm not sure if I understand what you think should happen next with .env. How do you think it should work with pytest?

From what I understood so far, PYTHONPATH needs to be set from outside, pytest-dotenv seems to deal with variables, not path, which fits with .env, but does not allow the modification of sys.path we need. LD_LIBRARY_PATH needs to be set up before the process starts for the library loading automation to work. PATH works, but if we can't import from the grass package, it is not that useful.

A conftest.py file in repo root would help, but we can have that. pytest plugins need to be importable, so no help there either. The only thing I can see that pytest's pythonpath and addopts may work together. Did you consider this in the past?

  [tool.pytest.ini_options]                                                                                                                                                                   
  pythonpath = ["python/grass/tests"]
  addopts = "-p grass_test_env" 
# Exists
ls python/grass/tests/grass_test_env.py

@wenzeslaus
Copy link
Copy Markdown
Member Author

In the pythonpath+addopts scenario, the python/grass/tests/grass_test_env.py (or maybe utils/grass_test_env.py) file needs to at least partially duplicate init code, but in a more hardcore way than grass.py or the grass package because it does not have any of those paths to start with (grass.py is running or the grass package was imported, so they know about themselves at least and can fill in the other part). Alternatively, the file needs to be generated by the user/agent, but than it is not part of the repo, so addopts links to a non-existent file.

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

Labels

docs markdown Related to markdown, markdown files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants