Skip to content

Feature Request: Set env variable during virtual env installation #1606

@hehaoqian

Description

@hehaoqian

Summary

The env configuration as described in https://prek.j178.dev/configuration/#args,
only have effect during the execution of the hook,
but have no effect during the virtualenv installation.


The current document is a bit unclear:

  1. The scope of the env configuration, if it is effective during virtualenv installation.
  2. The doc of the upstream pre-commit, describe the semantic of .pre-commit-hooks.yaml and .pre-commit-config.yaml separately. The preks only describe the semantic of .pre-commit-config.yaml and Prek says that it followes the format of upstream .pre-commit-hooks.yaml.
    So env field does not work in .pre-commit-hooks.yaml? Is this a delibreate design choice?

I am asking for additional configuration option, to set the env variable during the virtualenv installation.
This is useful for enterprise to setup mirror to download the package, because the internet access is often restricted.

Actually, setup env variable during venv installation, is more needed than env for hook execution, because the env can always be set by alternative entry, but no similar way for additional_dependencies.

I currently setup mirror by --index-url in additional_dependencies of python language,
but for several language, this is not possible,
such as setting mirror for the node language,
because both the mirror to nodeenv to download the nodejs,
and the mirror to npm registry, need to be set.

I know I can run the git hooks in a docker container with all mirror related env vars set,
but I would like to distribute the env as part of the git hooks.


Alternatively, a separate .env file may be desired, so it is easier to apply the environment variable globally, for both local hooks defined in .pre-commit-config.yaml
and the remote hooks defined in .pre-commit-hooks.yaml.

Document should describe how the configuration are merged, and if the local .env can unset the env variable set by the remote .env

Platform

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 GNU/Linux

Version

prek 0.3.2

.pre-commit-config.yaml

N/A

Log file

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    thinkingI'm thinking on this

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions