From a9bf28a7cf2c7190f961d57b59af8d725b66bf83 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:10:31 -0400 Subject: [PATCH 01/17] tidied comments --- src/rooibos/__init__.py | 77 +++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 477b241..b9b42d2 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -1,3 +1,14 @@ +# -*- coding: utf-8 -*- +__all__ = ( + 'Location', + 'LocationRange', + 'BoundTerm', + 'Environment', + 'Match', + 'Client', + 'ephemeral_server' +) + from typing import Dict, Tuple, Iterator, List, Any from contextlib import contextmanager from tempfile import TemporaryFile @@ -18,17 +29,8 @@ from .version import __version__ from .exceptions import * -logging.getLogger(__name__).addHandler(logging.NullHandler()) - -__all__ = [ - 'Location', - 'LocationRange', - 'BoundTerm', - 'Environment', - 'Match', - 'Client', - 'ephemeral_server' -] +logger = logging.getLogger(__name__) # type: logging.Logger +logger.setLevel(logging.DEBUG) class Location(object): @@ -66,17 +68,13 @@ def __repr__(self): @property def line(self): # type: () -> int - """ - The one-indexed line number for this location. - """ + """The one-indexed line number for this location.""" return self.__line @property def col(self): # type: () -> int - """ - The one-indexed column number for this location. - """ + """The one-indexed column number for this location.""" return self.__col @@ -122,24 +120,18 @@ def __repr__(self): @property def start(self): # type: () -> Location - """ - The position at which this range begins. - """ + """The position at which this range begins.""" return self.__start @property def stop(self): # type: () -> Location - """ - The position at which this range ends, inclusive. - """ + """The position at which this range ends, inclusive.""" return self.__stop class BoundTerm(object): - """ - Represents a binding of a named term to a fragment of source code. - """ + """Represents a binding of a named term to a fragment of source code.""" @staticmethod def from_dict(d): # type: (Dict[str, Any]) -> BoundTerm @@ -247,16 +239,13 @@ class Match(object): @staticmethod def from_dict(d): # type: (Dict[str, Any]) -> Match - """ - Constructs a match from a dictionary-based description. - """ + """Constructs a match from a dictionary-based description.""" return Match(environment=Environment.from_dict(d['environment']), location=LocationRange.from_string(d['location'])) def __init__(self, environment, location): # type: (Environment, LocationRange) -> None - """ - Constructs a new match. + """Constructs a new match. Parameters: environment: an environment that describes the mapping from terms @@ -274,8 +263,7 @@ def __repr__(self): def __getitem__(self, term): # type: (str) -> BoundTerm - """ - Retrieves a bound term from this match. + """Retrieves a bound term from this match. Parameters: term: the name of the term. @@ -300,24 +288,18 @@ def environment(self): @property def location(self): # type: () -> LocationRange - """ - The range of locations in the source text over which the template was - matched. - """ + """The range of locations in the text where the template matched.""" return self.__location class Client(object): - """ - Provides an interface for communicating with a Rooibos server. - """ + """Provides an interface for communicating with a Rooibos server.""" def __init__(self, base_url, # type: str timeout=30, # type: int timeout_connection=30 # type: int ): # type: (...) -> None - """ - Constructs a new client. + """Constructs a new client. Parameters: base_url: the base URL of the Rooibos server. @@ -364,17 +346,14 @@ def base_url(self): def _url(self, path): # type: (str) -> str - """ - Computes the URL for a resource located at a given path on the server. - """ + """Computes the URL for a resource on the server.""" return urljoin(self.__base_url, path) def matches(self, source, # type: str template # type: str ): # type: (...) -> Iterator[Match] - """ - Finds all matches of a given template within a source text. + """Finds all matches of a given template within a source text. Parameters: source: the source text to be searched. @@ -410,9 +389,7 @@ def substitute(self, template, # type: str args # type: Dict[str, str] ): # type: (...) -> str - """ - Substitutes a given set of terms into a given template. - """ + """Substitutes a given set of terms into a given template.""" logger = self.__logger logger.info("substituting arguments (%s) into template (%s)", repr(args), template) url = self._url("substitute") From be50e75709b7e945925b8dc8783ed8c5669afa32 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:12:53 -0400 Subject: [PATCH 02/17] drop support for Python 2.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8c16bf0..ced866f 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', ], - python_requires='>=2.7', + python_requires='>=3.5', install_requires=[ 'requests>=2.0.0', 'typing>=0.4.1' From b59f4b88741758c239041337a83bd54872ee3759 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:13:12 -0400 Subject: [PATCH 03/17] updated travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da0c1df..e5fe052 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ sudo: required services: - docker python: -- '2.7' - '3.5' - '3.6' +- '3.7' install: - pip install mypy - pip install . From 53d9dd4868cf333b08f75d4f7763f2c20eefa102 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:15:46 -0400 Subject: [PATCH 04/17] added pycodestyle --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e5fe052..21a565f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,10 @@ python: - '3.6' - '3.7' install: -- pip install mypy +- pip install mypy pycodestyle - pip install . script: +- pycodestyle src - mypy src --ignore-missing-imports notifications: email: false From fd546559c683361a06dad530cbd0130e106922ad Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:17:45 -0400 Subject: [PATCH 05/17] tidied classes --- src/rooibos/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index b9b42d2..e3c332d 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -33,7 +33,7 @@ logger.setLevel(logging.DEBUG) -class Location(object): +class Location: """ Represents the location of a single character within a source text by its zero-indexed line and column numbers. @@ -48,8 +48,10 @@ def from_string(s): def __init__(self, line, col): # type: (int, int) -> None - assert line > 0, "expected one-indexed line number greater than zero" - assert col >= 0, "expected one-indexed column number greater or equal to zero" + assert line > 0, \ + 'expected one-indexed line number greater than zero' + assert col >= 0, \ + 'expected one-indexed column number greater or equal to zero' self.__line = line self.__col = col @@ -78,7 +80,7 @@ def col(self): return self.__col -class LocationRange(object): +class LocationRange: """ Represents a contiguous range of locations within a given source text as a (non-inclusive) range of character positions. @@ -130,7 +132,7 @@ def stop(self): return self.__stop -class BoundTerm(object): +class BoundTerm: """Represents a binding of a named term to a fragment of source code.""" @staticmethod def from_dict(d): @@ -190,7 +192,7 @@ def fragment(self): return self.__fragment -class Environment(object): +class Environment: @staticmethod def from_dict(d): # type: (Dict[str, Any]) -> Environment @@ -231,7 +233,7 @@ def __getitem__(self, term): return self.__bindings[term] -class Match(object): +class Match: """ Describes a single match of a given template in a source text as a mapping of template terms to snippets of source code. @@ -292,7 +294,7 @@ def location(self): return self.__location -class Client(object): +class Client: """Provides an interface for communicating with a Rooibos server.""" def __init__(self, base_url, # type: str From 7bf24ebdf282787bd7d2026a6792866ebd789fee Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:19:09 -0400 Subject: [PATCH 06/17] removed weird/bad logging --- src/rooibos/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index e3c332d..4b5a70b 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -111,7 +111,8 @@ def __str__(self): """ Describes this location range as a string of the form `start::stop`, where `start` and `stop` are string-based descriptions of the positions - of the first and last characters within this source range, respectively. + of the first and last characters within this source range, + respectively. """ return "{}::{}".format(self.start, self.stop) @@ -317,8 +318,6 @@ def __init__(self, """ self.__base_url = base_url self.__timeout = timeout - self.__logger = logging.getLogger('rooibos') # type: logging.Logger - self.__logger.setLevel(logging.INFO) # attempt to establish a connection url = self._url("status") @@ -364,7 +363,6 @@ def matches(self, Returns: an iterator over all matches in the text. """ - logger = self.__logger logger.info("finding matches of template [%s] in source: %s", template, source) url = self._url("matches") payload = { @@ -392,7 +390,6 @@ def substitute(self, args # type: Dict[str, str] ): # type: (...) -> str """Substitutes a given set of terms into a given template.""" - logger = self.__logger logger.info("substituting arguments (%s) into template (%s)", repr(args), template) url = self._url("substitute") payload = { @@ -417,7 +414,6 @@ def rewrite(self, provided rewrite template and an optional set of arguments to that rewrite template. """ - logger = self.__logger logger.info("performing rewriting of source (%s) using match template (%s), rewrite template (%s) and arguments (%s)", source, match, rewrite, repr(args)) if args is None: From 10f997dd1095a43e7c24918a7bec2c966ae9a96e Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:20:10 -0400 Subject: [PATCH 07/17] tidied style --- src/rooibos/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 4b5a70b..a585274 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -363,7 +363,8 @@ def matches(self, Returns: an iterator over all matches in the text. """ - logger.info("finding matches of template [%s] in source: %s", template, source) + logger.info("finding matches of template [%s] in source: %s", + template, source) url = self._url("matches") payload = { 'source': source, @@ -390,7 +391,8 @@ def substitute(self, args # type: Dict[str, str] ): # type: (...) -> str """Substitutes a given set of terms into a given template.""" - logger.info("substituting arguments (%s) into template (%s)", repr(args), template) + logger.info("substituting arguments (%s) into template (%s)", + repr(args), template) url = self._url("substitute") payload = { 'template': template, @@ -414,7 +416,8 @@ def rewrite(self, provided rewrite template and an optional set of arguments to that rewrite template. """ - logger.info("performing rewriting of source (%s) using match template (%s), rewrite template (%s) and arguments (%s)", + logger.info("performing rewriting of source (%s) using match template " + "(%s), rewrite template (%s) and arguments (%s)", source, match, rewrite, repr(args)) if args is None: args = {} From 67e3b8c66f3e1b0658737ed73166ce4d53388361 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:30:37 -0400 Subject: [PATCH 08/17] updated type sigs --- src/rooibos/__init__.py | 182 +++++++++++++++------------------------- 1 file changed, 67 insertions(+), 115 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index a585274..15a343e 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -9,7 +9,7 @@ 'ephemeral_server' ) -from typing import Dict, Tuple, Iterator, List, Any +from typing import Dict, Tuple, Iterator, List, Any, Optional from contextlib import contextmanager from tempfile import TemporaryFile from timeit import default_timer as timer @@ -39,15 +39,13 @@ class Location: zero-indexed line and column numbers. """ @staticmethod - def from_string(s): - # type: (str) -> Location + def from_string(s: str) -> 'Location': s_line, _, s_col = s.partition(":") line = int(s_line) col = int(s_col) return Location(line, col) - def __init__(self, line, col): - # type: (int, int) -> None + def __init__(self, line: int, col: int) -> None: assert line > 0, \ 'expected one-indexed line number greater than zero' assert col >= 0, \ @@ -55,27 +53,23 @@ def __init__(self, line, col): self.__line = line self.__col = col - def __str__(self): - # type: () -> str + def __str__(self) -> str: """ Describes this location as a string of the form `line:col`, where `line and `col` are one-indexed line and column numbers. """ return "{}:{}".format(self.line, self.col) - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: return "rooibos.Location({})".format(self.__str__()) @property - def line(self): - # type: () -> int + def line(self) -> int: """The one-indexed line number for this location.""" return self.__line @property - def col(self): - # type: () -> int + def col(self) -> int: """The one-indexed column number for this location.""" return self.__col @@ -86,15 +80,13 @@ class LocationRange: (non-inclusive) range of character positions. """ @staticmethod - def from_string(s): - # type: (str) -> LocationRange + def from_string(s: str) -> 'LocationRange': s_start, _, s_end = s.partition("::") loc_start = Location.from_string(s_start) loc_end = Location.from_string(s_end) return LocationRange(loc_start, loc_end) - def __init__(self, start, stop): - # type: (Location, Location) -> None + def __init__(self, start: Location, stop: Location) -> None: """ Constructs a (non-inclusive) location range from a start and stop location. @@ -106,8 +98,7 @@ def __init__(self, start, stop): self.__start = start self.__stop = stop - def __str__(self): - # type: () -> str + def __str__(self) -> str: """ Describes this location range as a string of the form `start::stop`, where `start` and `stop` are string-based descriptions of the positions @@ -116,19 +107,16 @@ def __str__(self): """ return "{}::{}".format(self.start, self.stop) - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: return "rooibos.LocationRange({})".format(self.__str__()) @property - def start(self): - # type: () -> Location + def start(self) -> Location: """The position at which this range begins.""" return self.__start @property - def stop(self): - # type: () -> Location + def stop(self) -> Location: """The position at which this range ends, inclusive.""" return self.__stop @@ -136,22 +124,18 @@ def stop(self): class BoundTerm: """Represents a binding of a named term to a fragment of source code.""" @staticmethod - def from_dict(d): - # type: (Dict[str, Any]) -> BoundTerm - """ - Constructs a bound term from a dictionary-based description. - """ + def from_dict(d: Dict[str, Any]) -> 'BoundTerm': + """Constructs a bound term from a dictionary-based description.""" return BoundTerm(term=d['term'], location=LocationRange.from_string(d['location']), fragment=d['content']) - def __init__(self, - term, # type: str, - location, # type: LocationRange, - fragment, # type: str - ): # type: (...) -> None - """ - Constructs a new bound term. + def __init__(self, + term: str, + location: LocationRange, + fragment: str + ) -> None: + """Constructs a new bound term. Parameters: term: the name of the term. @@ -162,65 +146,47 @@ def __init__(self, self.__location = location self.__fragment = fragment - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: s = "rooibos.BoundTerm({}, {}, {})" return s.format(self.term, str(self.location), self.fragment) @property - def term(self): - # type: () -> str - """ - The name of the term. - """ + def term(self) -> str: + """The name of the term.""" return self.__term @property - def location(self): - # type: () -> LocationRange - """ - The location range covered by this term. - """ + def location(self) -> LocationRange: + """The location range covered by this term.""" return self.__location @property - def fragment(self): - # type: () -> str - """ - The source code fragment to which this term is bound, given as a - string. - """ + def fragment(self) -> str: + """The source code fragment to which this term is bound, as a string.=""" return self.__fragment class Environment: @staticmethod - def from_dict(d): - # type: (Dict[str, Any]) -> Environment + def from_dict(d: Dict[str, Any]) -> 'Environment': return Environment([BoundTerm.from_dict(bt) for bt in d]) - def __init__(self, bindings): - # type: (List[BoundTerm]) -> None + def __init__(self, bindings: List[BoundTerm]) -> None: self.__bindings = {b.term: b for b in bindings} - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: s = "rooibos.Environment([{}])" - s = s.format(', '.join([repr(self[t]) for t in self])) - return s + return s.format(', '.join([repr(self[t]) for t in self])) - def __iter__(self): - # type: () -> Iterator[str] + def __iter__(self) -> Iterator[str] """ - Returns an iterator over the names of the terms contained within - this environment. + Returns an iterator over the names of the terms within this + environment. """ return self.__bindings.keys().__iter__() - def __getitem__(self, term): - # type: (str) -> BoundTerm - """ - Fetches details of a particular term within this environment. + def __getitem__(self, term: str) -> BoundTerm: + """Fetches details of a particular term within this environment. Parameters: term: the name of the term. @@ -240,32 +206,27 @@ class Match: of template terms to snippets of source code. """ @staticmethod - def from_dict(d): - # type: (Dict[str, Any]) -> Match + def from_dict(d: Dict[str, Any]) -> 'Match': """Constructs a match from a dictionary-based description.""" return Match(environment=Environment.from_dict(d['environment']), location=LocationRange.from_string(d['location'])) - def __init__(self, environment, location): - # type: (Environment, LocationRange) -> None + def __init__(self, env: Environment, loc: LocationRange) -> None: """Constructs a new match. Parameters: - environment: an environment that describes the mapping from terms + env: an environment that describes the mapping from terms in the match template to snippets within the source text. - location: the location range over which the template was matched. + loc: the location range over which the template was matched. """ - self.__environment = environment - self.__location = location + self.__environment = env + self.__location = loc - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: s = "rooibos.Match({}, {})" - s = s.format(str(self.__location), repr(self.__environment)) - return s + return s.format(str(self.__location), repr(self.__environment)) - def __getitem__(self, term): - # type: (str) -> BoundTerm + def __getitem__(self, term: str) -> BoundTerm: """Retrieves a bound term from this match. Parameters: @@ -280,8 +241,7 @@ def __getitem__(self, term): return self.__environment[term] @property - def environment(self): - # type: () -> Environment + def environment(self) -> Environment: """ The environment that defines the mapping from terms in the match template to snippets in the source code. @@ -289,8 +249,7 @@ def environment(self): return self.__environment @property - def location(self): - # type: () -> LocationRange + def location(self) -> LocationRange: """The range of locations in the text where the template matched.""" return self.__location @@ -298,10 +257,10 @@ def location(self): class Client: """Provides an interface for communicating with a Rooibos server.""" def __init__(self, - base_url, # type: str - timeout=30, # type: int - timeout_connection=30 # type: int - ): # type: (...) -> None + base_url: str, + timeout: int = 30, + timeout_connection: int = 30 + ) -> None: """Constructs a new client. Parameters: @@ -338,22 +297,15 @@ def __init__(self, raise ConnectionFailure @property - def base_url(self): - # type: () -> str - """ - The base URL of the Rooibos server to which this client is attached. - """ + def base_url(self) -> str: + """The base URL of the server to which this client is attached.""" return self.__base_url - def _url(self, path): - # type: (str) -> str + def _url(self, path: str) -> str: """Computes the URL for a resource on the server.""" return urljoin(self.__base_url, path) - def matches(self, - source, # type: str - template # type: str - ): # type: (...) -> Iterator[Match] + def matches(self, source: str, template: str) -> Iterator[Match]: """Finds all matches of a given template within a source text. Parameters: @@ -387,9 +339,9 @@ def matches(self, yield match def substitute(self, - template, # type: str - args # type: Dict[str, str] - ): # type: (...) -> str + template: str, + args: Dict[str, str] + ) -> str: """Substitutes a given set of terms into a given template.""" logger.info("substituting arguments (%s) into template (%s)", repr(args), template) @@ -406,11 +358,11 @@ def substitute(self, return response.text def rewrite(self, - source, # type: str - match, # type: str - rewrite, # type: str - args=None # type: Dict[str, str] - ): # type: (...) -> str + source: str, + match: str, + rewrite: str, + args: Optional[Dict[str, str]] = None + ) -> str: """ Rewrites all matches of a given template in a source text using a provided rewrite template and an optional set of arguments to that @@ -437,9 +389,9 @@ def rewrite(self, @contextmanager -def ephemeral_server(port=8888, # type: int - verbose=False # type: bool - ): # type: (...) -> Iterator[Client] +def ephemeral_server(port: int = 8888, + verbose: bool = False + ) -> Iterator[Client]: """ Launches an ephemeral server instance that will be immediately close when no longer in context. From 9bb0628ac3b14177aa6efc361beda33b4d6245b3 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:31:29 -0400 Subject: [PATCH 09/17] fixed bad indentation --- src/rooibos/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 15a343e..917bb0c 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -130,11 +130,11 @@ def from_dict(d: Dict[str, Any]) -> 'BoundTerm': location=LocationRange.from_string(d['location']), fragment=d['content']) - def __init__(self, - term: str, - location: LocationRange, - fragment: str - ) -> None: + def __init__(self, + term: str, + location: LocationRange, + fragment: str + ) -> None: """Constructs a new bound term. Parameters: From 08bcd9ef5f1970d8d0d0fdd3c37514e2dcc3c835 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:33:04 -0400 Subject: [PATCH 10/17] bug fix: missing char --- src/rooibos/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 917bb0c..13c3607 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -178,7 +178,7 @@ def __repr__(self) -> str: s = "rooibos.Environment([{}])" return s.format(', '.join([repr(self[t]) for t in self])) - def __iter__(self) -> Iterator[str] + def __iter__(self) -> Iterator[str]: """ Returns an iterator over the names of the terms within this environment. From 816ae30f91ccd7d80a4b1355508e3bc4547e5a4b Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:33:30 -0400 Subject: [PATCH 11/17] short comment --- src/rooibos/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 13c3607..d018d16 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -162,7 +162,7 @@ def location(self) -> LocationRange: @property def fragment(self) -> str: - """The source code fragment to which this term is bound, as a string.=""" + """The source code fragment to which this term is bound.""" return self.__fragment From a91be1b2fa79706b020ef89fed51870e44f872ca Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:34:01 -0400 Subject: [PATCH 12/17] tidied exceptions --- src/rooibos/exceptions.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rooibos/exceptions.py b/src/rooibos/exceptions.py index 3a9878a..81dcb02 100644 --- a/src/rooibos/exceptions.py +++ b/src/rooibos/exceptions.py @@ -1,10 +1,9 @@ -__all__ = ['RooibosException', 'ConnectionFailure'] +# -*- coding: utf-8 -*- +__all__ = ('RooibosException', 'ConnectionFailure') class RooibosException(Exception): - """ - Base class used by all Rooibos exceptions. - """ + """Base class used by all Rooibos exceptions.""" class ConnectionFailure(RooibosException): From 6012475d969bfc510abb64ef72f094824f6bc195 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:37:07 -0400 Subject: [PATCH 13/17] simplified imports --- src/rooibos/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index d018d16..e6eed2a 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -10,8 +10,7 @@ ) from typing import Dict, Tuple, Iterator, List, Any, Optional -from contextlib import contextmanager -from tempfile import TemporaryFile +from urllib.parse import urljoin, urlparse from timeit import default_timer as timer import time import os @@ -19,11 +18,6 @@ import signal import logging -try: - from urllib.parse import urljoin, urlparse -except ImportError: - from urlparse import urljoin, urlparse - import requests from .version import __version__ From 37b705e2bd782ac7081002d115ae8ef501d9244d Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:38:16 -0400 Subject: [PATCH 14/17] fixed bad construction --- src/rooibos/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index e6eed2a..42408eb 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -202,8 +202,8 @@ class Match: @staticmethod def from_dict(d: Dict[str, Any]) -> 'Match': """Constructs a match from a dictionary-based description.""" - return Match(environment=Environment.from_dict(d['environment']), - location=LocationRange.from_string(d['location'])) + return Match(Environment.from_dict(d['environment']), + LocationRange.from_string(d['location'])) def __init__(self, env: Environment, loc: LocationRange) -> None: """Constructs a new match. From d17b33844c508f53c0345c927e734d07de43a97b Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:40:38 -0400 Subject: [PATCH 15/17] fixed bad from_dict --- src/rooibos/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index 42408eb..d8a5070 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -163,7 +163,7 @@ def fragment(self) -> str: class Environment: @staticmethod def from_dict(d: Dict[str, Any]) -> 'Environment': - return Environment([BoundTerm.from_dict(bt) for bt in d]) + return Environment([BoundTerm.from_dict(bt) for bt in d.values()]) def __init__(self, bindings: List[BoundTerm]) -> None: self.__bindings = {b.term: b for b in bindings} From 39adb0ff860370d97e381922dc4d24c1add17978 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:41:18 -0400 Subject: [PATCH 16/17] bug fix: missing import --- src/rooibos/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rooibos/__init__.py b/src/rooibos/__init__.py index d8a5070..2c12590 100644 --- a/src/rooibos/__init__.py +++ b/src/rooibos/__init__.py @@ -12,6 +12,7 @@ from typing import Dict, Tuple, Iterator, List, Any, Optional from urllib.parse import urljoin, urlparse from timeit import default_timer as timer +from contextlib import contextmanager import time import os import subprocess From abbfcf57bb203b62ca5c974984b7ef6543214b75 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Mon, 5 Aug 2019 11:57:29 -0400 Subject: [PATCH 17/17] no travis support for 3.7 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 21a565f..bd43186 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ services: python: - '3.5' - '3.6' -- '3.7' install: - pip install mypy pycodestyle - pip install .