Skip to content

Commit

Permalink
Initial release [0.1.0]
Browse files Browse the repository at this point in the history
 * implemented conversion algorithm to convert `:=` (walrus) operations / **assignment expressions** to pre-3.8 compatible codes
 * implemented auto detection of line seperator and tab size based on source code context
  • Loading branch information
JarryShaw committed Nov 25, 2019
1 parent 64d7f59 commit e6270ab
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 74 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export PIPENV_VERBOSITY=-1

# get version string
version = $(shell cat poseur.py | grep "^__version__" | sed "s/__version__ = '\(.*\)'/\1/")
version = $(shell cat walrus.py | grep "^__version__" | sed "s/__version__ = '\(.*\)'/\1/")

after: git-after
clean: pypi-clean
Expand All @@ -25,8 +27,8 @@ formula: setup-formula
set -ae
cd Tap
git pull
git add Formula/poseur.rb
git commit -S -m "poseur: $(version)"
git add Formula/walrus.rb
git commit -S -m "walrus: $(version)"
git push

test:
Expand Down Expand Up @@ -91,7 +93,7 @@ setup-formula: setup-version pipenv-update
pipenv run python scripts/setup-formula.py

setup-manual: setup-version
pipenv run rst2man.py share/poseur.rst > share/poseur.1
pipenv run rst2man.py share/walrus.rst > share/walrus.1

git-upload:
git pull
Expand All @@ -108,7 +110,7 @@ git-after:
git-release:
go run github.com/aktau/github-release release \
--user JarryShaw \
--repo poseur \
--repo walrus \
--tag "v$(version)" \
--name "poseur v$(version)" \
--name "walrus v$(version)" \
--description "$$(git log -1 --pretty=%B)"
18 changes: 9 additions & 9 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ intelligent, yet imperfect, solution of a **backport compiler** by replacing *as
old-fashioned assignment-then-conditional syntax, which guarantees you to always write *assignment expressions* in
Python 3.8 flavour then compile for compatibility later.

**NB**: `walrus` currently can only support *assignment expressions* used in `if` statements.

## Installation

