From 4fbc28ccd6d7fcd4b2f6c57fba9a11b075a70bf0 Mon Sep 17 00:00:00 2001 From: Noortheen Raja Date: Tue, 16 Feb 2021 19:33:44 +0530 Subject: [PATCH] chore: bump version to v1.3.5 --- CHANGELOG.md | 15 ++++++++++++++- arger/docstring.py | 40 ++++++++++++++++++++-------------------- arger/main.py | 2 +- arger/typing_utils.py | 2 -- pyproject.toml | 2 +- tasks.py | 2 +- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fce304..6fb7f3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + +[Compare with v1.3.4](https://github.com/jnoortheen/arger/compare/v1.3.4...v1.3.5) + +### 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 -[Compare with v1.3.0](https://github.com/jnoortheen/arger/compare/v1.3.0...v1.3.4) +[Compare with v1.3.1](https://github.com/jnoortheen/arger/compare/v1.3.1...v1.3.4) + + +## [v1.3.1](https://github.com/jnoortheen/arger/releases/tag/v1.3.1) - 2021-02-16 + +[Compare with v1.3.0](https://github.com/jnoortheen/arger/compare/v1.3.0...v1.3.1) ### Features - Use annotated for arguments ([ddbdf38](https://github.com/jnoortheen/arger/commit/ddbdf381f772d505fe15ad577d8d57aa3a585ab9) by Noortheen Raja). diff --git a/arger/docstring.py b/arger/docstring.py index c14a380..4eecc34 100644 --- a/arger/docstring.py +++ b/arger/docstring.py @@ -1,4 +1,4 @@ -# pylint: disable = protected-access +# pylint: disable = protected-access,inherit-non-class import inspect import re import typing as tp @@ -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: @@ -41,7 +41,7 @@ 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. @@ -49,12 +49,12 @@ def __init_subclass__(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 @@ -69,16 +69,16 @@ class NumpyDocParser(DocstringParser): """ def __init__(self): - self.pattern = re.compile(r'(Parameters\n[-]+)') - self.section_ptrn = re.compile(r'\n\s*(?P
\w+)\n\s*[-]+\n+') - self.param_ptrn = re.compile(r'^(?P\w+)[ \t]*:?[ \t]*(?P\w+)?') + self.pattern = re.compile(r"(Parameters\n[-]+)") + self.section_ptrn = re.compile(r"\n\s*(?P
\w+)\n\s*[-]+\n+") + self.param_ptrn = re.compile(r"^(?P\w+)[ \t]*:?[ \t]*(?P\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 = [] @@ -86,13 +86,13 @@ def parse_params(self, params: str) -> tp.Dict[str, ParamDocTp]: 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 } @@ -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
[A-Z]\w+):\n+') + self.pattern = re.compile(r"\s(Args|Arguments):\s") + self.section_ptrn = re.compile(r"\n(?P
[A-Z]\w+):\n+") self.param_ptrn = re.compile( - r'^\s+(?P[*\w]+)\s*(\((?P[\s,`:\w]+)\))?:\s*(?P[\s\S]+)' + r"^\s+(?P[*\w]+)\s*(\((?P[\s,`:\w]+)\))?:\s*(?P[\s\S]+)" ) # matches parameter_name e.g. param1 (type): description @@ -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.+):[ ]*(?P[\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.+):[ ]*(?P[\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: @@ -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) diff --git a/arger/main.py b/arger/main.py index dc17af9..470d929 100644 --- a/arger/main.py +++ b/arger/main.py @@ -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 diff --git a/arger/typing_utils.py b/arger/typing_utils.py index 133e465..6d80051 100644 --- a/arger/typing_utils.py +++ b/arger/typing_utils.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1f7f21c..b1a9330 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "arger" -version = "1.3.4" +version = "1.3.5" description = "Create argparser automatically from functions" license = "MIT" diff --git a/tasks.py b/tasks.py index 8824950..7b30878 100644 --- a/tasks.py +++ b/tasks.py @@ -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