From e47399dc381d8a8d6a3f324d7b0449056fef2057 Mon Sep 17 00:00:00 2001 From: Jarry Shaw Date: Fri, 10 May 2019 15:16:05 +0800 Subject: [PATCH] No changes --- .vscode/settings.json | 1 + src/core.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ca039431..3fb9b2dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "BDFL", "DEVEL", "EOFS", + "Envs", "HELPMSG", "METH", "NPROCESSORS", diff --git a/src/core.py b/src/core.py index a0525932..f2479041 100755 --- a/src/core.py +++ b/src/core.py @@ -29,16 +29,17 @@ __all__ = ['f2format', 'convert', 'ConvertError'] -# macros -PARSO_VERSION = ('3.6', '3.7', '3.8') -LOCALE_ENCODING = locale.getpreferredencoding() - # from configparser BOOLEAN_STATES = {'1': True, '0': False, 'yes': True, 'no': False, 'true': True, 'false': False, 'on': True, 'off': False} +# macros +PARSO_VERSION = ('3.6', '3.7', '3.8') +LOCALE_ENCODING = locale.getpreferredencoding() +F2FORMAT_QUIET = BOOLEAN_STATES.get(os.getenv('F2FORMAT_QUIET', '0').casefold(), False) + class ConvertError(SyntaxError): pass @@ -76,6 +77,9 @@ def convert(string, lineno=None): - string -- str, context to be converted - lineno -- dict, line number to actual offset mapping + Envs: + - F2FORMAT_VERSION -- encoding to open source files (same as `--encoding` option in CLI) + Returns: - str -- converted string @@ -226,8 +230,13 @@ def f2format(filename): Args: - filename -- str, file to be converted + Envs: + - F2FORMAT_QUIET -- run in quiet mode (same as `--quiet` option in CLI) + - F2FORMAT_VERSION -- encoding to open source files (same as `--encoding` option in CLI) + - F2FORMAT_ENCODING -- convert against Python version (same as `--python` option in CLI) + """ - if not BOOLEAN_STATES.get(os.getenv('F2FORMAT_QUIET', '0').casefold(), False): + if not F2FORMAT_QUIET: print('Now converting %r...' % filename) # pragma: no cover # fetch encoding