Skip to content

feat: make environment flag parsing consistent with click#4443

Merged
provinzkraut merged 13 commits intolitestar-org:mainfrom
7576457:fix/4422
Jan 8, 2026
Merged

feat: make environment flag parsing consistent with click#4443
provinzkraut merged 13 commits intolitestar-org:mainfrom
7576457:fix/4422

Conversation

@7576457
Copy link
Copy Markdown
Contributor

@7576457 7576457 commented Oct 17, 2025

Description

As mentioned in the issue, handling environment variables is currently inconsistent.
This PR aims to address this by using Click for a more consistent solution:

  • Add a new --quiet-console flag to control LITESTAR_QUIET_CONSOLE.
  • Introduce envflag(), which returns True for 1, true, t, yes, on, y, and False otherwise.
  • Apply envflag() wherever CLI or other code reads environment variables representing flags.

Closes

Also add a new utility function:
- envflag(): parses environment variables as boolean

Applied envflag() to read some environment variables
@github-actions github-actions Bot added area/private-api This PR involves changes to the privatized API size: small pr/external Triage Required 🏥 This requires triage labels Oct 17, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.85%. Comparing base (896fe1f) to head (9c9c7c9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4443      +/-   ##
==========================================
+ Coverage   97.83%   97.85%   +0.01%     
==========================================
  Files         297      297              
  Lines       15321    15336      +15     
  Branches     1716     1720       +4     
==========================================
+ Hits        14990    15007      +17     
+ Misses        189      188       -1     
+ Partials      142      141       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@7576457 7576457 changed the title Make environment flag parsing consistent with Click feat: make environment flag parsing consistent with click Oct 19, 2025
@github-actions
Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4443

@7576457 7576457 marked this pull request as ready for review October 19, 2025 17:40
@7576457 7576457 requested review from a team as code owners October 19, 2025 17:40
Comment thread litestar/utils/helpers.py Outdated
Comment thread litestar/utils/helpers.py
Comment thread litestar/utils/helpers.py Outdated
Comment thread tests/unit/test_utils/test_helpers.py Outdated
 * envflag: removed default parameter.
 * envflag: behavior now matches click.BoolParamType.
 * envflag: raises an error if none of the conditions are met.
 * tests(envflag): updated tests and applied monkeypatch.
@7576457
Copy link
Copy Markdown
Contributor Author

7576457 commented Oct 23, 2025

@provinzkraut
I’ve applied your feedback and made the changes. Please review them.
Also, I have a question regarding raising an error.

I’m currently using LitestarException. Would it be better to create a more specific error, for example LitestarEnvironmentError, in litestar/exceptions/base_exceptions.py?

Comment thread litestar/utils/helpers.py Outdated
@provinzkraut
Copy link
Copy Markdown
Member

Looks like you need to adjust the code to reflect the new default behaviour

- Set default=True for warning flags to keep them enabled by default
- Remove redundant bool() cast for quiet_console flag
- Add test for envflag() with default=True parameter
@7576457
Copy link
Copy Markdown
Contributor Author

7576457 commented Jan 7, 2026

Looks like you need to adjust the code to reflect the new default behaviour

Yes, you’re right. I’ve made the changes.
I only ended up using the default parameter in litestar/utils/warnings.py.
In the other places, it didn’t seem necessary

@provinzkraut provinzkraut enabled auto-merge (squash) January 8, 2026 19:23
@provinzkraut provinzkraut merged commit 1ad551c into litestar-org:main Jan 8, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/private-api This PR involves changes to the privatized API pr/external pr/internal size: small Triage Required 🏥 This requires triage type/feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants