Skip to content

build(direnv): Make direnv .envrc idempotent so it doesn't do all that work all the time - #7520

Merged
rfay merged 4 commits into
ddev:mainfrom
rfay:20250810_rfay_envrc
Aug 12, 2025
Merged

rfay merged 4 commits into
ddev:mainfrom
rfay:20250810_rfay_envrc

Conversation

@rfay

@rfay rfay commented Aug 10, 2025 •

Copy link
Copy Markdown
Member

The Issue

Every time I switch into a ddev directory (a lot) I get several seconds of useless work being done:

direnv: loading ~/workspace/ddev/.envrc
Initializing python nodeenv...
Requirement already satisfied: nodeenv in ./.gotmp/env/python/lib/python3.13/site-packages (1.9.1)

[notice] A new release of pip is available: 25.1.1 -> 25.2
[notice] To update, run: pip install --upgrade pip
 * Environment already exists: .gotmp/env/node
./.envrc:47: .gotmp/env/node/bin/activate: No such file or directory
Installing markdownlint...

changed 104 packages in 2s

54 packages are looking for funding
  run `npm fund` for details
Installing linkspector...
⠼direnv: ([/opt/homebrew/bin/direnv export bash]) is taking a while to execute. Use CTRL-C to give up.

changed 231 packages in 5s

93 packages are looking for funding
  run `npm fund` for details
Installing textlint...

changed 298 packages in 6s

92 packages are looking for funding
  run `npm fund` for details
direnv: export +VIRTUAL_ENV +VIRTUAL_ENV_PROMPT ~PATH

How This PR Solves The Issue

Make it check to see if things are already properly installed and not do them in that case.

Manual Testing Instructions

Rendered at https://ddev--7520.org.readthedocs.build/en/7520/developers/building-contributing/#helpers-for-mkdocs-linkspector-markdownlint

Use it in .envrc

  • cd into ddev dir see easy fast response
  • rm -r .gotmp/env
  • Switch out
  • Switch back in, see installs happen
  • Switch out
  • Switch back in, see fast result

Questions

Why are we even installing these things in the project instead of an external directory like ~/.cache? It's conceivably possible that some dependency of mkdocs could change, but it doesn't seem like it ever happens. I think that's the key question. And in that case... does it need to be done in .envrc at all?

Comments

Assisted by ChatGPT

@rfay
rfay requested a review from a team as a code owner August 10, 2025 12:38

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

direnv: loading ~/workspace/ddev/.envrc
Initializing python nodeenv...
Requirement already satisfied: nodeenv in ./.gotmp/env/python/lib/python3.13/site-packages (1.9.1)

I don't see any of this, my ~/.bashrc contains:

export DIRENV_LOG_FORMAT=

But without it, I see only this line:

direnv: loading ~/code/ddev/ddev/.envrc

If this change can improve that behavior, I'm fine with it.

P.S. The current PR adds some logic instead of replacing it.

@rfay

rfay commented Aug 11, 2025

Copy link
Copy Markdown
Member Author

Does your system take several seconds in the switch?

What do you think about a global location for these tools, instead of project location?

@stasadev

Copy link
Copy Markdown
Member

Does your system take several seconds in the switch?

No.

And I didn't try this PR yet because of added changes.

What do you think about a global location for these tools, instead of project location?

If it can be done in a different way, I would like to see it.

@rfay

rfay commented Aug 11, 2025

Copy link
Copy Markdown
Member Author

Actually, I would probably just make a script that does the install work into a global location in the PATH, and not update it very often, instead of tieing it to a specific repository/branch/directory.

@rfay

rfay commented Aug 11, 2025

Copy link
Copy Markdown
Member Author

I cleaned up the duplication, maybe you can experiment with it now.

However, I'd still rather this be a script in the scripts directory that sets up the venv on the system instead of per project. I don't remember seeing a project where that would be a problem.

If you're OK with this one, let's get it in so I can continue to use direnv without pain, and then I'll pursue a system-venv setup as an alternate technique in an alternate PR.

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Works for me.

There is no direnv in our docs, I think a mention would be nice, somewhere in https://ddev.readthedocs.io/en/stable/developers/building-contributing/

@rfay
rfay requested a review from a team as a code owner August 12, 2025 12:07
@rfay
rfay force-pushed the 20250810_rfay_envrc branch from d1a065e to 8178161 Compare August 12, 2025 12:11
@rfay
rfay requested a review from stasadev August 12, 2025 12:13
@rfay

rfay commented Aug 12, 2025

Copy link
Copy Markdown
Member Author

Added docs.

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@rfay
rfay merged commit ff6fda3 into ddev:main Aug 12, 2025
@rfay
rfay deleted the 20250810_rfay_envrc branch August 12, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants