Skip to content

Add a NAV_CONFIG_DIR environment variable to override NAV configuration file search path#3697

Merged
lunkwill42 merged 5 commits intomasterfrom
chore/manipulate-config-dir
Dec 16, 2025
Merged

Add a NAV_CONFIG_DIR environment variable to override NAV configuration file search path#3697
lunkwill42 merged 5 commits intomasterfrom
chore/manipulate-config-dir

Conversation

@lunkwill42
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 commented Dec 15, 2025

Scope and purpose

The NAV_CONFIG_DIR environment variable can now be used to insert a custom directory as the first entry in the list of directories NAV will search for its config files.

This would mostly be useful to manipulate where NAV code searches for configuration files during tests. Currently, the test suite sort of depends on tox and the manipulation of config files below the current virtualenv directory, but this is not conducive to running tests interactively during development, since it would cause tests to use the developer's currently active configuration files rather than a set created in a temporary directory for the tests.

I.e. this PR adds the option both for users to manipulate this if needed, and lays the groundwork for the test suite to be able to more properly manipulate test configuration in isolated environments.

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

The NAV_CONFIG_DIR environment variable can be used to insert a custom
directory as the first entry in the list of directories NAV will search
for its config files.

This would mostly be useful to manipulate where NAV code searches for
configuration files during tests. Currently, the test suite sort of
depends on tox and the manipulation of config files below the current
virtualenv directory, but this is not conducive to running tests
interactively during development, since it would cause tests to use
the developer's currently active configuration files rather than
a set created in a temporary directory for the tests.
Change any code that uses the `CONFIG_LOCATIONS` global variable
directly to instead use the new `get_config_locations()` function.
This adds tests that will test the proper behavior when manipulating
the `NAV_CONFIG_DIR` environment variable.
@lunkwill42 lunkwill42 self-assigned this Dec 15, 2025
@lunkwill42 lunkwill42 requested a review from a team December 15, 2025 15:13
@lunkwill42 lunkwill42 marked this pull request as ready for review December 15, 2025 15:22
@lunkwill42 lunkwill42 changed the title Chore/manipulate config dir Add a NAV_CONFIG_DIR environment variable to override NAV configuration files directory Dec 15, 2025
@lunkwill42 lunkwill42 changed the title Add a NAV_CONFIG_DIR environment variable to override NAV configuration files directory Add a NAV_CONFIG_DIR environment variable to override NAV configuration file search path Dec 15, 2025
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test results

    27 files      27 suites   46m 1s ⏱️
 2 736 tests  2 736 ✅ 0 💤 0 ❌
20 278 runs  20 278 ✅ 0 💤 0 ❌

Results for commit bdbcd25.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.07%. Comparing base (a30882c) to head (bdbcd25).
⚠️ Report is 385 commits behind head on master.

Files with missing lines Patch % Lines
python/nav/bin/navmain.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3697   +/-   ##
=======================================
  Coverage   63.07%   63.07%           
=======================================
  Files         612      612           
  Lines       45239    45245    +6     
  Branches       43       43           
=======================================
+ Hits        28533    28537    +4     
- Misses      16696    16698    +2     
  Partials       10       10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@hmpf hmpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the function and the use of pathlib is an improvement!

Copy link
Copy Markdown
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, maybe the documentation that you added to the install guides can also be added to https://nav.readthedocs.io/en/latest/hacking/hacking.html#running-tests since you said it was to be used when running tests in the future

@lunkwill42
Copy link
Copy Markdown
Member Author

Looks good, maybe the documentation that you added to the install guides can also be added to https://nav.readthedocs.io/en/latest/hacking/hacking.html#running-tests since you said it was to be used when running tests in the future

Not in this PR, since nothing in the test suite is affected by this yet. I have commits for future PRs that adds a config-dir fixture which can be used for configuration manipulation, and when I get around to making that work properly (with tests that show how to use it) would be the right time to add more docs.

@lunkwill42 lunkwill42 merged commit 10872c7 into master Dec 16, 2025
19 checks passed
@lunkwill42 lunkwill42 deleted the chore/manipulate-config-dir branch December 16, 2025 12:17
@johannaengland
Copy link
Copy Markdown
Contributor

Looks good, maybe the documentation that you added to the install guides can also be added to https://nav.readthedocs.io/en/latest/hacking/hacking.html#running-tests since you said it was to be used when running tests in the future

Not in this PR, since nothing in the test suite is affected by this yet. I have commits for future PRs that adds a config-dir fixture which can be used for configuration manipulation, and when I get around to making that work properly (with tests that show how to use it) would be the right time to add more docs.

Goody, just didn't want that part to be forgotten :)

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.

3 participants