Skip to content

Commit e6270ab

Browse files
committed
Initial release [0.1.0]
* 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
1 parent 64d7f59 commit e6270ab

File tree

8 files changed

+271
-74
lines changed

8 files changed

+271
-74
lines changed

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
export PIPENV_VERBOSITY=-1
2+
13
# get version string
2-
version = $(shell cat poseur.py | grep "^__version__" | sed "s/__version__ = '\(.*\)'/\1/")
4+
version = $(shell cat walrus.py | grep "^__version__" | sed "s/__version__ = '\(.*\)'/\1/")
35

46
after: git-after
57
clean: pypi-clean
@@ -25,8 +27,8 @@ formula: setup-formula
2527
set -ae
2628
cd Tap
2729
git pull
28-
git add Formula/poseur.rb
29-
git commit -S -m "poseur: $(version)"
30+
git add Formula/walrus.rb
31+
git commit -S -m "walrus: $(version)"
3032
git push
3133

3234
test:
@@ -91,7 +93,7 @@ setup-formula: setup-version pipenv-update
9193
pipenv run python scripts/setup-formula.py
9294

9395
setup-manual: setup-version
94-
pipenv run rst2man.py share/poseur.rst > share/poseur.1
96+
pipenv run rst2man.py share/walrus.rst > share/walrus.1
9597

9698
git-upload:
9799
git pull
@@ -108,7 +110,7 @@ git-after:
108110
git-release:
109111
go run github.com/aktau/github-release release \
110112
--user JarryShaw \
111-
--repo poseur \
113+
--repo walrus \
112114
--tag "v$(version)" \
113-
--name "poseur v$(version)" \
115+
--name "walrus v$(version)" \
114116
--description "$$(git log -1 --pretty=%B)"

Pipfile.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ intelligent, yet imperfect, solution of a **backport compiler** by replacing *as
1818
old-fashioned assignment-then-conditional syntax, which guarantees you to always write *assignment expressions* in
1919
Python 3.8 flavour then compile for compatibility later.
2020

21-
**NB**: `walrus` currently can only support *assignment expressions* used in `if` statements.
22-
2321
## Installation
2422

