diff --git a/src/linkahead/common/versioning.py b/src/linkahead/common/versioning.py index 11cf5f6904b02954eb0b2bddc16478590df167e7..1c2999df8174e239a470cfc637533c3c8c302c33 100644 --- a/src/linkahead/common/versioning.py +++ b/src/linkahead/common/versioning.py @@ -101,11 +101,14 @@ class Version(): # pylint: disable=redefined-builtin def __init__(self, id: Optional[str] = None, date: Optional[str] = None, username: Optional[str] = None, realm: Optional[str] = None, - predecessors: Optional[List[Version]] = None, successors: Optional[List[Version]] = None, + predecessors: Optional[List[Version]] = None, + successors: Optional[List[Version]] = None, is_head: Union[bool, str, None] = False, is_complete_history: Union[bool, str, None] = False): - """Typically the `predecessors` or `successors` should not "link back" to an existing Version - object.""" + """Typically the `predecessors` or `successors` should not "link back" to an existing + Version object. + + """ self.id = id self.date = date self.username = username @@ -205,8 +208,8 @@ class Version(): version : Version a new version instance """ - predecessors = [Version.from_xml(p) for p in xml if p.tag.lower() == "predecessor"] - successors = [Version.from_xml(s) for s in xml if s.tag.lower() == "successor"] + predecessors = [Version.from_xml(p) for p in xml if str(p.tag).lower() == "predecessor"] + successors = [Version.from_xml(s) for s in xml if str(s.tag).lower() == "successor"] return Version(id=xml.get("id"), date=xml.get("date"), is_head=xml.get("head"), is_complete_history=xml.get("completeHistory"), diff --git a/src/linkahead/connection/connection.py b/src/linkahead/connection/connection.py index c95134fed3fd6b031b01b518c6362bf3b371c960..f75226d42e5f7ca15f8300ad31528cda00f1146f 100644 --- a/src/linkahead/connection/connection.py +++ b/src/linkahead/connection/connection.py @@ -103,9 +103,12 @@ class _WrappedHTTPResponse(CaosDBHTTPResponse): if len(self._buffer) >= size: # still enough bytes in the buffer # FIXME: `chunk`` is used before definition - result = chunk[:size] - self._buffer = chunk[size:] - return result + raise NotImplementedError("chunk is undefined") + + # # old code: + # result = chunk[:size] + # self._buffer = chunk[size:] + # return result if self._generator is None: # first call to this method @@ -218,7 +221,7 @@ class _DefaultCaosDBServerConnection(CaosDBServerConnection): "Connection failed. Network or server down? " + str(conn_err) ) - def configure(self, **config): + def configure(self, **config) -> None: """configure. Configure the http connection. @@ -551,9 +554,9 @@ class _Connection(object): # pylint: disable=useless-object-inheritance __instance = None - def __init__(self): + def __init__(self) -> None: self._delegate_connection: Optional[CaosDBServerConnection] = None - self._authenticator: Optional[CredentialsAuthenticator] = None + self._authenticator: Optional[AbstractAuthenticator] = None self.is_configured = False @classmethod @@ -563,7 +566,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance return cls.__instance - def configure(self, **config): + def configure(self, **config) -> _Connection: self.is_configured = True if "implementation" not in config: @@ -571,8 +574,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance "Missing CaosDBServerConnection implementation. You did not " "specify an `implementation` for the connection.") try: - self._delegate_connection: CaosDBServerConnection = config["implementation"]( - ) + self._delegate_connection = config["implementation"]() if not isinstance(self._delegate_connection, CaosDBServerConnection): @@ -762,6 +764,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance if self._authenticator is None: raise ValueError( "No authenticator set. Please call configure_connection() first.") + assert isinstance(self._authenticator, CredentialsAuthenticator) if self._authenticator._credentials_provider is None: raise ValueError( "No credentials provider set. Please call configure_connection() first.") diff --git a/src/linkahead/utils/git_utils.py b/src/linkahead/utils/git_utils.py index 7a58272a3bef1930f75a1e08364349388e2bb89f..4824d619bfc77925add0c383f72360a644dd7833 100644 --- a/src/linkahead/utils/git_utils.py +++ b/src/linkahead/utils/git_utils.py @@ -36,9 +36,9 @@ logger = logging.getLogger(__name__) def get_origin_url_in(folder: str): """return the Fetch URL of the git repository in the given folder.""" - with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: - call(["git", "remote", "show", "origin"], stdout=t, cwd=folder) - with open(t.name, "r") as t: + with tempfile.NamedTemporaryFile(delete=False, mode="w", encoding="utf8") as tempf: + call(["git", "remote", "show", "origin"], stdout=tempf, cwd=folder) + with open(tempf.name, "r", encoding="utf8") as t: urlString = "Fetch URL:" for line in t.readlines(): @@ -63,9 +63,9 @@ def get_branch_in(folder: str): The command "git branch" is called in the given folder and the output is returned """ - with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: - call(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=t, cwd=folder) - with open(t.name, "r") as t: + with tempfile.NamedTemporaryFile(delete=False, mode="w") as tempf: + call(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=tempf, cwd=folder) + with open(tempf.name, "r") as t: return t.readline().strip() @@ -76,7 +76,7 @@ def get_commit_in(folder: str): and the output is returned """ - with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: - call(["git", "log", "-1", "--format=%h"], stdout=t, cwd=folder) - with open(t.name, "r") as t: + with tempfile.NamedTemporaryFile(delete=False, mode="w") as tempf: + call(["git", "log", "-1", "--format=%h"], stdout=tempf, cwd=folder) + with open(tempf.name, "r") as t: return t.readline().strip()