Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose an env variable that indicates if pre-commit is running #1426

Closed
lorenzwalthert opened this issue May 2, 2020 · 3 comments · Fixed by #1467
Closed

Expose an env variable that indicates if pre-commit is running #1426

lorenzwalthert opened this issue May 2, 2020 · 3 comments · Fixed by #1467
Labels

Comments

@lorenzwalthert
Copy link
Contributor

In some circumstances, it could be helpful to know inside an executable / function / script if it was invoked from pre-commit or from some other process. I wrote a hook that just printed all env variables set but I could not find an env variable like PRECOMMIT_RUNNING or similar. Would you consider setting such an env variable during running pre-commit? I searched old issues and documentation but I could not find anything.

@asottile
Copy link
Member

asottile commented May 2, 2020

I'd be curious to hear the concrete usecase, it seems a bit odd to need to know this information

@lorenzwalthert
Copy link
Contributor Author

lorenzwalthert commented May 2, 2020

The use case is hacky so I don't post this on GitHub to maintain good reputation 😄 (#todayInOpensource). Well, the thing is that R has a startup process that runs something like a .bash_rc and this may be slow, depending on the code people put in and it is in mostly not necessary for the hooks. The startup process is ran every time a hook is invoked that uses R by default. With the proposed solution above, they could run this code conditional on whether or not a hook invokes the startup process.

Other approach is to always exclude this .bash_rc-like file from startup. But since shebang does generally only take one argument, I can't set the option for excluding (--vanilla) in the shebang #!/usr/bin/env Rscript when using the script language, which is the language used for my hooks. Also, this would make it impossible for people to include it again for whatever reason they have, which I may want to allow.

I understand if you don't want to support this hack 😊. It's also only a minor problem.

@asottile
Copy link
Member

asottile commented May 2, 2020

The use case is hacky so I don't post this on GitHub to maintain good reputation 😄 (#todayInOpensource).

lol, I know that feel ;)

it should be easy to add something that sets PRE_COMMIT=1 or something -- probably would go in pre_commit/command/run.py if you'd like to send a patch

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

Successfully merging a pull request may close this issue.

2 participants