2523
> Note that `walrus` only supports Python versions __since 3.3__ 🐍
@@ -73,7 +71,7 @@ optional arguments:
7371
archive options:
7472
duplicate original files in case there's any issue
7573
76-
-n, --no-archive do not archive original files
74+
-na, --no-archive do not archive original files
7775
-p PATH, --archive-path PATH
7876
path to archive original files (${CWD}/archive)
7977
@@ -87,6 +85,8 @@ convert options:
8785
-s SEP, --linesep SEP
8886
line separator to process source files (${OS_LINESEP})
8987
-nl, --no-linting do not lint converted codes
88+
-t INDENT, --tabsize INDENT
89+
indentation tab size (4)
9090
```
9191

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

112113
### APIs
113114

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

132134
Raises:
133135

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

153156
Returns:
154157

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

168171
## Test
169172

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

172175
## Contribution
173176

scripts/setup-formula.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/local/Homebrew/Library/Taps/jarryshaw/homebrew-tap/Generator/scripts/walrus.py

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
long_desc = file.read()
1616

1717
# version string
18-
__version__ = '0.0.0.dev0'
18+
__version__ = '0.1.0'
1919

2020
# set-up script for pip distribution
2121
setup(

share/walrus.1

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
.\" Man page generated from reStructuredText.
2+
.
3+
.TH WALRUS 1 "November 25, 2019" "v0.1.0" ""
4+
.SH NAME
5+
walrus \- back-port compiler for Python 3.8 assignment expression
6+
.
7+
.nr rst2man-indent-level 0
8+
.
9+
.de1 rstReportMargin
10+
\\$1 \\n[an-margin]
11+
level \\n[rst2man-indent-level]
12+
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
13+
-
14+
\\n[rst2man-indent0]
15+
\\n[rst2man-indent1]
16+
\\n[rst2man-indent2]
17+
..
18+
.de1 INDENT
19+
.\" .rstReportMargin pre:
20+
. RS \\$1
21+
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
22+
. nr rst2man-indent-level +1
23+
.\" .rstReportMargin post:
24+
..
25+
.de UNINDENT
26+
. RE
27+
.\" indent \\n[an-margin]
28+
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
29+
.nr rst2man-indent-level -1
30+
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
31+
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
32+
..
33+
.SH SYNOPSIS
34+
.sp
35+
walrus [\fIoptions\fP] <\fIpython source files and folders\fP> ...
36+
.SH DESCRIPTION
37+
.sp
38+
Since PEP 572, Python introduced \fIassignment expressions\fP syntax in
39+
version __3.8__. For those who wish to use \fIassignment expressions\fP
40+
in their code, \fIwalrus\fP provides an intelligent, yet imperfect,
41+
solution of a \fBbackport compiler\fP by replacing \fIassignment expressions\fP
42+
syntax with old\-fashioned assignment\-then\-conditional syntax, which
43+
guarantees you to always write \fIassignment expressions\fP in Python 3.8
44+
flavour then compile for compatibility later.
45+
.SH OPTIONS
46+
.SS positional arguments
47+
.INDENT 0.0
48+
.TP
49+
.B SOURCE
50+
python source files and folders to be converted
51+
.UNINDENT
52+
.SS optional arguments
53+
.INDENT 0.0
54+
.TP
55+
.B \-h\fP,\fB \-\-help
56+
show this help message and exit
57+
.TP
58+
.B \-V\fP,\fB \-\-version
59+
show program\(aqs version number and exit
60+
.TP
61+
.B \-q\fP,\fB \-\-quiet
62+
run in quiet mode
63+
.UNINDENT
64+
.SS archive options
65+
.sp
66+
duplicate original files in case there\(aqs any issue
67+
.INDENT 0.0
68+
.TP
69+
.BI \-n\fB a\fP,\fB \ \-\-no\-archive
70+
do not archive original files
71+
.UNINDENT
72+
.INDENT 0.0
73+
.TP
74+
.B \-p \fIPATH\fP, \-\-archive\-path \fIPATH\fP
75+
path to archive original files
76+
.UNINDENT
77+
.SS convert options
78+
.sp
79+
compatibility configuration for none\-unicode files
80+
.INDENT 0.0
81+
.TP
82+
.B \-c \fICODING\fP, \-\-encoding \fICODING\fP
83+
encoding to open source files
84+
.TP
85+
.B \-v \fIVERSION\fP, \-\-python \fIVERSION\fP
86+
convert against Python version
87+
.TP
88+
.B \-s \fISEP\fP, \-\-linesep \fISEP\fP
89+
line separator to process source files
90+
.UNINDENT
91+
.INDENT 0.0
92+
.TP
93+
.BI \-n\fB l\fP,\fB \ \-\-no\-linting
94+
do not lint converted codes
95+
.UNINDENT
96+
.INDENT 0.0
97+
.TP
98+
.B \-t \fIINDENT\fP, \-\-tabsize \fIINDENT\fP
99+
indentation tab size
100+
.UNINDENT
101+
.SH ENVIRONMENT
102+
.sp
103+
\fBwalrus\fP currently supports two environment variables.
104+
.INDENT 0.0
105+
.TP
106+
.B WALRUS_QUIET
107+
run in quiet mode
108+
.TP
109+
.B WALRUS_ENCODING
110+
encoding to open source files
111+
.TP
112+
.B WALRUS_VERSION
113+
convert against Python version
114+
.TP
115+
.B WALRUS_LINESEP
116+
line separator to process source files
117+
.TP
118+
.B WALRUS_LINTING
119+
lint converted codes
120+
.TP
121+
.B WALRUS_TABSIZE
122+
indentation tab size
123+
.UNINDENT
124+
.SH SEE ALSO
125+
.sp
126+
babel(1), f2format(1), poseur(1), vermin(1)
127+
.SH AUTHOR
128+
Jarry Shaw, a newbie programmer, is the author, owner and maintainer
129+
of walrus. Please contact me at [email protected].
130+
.SH COPYRIGHT
131+
walrus is licensed under the MIT License.
132+
.\" Generated by docutils manpage writer.
133+
.

share/walrus.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ walrus
66
back-port compiler for Python 3.8 assignment expression
77
-------------------------------------------------------
88

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

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

2834
OPTIONS
2935
=======
@@ -66,6 +72,9 @@ compatibility configuration for none-unicode files
6672

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

75+
-t *INDENT*, --tabsize *INDENT*
76+
indentation tab size
77+
6978
ENVIRONMENT
7079
===========
7180

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

8090
SEE ALSO
8191
========

0 commit comments

Comments
 (0)