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

Provide environment variables for CLI option defaults #754

Closed
3 tasks done
bittner opened this issue Mar 29, 2024 · 3 comments · Fixed by #755
Closed
3 tasks done

Provide environment variables for CLI option defaults #754

bittner opened this issue Mar 29, 2024 · 3 comments · Fixed by #755
Labels
enhancement New feature or request

Comments

@bittner
Copy link
Contributor

bittner commented Mar 29, 2024

Pre-submission checks

  • I am not reporting a new vulnerability or requesting a new vulnerability identifier. These must be reported or managed via upstream dependency sources or services, not this repository.
  • I agree to follow the PSF Code of Conduct.
  • I have looked through the open issues for a duplicate request.

What's the problem this feature will solve?

Currently, we can only use command line options to configure behavior of pip-audit. There is no way to configure its behavior once and retain the configuration for follow-up runs.

Describe the solution you'd like

Every CLI option should have its default value configurable via an environment variable (following an easy-to-remember naming scheme). Using a CLI option should take precedence over any such value.

This way, in a terminal one could use export PIP_AUDIT_...=.... In the YAML file of popular CI systems one could set environment variables in the respective ENVIRONMENT section or similar.

Example Implementation

parser.add_argument("-f", "--format", default=os.environ.get("PIP_AUDIT_FORMAT", "columns"))
parser.add_argument("-o", "--output", default=os.environ.get("PIP_AUDIT_OUTPUT", "stdout"))
parser.add_argument("--progress-spinner", default=os.environ.get("PIP_AUDIT_PROGRESS_SPINNER", "on"))
parser.add_argument("--timeout", default=os.environ.get("PIP_AUDIT_TIMEOUT", "15"))

Additional context

This suggestion would be complementary to #694, but quicker, easier and more straight-forward to implement as it is without the complexity of reading a configuration file.

@bittner bittner added the enhancement New feature or request label Mar 29, 2024
@woodruffw
Copy link
Member

Thanks for the feature request @bittner!

I have no objection to environment variables for fallbacks here, with two qualifications:

  1. We should probably only do this for flags that are "solely" pip-audit flags, i.e. not ones that overlap with pip. For flags that overlap with pip, we should respect whatever environment variables pip already respects (we might do this transitively already).
  2. We probably don't want environmental defaults for things like -r requirements.txt, since having those kinds of inputs passed via the environment makes the overall command's behavior harder to diagnose (especially in bug reports). Instead, it should only be for "knob" inputs, i.e. bools, selections, ints.

@bittner
Copy link
Contributor Author

bittner commented Mar 30, 2024

@woodruffw I sympathize with your reasoning. It requires more care and effort, though, w.r.t. documenting the CLI options.

I started a PR that adds a few environment variables for overriding the CLI option defaults. I'd be happy if you could verify whether the ones are covered that you thought should be used, and those omitted you didn't want to be covered.

@woodruffw
Copy link
Member

I started a PR that adds a few environment variables for overriding the CLI option defaults. I'd be happy if you could verify whether the ones are covered that you thought should be used, and those omitted you didn't want to be covered.

Awesome, thank you! I'll take a look in a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants