Skip to content

Commit

Permalink
Added missing union type import (cylc#5906)
Browse files Browse the repository at this point in the history
* Added missing union type import

* moved functions back into log_level

---------

Co-authored-by: Mark Dawson <[email protected]>
  • Loading branch information
markgrahamdawson and Mark Dawson authored Jan 4, 2024
1 parent 5a94866 commit 1c1e840
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 95 deletions.
4 changes: 2 additions & 2 deletions cylc/flow/log_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def log_level_to_verbosity(lvl: int) -> int:
>>> log_level_to_verbosity(logging.NOTSET)
2
>>> log_level_to_verbosity(logging.DEBUG)
1
2
>>> log_level_to_verbosity(logging.INFO)
0
>>> log_level_to_verbosity(logging.WARNING)
-1
>>> log_level_to_verbosity(logging.ERROR)
-1
"""
if lvl < logging.DEBUG:
if lvl <= logging.DEBUG:
return 2
if lvl < logging.INFO:
return 1
Expand Down
93 changes: 0 additions & 93 deletions cylc/flow/option_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,99 +182,6 @@ def format_help_headings(string):
)


def verbosity_to_log_level(verb: int) -> int:
"""Convert Cylc verbosity to log severity level."""
if verb < 0:
return logging.WARNING
if verb > 0:
return logging.DEBUG
return logging.INFO


def log_level_to_verbosity(lvl: int) -> int:
"""Convert log severity level to Cylc verbosity.
Examples:
>>> log_level_to_verbosity(logging.NOTSET)
2
>>> log_level_to_verbosity(logging.DEBUG)
2
>>> log_level_to_verbosity(logging.INFO)
0
>>> log_level_to_verbosity(logging.WARNING)
-1
>>> log_level_to_verbosity(logging.ERROR)
-1
"""
if lvl <= logging.DEBUG:
return 2
if lvl < logging.INFO:
return 1
if lvl == logging.INFO:
return 0
return -1


def verbosity_to_opts(verb: int) -> List[str]:
"""Convert Cylc verbosity to the CLI opts required to replicate it.
Examples:
>>> verbosity_to_opts(0)
[]
>>> verbosity_to_opts(-2)
['-q', '-q']
>>> verbosity_to_opts(2)
['-v', '-v']
"""
return [
'-q'
for _ in range(verb, 0)
] + [
'-v'
for _ in range(0, verb)
]


def verbosity_to_env(verb: int) -> Dict[str, str]:
"""Convert Cylc verbosity to the env vars required to replicate it.
Examples:
>>> verbosity_to_env(0)
{'CYLC_VERBOSE': 'false', 'CYLC_DEBUG': 'false'}
>>> verbosity_to_env(1)
{'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'false'}
>>> verbosity_to_env(2)
{'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'true'}
"""
return {
'CYLC_VERBOSE': str((verb > 0)).lower(),
'CYLC_DEBUG': str((verb > 1)).lower(),
}


def env_to_verbosity(env: Union[Dict, os._Environ]) -> int:
"""Extract verbosity from environment variables.
Examples:
>>> env_to_verbosity({})
0
>>> env_to_verbosity({'CYLC_VERBOSE': 'true'})
1
>>> env_to_verbosity({'CYLC_DEBUG': 'true'})
2
>>> env_to_verbosity({'CYLC_DEBUG': 'TRUE'})
2
"""
return (
2 if env.get('CYLC_DEBUG', '').lower() == 'true'
else 1 if env.get('CYLC_VERBOSE', '').lower() == 'true'
else 0
)


class CylcOption(Option):
"""Optparse option which adds a decrement action."""

Expand Down

0 comments on commit 1c1e840

Please sign in to comment.