Package: walrus-converter
walrusWriteassignment expressionsin Python 3.8 flavour, and letwalrusworry about back-port issues :beer:SincePEP 572, Python introducedassignment expressionssyntax in version3.8. For those who wish to useassignment expressionsin their code,walrusprovides an
intelligent, yet imperfect, solution of abackport compilerby replacingassignment expressionssyntax with
old-fashioned assignment-then-conditional syntax, which guarantees you to always writeassignment expressionsin
Python 3.8 flavour then compile for compatibility later.NB:walruscurrently can only supportassignment expressionsused inifstatements.InstallationNote thatwalrusonly supports Python versionssince 3.3🐍For macOS users,walrusis now available throughHomebrew:brewtapjarryshaw/tap
brewinstallwalrus# or simply, a one-linerbrewinstalljarryshaw/tap/walrusSimply run the following to install the current version from PyPI:pipinstallpython-walrusOr install the latest version from the git repository:gitclonehttps://github.com/JarryShaw/walrus.gitcdwalrus
pipinstall-e.# and to update at any timegitpullBasic UsageCLIIt is fairly straightforward to usewalrus:context in${...}changes dynamically according to runtime environmentusage: walrus [options] <python source files and folders...>

Back-port compiler for Python 3.8 assignment expressions.

positional arguments:
  SOURCE                python source files and folders to be converted (${CWD})

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -q, --quiet           run in quiet mode

archive options:
  duplicate original files in case there's any issue

  -n, --no-archive      do not archive original files
  -p PATH, --archive-path PATH
                        path to archive original files (${CWD}/archive)

convert options:
  compatibility configuration for none-unicode files

  -c CODING, --encoding CODING
                        encoding to open source files (${LOCALE_ENCODING})
  -v VERSION, --python VERSION
                        convert against Python version (${LATEST_VERSION})
  -s SEP, --linesep SEP
                        line separator to process source files (${OS_LINESEP})
  -nl, --no-linting     do not lint converted codeswalruswill read then convert allassignment expressionssyntax in every Python
file under this path. In case there might be some problems with the conversion,walruswill
duplicate all original files it is to modify intoarchivedirectory ahead of the process,
if-nnot set.Besides, to keep consistency of API to users,walrusships with adecoratorfor
such functions to check assignment expressions at runtime, if-nlnot set.Developer ReferenceEnvironmentswalruscurrently supports three environment arguments:WALRUS_QUIET-- run in quiet mode (same as--quietoption in CLI)WALRUS_VERSION-- convert against Python version (same as--pythonoption in CLI)WALRUS_ENCODING-- encoding to open source files (same as--encodingoption in CLI)WALRUS_LINESEP-- line separator to process source files (same as--linesepoption in CLI)WALRUS_LINTING-- lint converted codes (same as--lintingoption in CLI)APIswalrus-- wrapper works for conversionwalrus(filename)Args:filename--str, file to be convertedEnvs:WALRUS_QUIET-- run in quiet mode (same as--quietoption in CLI)WALRUS_ENCODING-- encoding to open source files (same as--encodingoption in CLI)WALRUS_VERSION-- convert against Python version (same as--pythonoption in CLI)WALRUS_LINESEP-- line separator to process source files (same as--linesepoption in CLI)WALRUS_LINTING-- lint converted codes (same as--lintingoption in CLI)Raises:ConvertError-- whenparso.ParserSyntaxErrorraisedconvert-- the main conversion processconvert(string,source='<unknown>')Args:string--str, context to be convertedsource--str, source of the contextEnvs:WALRUS_VERSION-- convert against Python version (same as--pythonoption in CLI)WALRUS_LINESEP-- line separator to process source files (same as--linesepoption in CLI)WALRUS_LINTING-- lint converted codes (same as--lintingoption in CLI)Returns:str-- converted stringRaises:ConvertError-- whenparso.ParserSyntaxErrorraisedConvertError--walrusinternal exceptionclassConvertError(SyntaxError):passTestSeetest.py.ContributionContributions are very welcome, especially fixing bugs and providing test cases.
Note that code must remain valid and reasonable.See Alsobabelf2formatposeurvermin