> Note that `walrus` only supports Python versions __since 3.3__ 🐍
Expand Down Expand Up @@ -73,7 +71,7 @@ optional arguments:
archive options:
duplicate original files in case there's any issue
-n, --no-archive do not archive original files
-na, --no-archive do not archive original files
-p PATH, --archive-path PATH
path to archive original files (${CWD}/archive)
Expand All @@ -87,6 +85,8 @@ convert options:
-s SEP, --linesep SEP
line separator to process source files (${OS_LINESEP})
-nl, --no-linting do not lint converted codes
-t INDENT, --tabsize INDENT
indentation tab size (4)
```

  `walrus` will read then convert all *assignment expressions* syntax in every Python
Expand All @@ -108,6 +108,7 @@ such functions to check assignment expressions at runtime, if `-nl` not set.
- `WALRUS_ENCODING` -- encoding to open source files (same as `--encoding` option in CLI)
- `WALRUS_LINESEP` -- line separator to process source files (same as `--linesep` option in CLI)
- `WALRUS_LINTING` -- lint converted codes (same as `--linting` option in CLI)
- `WALRUS_TABSIZE` -- indentation tab size (same as `--tabsize` option in CLI)

### APIs

Expand All @@ -128,6 +129,7 @@ Envs:
- `WALRUS_VERSION`-- convert against Python version (same as `--python` option in CLI)
- `WALRUS_LINESEP` -- line separator to process source files (same as `--linesep` option in CLI)
- `WALRUS_LINTING` -- lint converted codes (same as `--linting` option in CLI)
- `WALRUS_TABSIZE` -- indentation tab size (same as `--tabsize` option in CLI)

Raises:

Expand All @@ -149,6 +151,7 @@ Envs:
- `WALRUS_VERSION`-- convert against Python version (same as `--python` option in CLI)
- `WALRUS_LINESEP` -- line separator to process source files (same as `--linesep` option in CLI)
- `WALRUS_LINTING` -- lint converted codes (same as `--linting` option in CLI)
- `WALRUS_TABSIZE` -- indentation tab size (same as `--tabsize` option in CLI)

Returns:

Expand All @@ -167,7 +170,7 @@ class ConvertError(SyntaxError):

## Test

  See [`test.py`](https://github.com/JarryShaw/walrus/blob/master/scripts/test.py).
  See [`tests`](https://github.com/JarryShaw/walrus/blob/master/tests) folder.

## Contribution

Expand Down
1 change: 1 addition & 0 deletions scripts/setup-formula.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
long_desc = file.read()

# version string
__version__ = '0.0.0.dev0'
__version__ = '0.1.0'

# set-up script for pip distribution
setup(
Expand Down
133 changes: 133 additions & 0 deletions share/walrus.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
.\" Man page generated from reStructuredText.
.
.TH WALRUS 1 "November 25, 2019" "v0.1.0" ""
.SH NAME
walrus \- back-port compiler for Python 3.8 assignment expression
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH SYNOPSIS
.sp
walrus [\fIoptions\fP] <\fIpython source files and folders\fP> ...
.SH DESCRIPTION
.sp
Since PEP 572, Python introduced \fIassignment expressions\fP syntax in
version __3.8__. For those who wish to use \fIassignment expressions\fP
in their code, \fIwalrus\fP provides an intelligent, yet imperfect,
solution of a \fBbackport compiler\fP by replacing \fIassignment expressions\fP
syntax with old\-fashioned assignment\-then\-conditional syntax, which
guarantees you to always write \fIassignment expressions\fP in Python 3.8
flavour then compile for compatibility later.
.SH OPTIONS
.SS positional arguments
.INDENT 0.0
.TP
.B SOURCE
python source files and folders to be converted
.UNINDENT
.SS optional arguments
.INDENT 0.0
.TP
.B \-h\fP,\fB \-\-help
show this help message and exit
.TP
.B \-V\fP,\fB \-\-version
show program\(aqs version number and exit
.TP
.B \-q\fP,\fB \-\-quiet
run in quiet mode
.UNINDENT
.SS archive options
.sp
duplicate original files in case there\(aqs any issue
.INDENT 0.0
.TP
.BI \-n\fB a\fP,\fB \ \-\-no\-archive
do not archive original files
.UNINDENT
.INDENT 0.0
.TP
.B \-p \fIPATH\fP, \-\-archive\-path \fIPATH\fP
path to archive original files
.UNINDENT
.SS convert options
.sp
compatibility configuration for none\-unicode files
.INDENT 0.0
.TP
.B \-c \fICODING\fP, \-\-encoding \fICODING\fP
encoding to open source files
.TP
.B \-v \fIVERSION\fP, \-\-python \fIVERSION\fP
convert against Python version
.TP
.B \-s \fISEP\fP, \-\-linesep \fISEP\fP
line separator to process source files
.UNINDENT
.INDENT 0.0
.TP
.BI \-n\fB l\fP,\fB \ \-\-no\-linting
do not lint converted codes
.UNINDENT
.INDENT 0.0
.TP
.B \-t \fIINDENT\fP, \-\-tabsize \fIINDENT\fP
indentation tab size
.UNINDENT
.SH ENVIRONMENT
.sp
\fBwalrus\fP currently supports two environment variables.
.INDENT 0.0
.TP
.B WALRUS_QUIET
run in quiet mode
.TP
.B WALRUS_ENCODING
encoding to open source files
.TP
.B WALRUS_VERSION
convert against Python version
.TP
.B WALRUS_LINESEP
line separator to process source files
.TP
.B WALRUS_LINTING
lint converted codes
.TP
.B WALRUS_TABSIZE
indentation tab size
.UNINDENT
.SH SEE ALSO
.sp
babel(1), f2format(1), poseur(1), vermin(1)
.SH AUTHOR
Jarry Shaw, a newbie programmer, is the author, owner and maintainer
of walrus. Please contact me at [email protected].
.SH COPYRIGHT
walrus is licensed under the MIT License.
.\" Generated by docutils manpage writer.
.
16 changes: 13 additions & 3 deletions share/walrus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ walrus
back-port compiler for Python 3.8 assignment expression
-------------------------------------------------------

:Version: v0.3.1
:Date: October 24, 2019
:Version: v0.1.0
:Date: November 25, 2019
:Manual section: 1
:Author:
Jarry Shaw, a newbie programmer, is the author, owner and maintainer
Expand All @@ -23,7 +23,13 @@ walrus [*options*] <*python source files and folders*> ...
DESCRIPTION
===========


Since PEP 572, Python introduced *assignment expressions* syntax in
version __3.8__. For those who wish to use *assignment expressions*
in their code, `walrus` provides an intelligent, yet imperfect,
solution of a **backport compiler** by replacing *assignment expressions*
syntax with old-fashioned assignment-then-conditional syntax, which
guarantees you to always write *assignment expressions* in Python 3.8
flavour then compile for compatibility later.

OPTIONS
=======
Expand Down Expand Up @@ -66,6 +72,9 @@ compatibility configuration for none-unicode files

-nl, --no-linting do not lint converted codes

-t *INDENT*, --tabsize *INDENT*
indentation tab size

ENVIRONMENT
===========

Expand All @@ -76,6 +85,7 @@ ENVIRONMENT
:WALRUS_VERSION: convert against Python version
:WALRUS_LINESEP: line separator to process source files
:WALRUS_LINTING: lint converted codes
:WALRUS_TABSIZE: indentation tab size

SEE ALSO
========
Expand Down
Loading

0 comments on commit e6270ab

Please sign in to comment.