Skip to content

Commit

Permalink
chore: bump version to v1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Feb 16, 2021
1 parent 20abc00 commit 4fbc28c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v1.3.5](https://github.com/jnoortheen/arger/releases/tag/v1.3.5) - 2021-02-16

<small>[Compare with v1.3.4](https://github.com/jnoortheen/arger/compare/v1.3.4...v1.3.5)</small>

### Bug Fixes
- Py36 compatibility for get_origin(annotated) ([20abc00](https://github.com/jnoortheen/arger/commit/20abc00734ead149d1dd9ef5228928c46bea15eb) by Noortheen Raja).


## [v1.3.4](https://github.com/jnoortheen/arger/releases/tag/v1.3.4) - 2021-02-16

<small>[Compare with v1.3.0](https://github.com/jnoortheen/arger/compare/v1.3.0...v1.3.4)</small>
<small>[Compare with v1.3.1](https://github.com/jnoortheen/arger/compare/v1.3.1...v1.3.4)</small>


## [v1.3.1](https://github.com/jnoortheen/arger/releases/tag/v1.3.1) - 2021-02-16

<small>[Compare with v1.3.0](https://github.com/jnoortheen/arger/compare/v1.3.0...v1.3.1)</small>

### Features
- Use annotated for arguments ([ddbdf38](https://github.com/jnoortheen/arger/commit/ddbdf381f772d505fe15ad577d8d57aa3a585ab9) by Noortheen Raja).
Expand Down
40 changes: 20 additions & 20 deletions arger/docstring.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable = protected-access
# pylint: disable = protected-access,inherit-non-class
import inspect
import re
import typing as tp
Expand All @@ -10,7 +10,7 @@ class ParamDocTp(tp.NamedTuple):
doc: str

@classmethod
def init(cls, type_hint: tp.Any, doc: str, flag_symbol='-'):
def init(cls, type_hint: tp.Any, doc: str, flag_symbol="-"):
"""Parse flags defined in param's doc
Examples:
Expand Down Expand Up @@ -41,20 +41,20 @@ class DocstringParser:
section_ptrn: tp.Pattern
param_ptrn: tp.Pattern

_parsers: tp.List['DocstringParser'] = []
_parsers: tp.List["DocstringParser"] = []

def __init_subclass__(cls, **_):
# Cache costly init phase per session.
cls._parsers.append(cls())

@classmethod
def parse(cls, func: tp.Optional[tp.Callable]) -> DocstringTp:
doc = (inspect.getdoc(func) or '') if func else ''
doc = (inspect.getdoc(func) or "") if func else ""
if doc:
for parser in cls._parsers:
if parser.matches(doc):
return parser._parse(doc)
return DocstringTp(description=doc, epilog='', params={})
return DocstringTp(description=doc, epilog="", params={})

def _parse(self, doc: str) -> DocstringTp:
raise NotImplementedError
Expand All @@ -69,30 +69,30 @@ class NumpyDocParser(DocstringParser):
"""

def __init__(self):
self.pattern = re.compile(r'(Parameters\n[-]+)')
self.section_ptrn = re.compile(r'\n\s*(?P<section>\w+)\n\s*[-]+\n+')
self.param_ptrn = re.compile(r'^(?P<param>\w+)[ \t]*:?[ \t]*(?P<type>\w+)?')
self.pattern = re.compile(r"(Parameters\n[-]+)")
self.section_ptrn = re.compile(r"\n\s*(?P<section>\w+)\n\s*[-]+\n+")
self.param_ptrn = re.compile(r"^(?P<param>\w+)[ \t]*:?[ \t]*(?P<type>\w+)?")

def get_rest_of_section(self, params: str) -> tp.Tuple[str, str]:
other_sect = self.section_ptrn.search(params)
if other_sect:
pos = other_sect.start()
return params[pos:].strip(), params[:pos]
return '', params
return "", params

def parse_params(self, params: str) -> tp.Dict[str, ParamDocTp]:
docs = []
for line in params.splitlines():
match = self.param_ptrn.search(line)
if match:
result = match.groupdict()
doc = result.get('doc', '')
docs.append([result['param'], result['type'], doc])
doc = result.get("doc", "")
docs.append([result["param"], result["type"], doc])
elif docs:
docs[-1][-1] += line

return {
param.strip('*'): ParamDocTp.init(tphint, doc)
param.strip("*"): ParamDocTp.init(tphint, doc)
for param, tphint, doc in docs
}

Expand All @@ -108,10 +108,10 @@ class GoogleDocParser(NumpyDocParser):
"""

def __init__(self): # pylint: disable=super-init-not-called
self.pattern = re.compile(r'\s(Args|Arguments):\s')
self.section_ptrn = re.compile(r'\n(?P<section>[A-Z]\w+):\n+')
self.pattern = re.compile(r"\s(Args|Arguments):\s")
self.section_ptrn = re.compile(r"\n(?P<section>[A-Z]\w+):\n+")
self.param_ptrn = re.compile(
r'^\s+(?P<param>[*\w]+)\s*(\((?P<type>[\s,`:\w]+)\))?:\s*(?P<doc>[\s\S]+)'
r"^\s+(?P<param>[*\w]+)\s*(\((?P<type>[\s,`:\w]+)\))?:\s*(?P<doc>[\s\S]+)"
) # matches parameter_name e.g. param1 (type): description


Expand All @@ -121,15 +121,15 @@ class RstDocParser(DocstringParser):
"""

def __init__(self):
self.pattern = re.compile(r':param')
self.section_ptrn = re.compile(r'\n:[\w]+') # matches any start of the section
self.param_ptrn = re.compile(r'^[ ]+(?P<tp_param>.+):[ ]*(?P<doc>[\s\S]+)')
self.pattern = re.compile(r":param")
self.section_ptrn = re.compile(r"\n:[\w]+") # matches any start of the section
self.param_ptrn = re.compile(r"^[ ]+(?P<tp_param>.+):[ ]*(?P<doc>[\s\S]+)")

def parse_doc(self, line: str, params: tp.Dict[str, ParamDocTp]):
match = self.param_ptrn.match(line)
if match:
tp_param, doc = match.groups() # type: str, str
parts = tp_param.strip().rsplit(' ', maxsplit=1)
parts = tp_param.strip().rsplit(" ", maxsplit=1)
param = parts[-1].strip()
type_hint = None
if len(parts) > 1:
Expand All @@ -139,7 +139,7 @@ def parse_doc(self, line: str, params: tp.Dict[str, ParamDocTp]):
def _parse(self, doc: str) -> DocstringTp:
lines = self.pattern.split(doc)
long_desc = lines.pop(0)
epilog = ''
epilog = ""
params: tp.Dict[str, ParamDocTp] = {}
for idx, lin in enumerate(lines):
sections = self.section_ptrn.split(lin, maxsplit=1)
Expand Down
2 changes: 1 addition & 1 deletion arger/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable = protected-access,unused-argument,redefined-builtin
# pylint: disable = protected-access,unused-argument,redefined-builtin,unsubscriptable-object
import argparse as ap
import copy
import functools
Expand Down
2 changes: 0 additions & 2 deletions arger/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from inspect import isclass
from typing import Any, FrozenSet, List, Set, Tuple, TypeVar, Union

import typing_extensions as tpe

NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "arger"
version = "1.3.4"
version = "1.3.5"
description = "Create argparser automatically from functions"

license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def prun(*cmd, **kwargs):
sys.stderr.flush()
if c.returncode:
raise arger.exit(
message=f"Failed[{c.returncode}] - {cmd}:\n {c.stderr.decode()}",
message=f"Failed[{c.returncode}] - {cmd}",
status=c.returncode,
)
return c
Expand Down

0 comments on commit 4fbc28c

Please sign in to comment.