Visitar URL original
Support configuring run-time environment options generically · Issue #1157 · pre-commit/pre-commit · GitHub
The Wayback Machine - https://web.archive.org/web/20201130225616/https://github.com/pre-commit/pre-commit/issues/1157
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

Support configuring run-time environment options generically #1157

Closed
eigengrau opened this issue Oct 5, 2019 · 3 comments
Closed

Support configuring run-time environment options generically #1157

eigengrau opened this issue Oct 5, 2019 · 3 comments
Labels

Comments

@eigengrau
Copy link

@eigengrau eigengrau commented Oct 5, 2019

It would be useful if we could configure certain aspects of the run-time environment from which hooks are run. E.g., I would find it awesome if I could:

  • set arbitrary environment variables for some or all hooks that are run
  • source a piece of shell-code before a hook is run
  • switch into a subdirectory of the repository before running the hook’s entry-point

My immediate use-case is to work-around ansible/ansible-lint#245, which would require both custom environment variables as well as switching the working directory. However, I expect that this would be great to have for other situations, as well.

E.g., while pre-commit does a great job of isolating a hooks environment by installing all dependencies of a Python-hosted hooks in an isolated location, a lot of my co-workers are using outdated distributions resp. Python installations. To keep our workflow as uniform as possible, I take steps which will create repository-local installations of Python, Node.js and other run-times. For working on the command-line, I usually rely on direnv to install any run-times and to adjust the user’s PATH so that repository-local installations are used. It would be great if I could configure pre-commit so that, prior to running any hook, pre-commit would source a script of my choosing.

Thank you for making pre-commit!

@asottile
Copy link
Member

@asottile asottile commented Oct 5, 2019

you can do that with env or bash-- this is already demonstrated here: #758 (comment)

@asottile asottile closed this Oct 5, 2019
@asottile asottile reopened this Oct 5, 2019
@asottile asottile added the question label Oct 5, 2019
@asottile asottile closed this Oct 7, 2019
@eigengrau
Copy link
Author

@eigengrau eigengrau commented Oct 7, 2019

Thank you for the pointer! I guess overriding the entrypoint should work out in our case, even though it increases the coupling between configuration and hook. It’s a bit problematic that the entrypoint is not passed through a shell. Going via bash -c adds another level of quoting, so a generic mechanism would be great. Alternatively, having the entrypoint command pass through a shell (perhaps optionally) would be useful. If you think that’s something worth having I could see if I can find some time to look into the code.

@asottile
Copy link
Member

@asottile asottile commented Oct 7, 2019

It’s a bit problematic that the entrypoint is not passed through a shell

well for a couple reasons:

  • shells mean shell injections mean CVEs, no no no
  • pre-commit is cross platform where you may not have a consistent shell (windows, macos, future macos, etc.)

Going via bash -c adds another level of quoting,

you'd have the same level of quoting either way as you have to make a shell command. yaml supports bare words so you probably don't need anything tricky here anyway

Alternatively, having the entrypoint command pass through a shell (perhaps optionally) would be useful. If you think that’s something worth having I could see if I can find some time to look into the code.

thanks for the suggestion, but no (as per above)

pre-commit has a golden path which is where pre-commit manages all the environments and dependencies. when you start to step outside that you're going to need to do tricky things -- pre-commit is not going to support those directly because it steps outside the bounds of the happy path (requiring extra setup on the user's side, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.