-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(hosting-cli): make reflex-base an optional dependency #6939
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
Open
adhami3310
wants to merge
5
commits into
main
Choose a base branch
from
claude/reflex-hosting-cli-deps-31c397
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3296f3
fix(hosting-cli): make reflex-base an optional dependency
adhami3310 ee7706f
test(hosting-cli): guard the advertised minimum reflex version
adhami3310 3c30ee8
fix(hosting-cli): complete the forked LogLevel API and stop test stat…
adhami3310 c765d9f
test(hosting-cli): ban only the framework packages, not every workspa…
adhami3310 6cd5694
Merge main into the reflex-base optional-dependency branch
adhami3310 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| The hosting CLI's forked console module and `LogLevel` enum are now shims over `reflex-base` (new dependency), and its logging goes through standard python `logging`. Debug output renders purple (was blue), errors go to stderr (was stdout), and success messages are hidden at `--loglevel warning`. | ||
| The hosting CLI's logging goes through standard python `logging`. On reflex 0.9 and up it shares the `reflex-base` console and `LogLevel`; on earlier reflex, where `reflex-base` is not installed, the CLI renders the same output itself. Debug output renders purple (was blue), errors go to stderr (was stdout), and success messages are hidden at `--loglevel warning`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/reflex-hosting-cli/src/reflex_cli/constants/log_level.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """The hosting CLI's own LogLevel, used when reflex-base is not installed. | ||
|
|
||
| reflex-base only exists from reflex 0.9 on, but the hosting CLI supports older | ||
| reflex too. :mod:`reflex_cli.constants.base` prefers the reflex-base enum when | ||
| it is importable and falls back to this one otherwise; the two are | ||
| interchangeable, with the same members and the same string values. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class LogLevel(str, Enum): | ||
| """The log levels.""" | ||
|
|
||
| DEBUG = "debug" | ||
| DEFAULT = "default" | ||
| INFO = "info" | ||
| WARNING = "warning" | ||
| ERROR = "error" | ||
| CRITICAL = "critical" | ||
|
|
||
| @classmethod | ||
| def from_string(cls, level: str | None) -> LogLevel | None: | ||
| """Convert a string to a log level. | ||
|
|
||
| Args: | ||
| level: The log level as a string. | ||
|
|
||
| Returns: | ||
| The log level, or None if the string names no level. | ||
| """ | ||
| if not level: | ||
| return None | ||
| try: | ||
| return cls[level.upper()] | ||
| except KeyError: | ||
| return None | ||
|
|
||
| def to_logging_level(self) -> int: | ||
| """Map this level to a stdlib logging level number. | ||
|
|
||
| DEFAULT acts as a threshold equivalent to INFO. | ||
|
|
||
| Returns: | ||
| The stdlib logging level. | ||
| """ | ||
| return _LOGGING_LEVELS[self] | ||
|
|
||
| def subprocess_level(self) -> LogLevel: | ||
| """Return the log level to hand to a subprocess. | ||
|
|
||
| Returns: | ||
| This level, or WARNING when it is DEFAULT. | ||
| """ | ||
| return self if self != LogLevel.DEFAULT else LogLevel.WARNING | ||
|
|
||
| # The str mixin supplies alphabetical comparisons, so all four operators | ||
| # must be overridden to compare by verbosity rank instead. | ||
| def __lt__(self, other: LogLevel) -> bool: | ||
| """Compare log levels. | ||
|
|
||
| Args: | ||
| other: The other log level. | ||
|
|
||
| Returns: | ||
| True if the log level is less verbose than the other log level. | ||
| """ | ||
| return _LOG_LEVEL_RANK[self] < _LOG_LEVEL_RANK[other] | ||
|
|
||
| def __le__(self, other: LogLevel) -> bool: | ||
| """Compare log levels. | ||
|
|
||
| Args: | ||
| other: The other log level. | ||
|
|
||
| Returns: | ||
| True if the log level is less than or equal to the other log level. | ||
| """ | ||
| return _LOG_LEVEL_RANK[self] <= _LOG_LEVEL_RANK[other] | ||
|
|
||
| def __gt__(self, other: LogLevel) -> bool: | ||
| """Compare log levels. | ||
|
|
||
| Args: | ||
| other: The other log level. | ||
|
|
||
| Returns: | ||
| True if the log level is more verbose-restrictive than the other. | ||
| """ | ||
| return _LOG_LEVEL_RANK[self] > _LOG_LEVEL_RANK[other] | ||
|
|
||
| def __ge__(self, other: LogLevel) -> bool: | ||
| """Compare log levels. | ||
|
|
||
| Args: | ||
| other: The other log level. | ||
|
|
||
| Returns: | ||
| True if the log level is greater than or equal to the other. | ||
| """ | ||
| return _LOG_LEVEL_RANK[self] >= _LOG_LEVEL_RANK[other] | ||
|
|
||
|
|
||
| _LOG_LEVEL_RANK = {level: rank for rank, level in enumerate(LogLevel)} | ||
| _LOGGING_LEVELS = { | ||
| LogLevel.DEBUG: logging.DEBUG, | ||
| LogLevel.DEFAULT: logging.INFO, | ||
| LogLevel.INFO: logging.INFO, | ||
| LogLevel.WARNING: logging.WARNING, | ||
| LogLevel.ERROR: logging.ERROR, | ||
| LogLevel.CRITICAL: logging.CRITICAL, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.