Skip to content

Commit

Permalink
New distribution [0.3.3]
Browse files Browse the repository at this point in the history
 * changed default decorator name to `__poseur_decorator`
 * revised documentation & manual
 * bugfix for `linesep` handling
 * revised tests
  • Loading branch information
JarryShaw committed Oct 29, 2019
1 parent 731701c commit 202c40c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Envs:
- `POSEUR_LINESEP` -- line separator to process source files (same as `--linesep` option in CLI)
- `POSEUR_DISMISS` -- dismiss runtime checks for positional-only arguments (same as `--dismiss` option in CLI)
- `POSEUR_LINTING` -- lint converted codes (same as `--linting` option in CLI)
- `POSEUR_DECORATOR` -- name of decorator for runtime checks (same as `--decorator` option in CLI)

Returns:

Expand Down
16 changes: 8 additions & 8 deletions poseur.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
del multiprocessing

# version string
__version__ = '0.3.2'
__version__ = '0.3.3'

# from configparser
BOOLEAN_STATES = {'1': True, '0': False,
Expand Down Expand Up @@ -72,7 +72,6 @@ def predicate(filename): # pragma: no cover
###############################################################################
# Positional-only decorator


_decorator = '''
def %s(*poseur):
"""Positional-only arguments runtime checker.
Expand All @@ -95,10 +94,9 @@ def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
return caller
'''

exec(_decorator % 'decorator')
'''.splitlines()

exec(os.linesep.join(_decorator) % 'decorator')

###############################################################################
# Main convertion implementation
Expand Down Expand Up @@ -510,6 +508,7 @@ def process_module(node):
- `node` -- `parso.python.tree.Module`, parso AST
Envs:
- `POSEUR_LINESEP` -- line separator to process source files (same as `--linesep` option in CLI)
- `POSEUR_LINTING` -- lint converted codes (same as `--linting` option in CLI)
- `POSEUR_DECORATOR` -- name of decorator for runtime checks (same as `--decorator` option in CLI)
Expand All @@ -528,16 +527,17 @@ def process_module(node):
suffix += walk(child)

if postmt >= 0:
POSEUR_LINESEP = os.getenv('POSEUR_LINESEP', os.linesep)
POSEUR_DECORATOR = os.getenv('POSEUR_DECORATOR', __poseur_decorator__)
middle = _decorator % POSEUR_DECORATOR

middle = POSEUR_LINESEP.join(_decorator) % POSEUR_DECORATOR
if not prefix:
middle = middle.lstrip()
if not suffix:
middle = middle.rstrip()

POSEUR_LINTING = BOOLEAN_STATES.get(os.getenv('POSEUR_LINTING', '0').casefold(), False)
if POSEUR_LINTING:
POSEUR_LINESEP = os.getenv('POSEUR_LINESEP', os.linesep)
if prefix:
if prefix.endswith(POSEUR_LINESEP * 2):
pass
Expand Down Expand Up @@ -691,7 +691,7 @@ def poseur(filename):
__poseur_version__ = os.getenv('POSEUR_VERSION', POSEUR_VERSION[-1])
__poseur_encoding__ = os.getenv('POSEUR_ENCODING', LOCALE_ENCODING)
__poseur_linesep__ = os.getenv('POSEUR_LINESEP', os.linesep)
__poseur_decorator__ = os.getenv('POSEUR_DECORATOR', '_poseur_decorator')
__poseur_decorator__ = os.getenv('POSEUR_DECORATOR', '__poseur_decorator')


def get_parser():
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.pypi.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.3.2'
__version__ = '0.3.3'

# set-up script for pip distribution
setup(
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.pypitest.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.3.2'
__version__ = '0.3.3'

# set-up script for pip distribution
setup(
Expand Down
2 changes: 1 addition & 1 deletion share/poseur.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH POSEUR 1 "October 24, 2019" "v0.3.2" ""
.TH POSEUR 1 "October 29, 2019" "v0.3.3" ""
.SH NAME
poseur \- back-port compiler for Python 3.8 positional-only parameter syntax
.
Expand Down
4 changes: 2 additions & 2 deletions share/poseur.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ poseur
back-port compiler for Python 3.8 positional-only parameter syntax
------------------------------------------------------------------

:Version: v0.3.2
:Date: October 24, 2019
:Version: v0.3.3
:Date: October 29, 2019
:Manual section: 1
:Author:
Jarry Shaw, a newbie programmer, is the author, owner and maintainer
Expand Down
26 changes: 18 additions & 8 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
TEXT = file.read()

# environs
os.environ['POSEUR_DECORATOR'] = '_poseur_decorator'
os.environ['POSEUR_QUIET'] = 'true'
os.environ['POSEUR_ENCODING'] = 'utf-8'
os.environ['POSEUR_LINESEP'] = '\n'
POSEUR_LINESEP = os.environ['POSEUR_LINESEP']


@contextlib.contextmanager
Expand Down Expand Up @@ -135,7 +137,8 @@ def func(a, b, *, c): # pylint: disable=unused-argument
def test_async(self):
src = 'async def func(param, /): pass'
dst = 'async def func(param): pass'
dst = "%s@_poseur_decorator(\'param\')\nasync def func(param): pass" % (_decorator % '_poseur_decorator').lstrip()
dst = "%s@_poseur_decorator(\'param\')\nasync def func(param): pass" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

def test_lambdef(self):
Expand All @@ -146,7 +149,8 @@ def test_lambdef(self):

# basic poseur
src = 'lambda param, /: param'
dst = "%s_poseur_decorator('param')(lambda param: param)" % (_decorator % '_poseur_decorator').lstrip()
dst = "%s_poseur_decorator('param')(lambda param: param)" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

# no poseur in default value
Expand All @@ -156,17 +160,20 @@ def test_lambdef(self):

# poseur in default value
src = 'lambda param=lambda p, /: p: param'
dst = "%slambda param=_poseur_decorator('p')(lambda p: p): param" % (_decorator % '_poseur_decorator').lstrip()
dst = "%slambda param=_poseur_decorator('p')(lambda p: p): param" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

# poseur in lambda suite
src = 'lambda param: lambda p, /: p'
dst = "%slambda param: _poseur_decorator('p')(lambda p: p)" % (_decorator % '_poseur_decorator').lstrip()
dst = "%slambda param: _poseur_decorator('p')(lambda p: p)" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

# hybrid poseur
src = 'lambda param: param\nlambda param, /: param'
dst = "lambda param: param\n%s_poseur_decorator('param')(lambda param: param)" % (_decorator % '_poseur_decorator')
dst = "lambda param: param\n%s_poseur_decorator('param')(lambda param: param)" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator')
self._check_convert(src, dst)

def test_funcdef(self):
Expand All @@ -177,12 +184,14 @@ def test_funcdef(self):

# simple poseur
src = 'def func(a, /, b): pass'
dst = "%s@_poseur_decorator(\'a\')\ndef func(a, b): pass" % (_decorator % '_poseur_decorator').lstrip()
dst = "%s@_poseur_decorator(\'a\')\ndef func(a, b): pass" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

# poseur in function suite
src = 'def func(): lambda param, /: param'
dst = "%sdef func(): _poseur_decorator('param')(lambda param: param)" % (_decorator % '_poseur_decorator').lstrip()
dst = "%sdef func(): _poseur_decorator('param')(lambda param: param)" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)

# keyword arguments
Expand All @@ -192,7 +201,8 @@ def test_funcdef(self):

# poseur in default value
src = 'def func(a=lambda param, /: param): pass'
dst = "%sdef func(a=_poseur_decorator('param')(lambda param: param)): pass" % (_decorator % '_poseur_decorator').lstrip()
dst = "%sdef func(a=_poseur_decorator('param')(lambda param: param)): pass" % (
POSEUR_LINESEP.join(_decorator) % '_poseur_decorator').lstrip()
self._check_convert(src, dst)


Expand Down

0 comments on commit 202c40c

Please sign in to comment.