Skip to content

Commit

Permalink
Improved type hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Feb 14, 2023
1 parent 7dfac77 commit d05060d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 41 deletions.
15 changes: 6 additions & 9 deletions pyVersioning/AppVeyor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# ==================================================================================================================== #
#
"""AppVeyor specific code to collect the build environment."""
from os import environ
from os import environ
from typing import Optional as Nullable

from pyTooling.Decorators import export

Expand All @@ -54,21 +55,17 @@ def getGitHash(self) -> str:
except KeyError as ex:
raise ServiceException from ex

def getGitBranch(self) -> str:
def getGitBranch(self) -> Nullable[str]:
try:
return environ['APPVEYOR_REPO_BRANCH']
except KeyError:
pass
return None

return None

def getGitTag(self) -> str:
def getGitTag(self) -> Nullable[str]:
try:
return environ['APPVEYOR_REPO_TAG_NAME']
except KeyError:
pass

return None
return None

def getGitRepository(self) -> str:
try:
Expand Down
25 changes: 12 additions & 13 deletions pyVersioning/CIService.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
# ==================================================================================================================== #
#
"""Module for CI service base classes."""
from dataclasses import make_dataclass, dataclass
from dataclasses import make_dataclass
from datetime import datetime
from os import environ

from pyTooling.MetaClasses import ExtendedType, abstractmethod
from typing import Dict
from typing import Dict, Optional as Nullable

from pyTooling.Decorators import export
from pyTooling.MetaClasses import ExtendedType, abstractmethod

from pyVersioning import SelfDescriptive, GitHelper, GitShowCommand

Expand Down Expand Up @@ -75,10 +74,10 @@ def getPlatform(self) -> Platform:
class CIService(BaseService, GitHelper):
"""Base-class to collect Git and other platform and environment information from CI service environment variables."""

ENV_INCLUDE_FILTER = ()
ENV_EXCLUDE_FILTER = ()
ENV_INCLUDES = []
ENV_EXCLUDES = []
ENV_INCLUDE_FILTER = ()
ENV_EXCLUDE_FILTER = ()
ENV_INCLUDES = []
ENV_EXCLUDES = []

def getEnvironment(self) -> Dict[str, str]:
""".. todo:: getEnvironment needs documentation"""
Expand Down Expand Up @@ -108,9 +107,9 @@ def func(s):
[(name, str) for name in filteredEnv.keys()],
bases=(SelfDescriptive,),
namespace={
'as_dict': lambda self: filteredEnv,
'Keys': lambda self: filteredEnv.keys(),
'KeyValuePairs': lambda self: func(self)
'as_dict': lambda self: filteredEnv,
'Keys': lambda self: filteredEnv.keys(),
'KeyValuePairs': lambda self: func(self)
},
repr=True
)
Expand All @@ -129,11 +128,11 @@ def getCommitDate(self) -> datetime:
return datetime.fromtimestamp(int(datetimeString))

@abstractmethod
def getGitBranch(self) -> str:
def getGitBranch(self) -> Nullable[str]:
""".. todo:: getGitBranch needs documentation"""

@abstractmethod
def getGitTag(self) -> str:
def getGitTag(self) -> Nullable[str]:
""".. todo:: getGitTag needs documentation"""

@abstractmethod
Expand Down
8 changes: 2 additions & 6 deletions pyVersioning/GitHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def getGitBranch(self) -> Nullable[str]:
if ref.startswith(branchPrefix):
return ref[len(branchPrefix):]
except KeyError:
pass

return None
return None

def getGitTag(self) -> Nullable[str]:
tagPrefix = "refs/tags/"
Expand All @@ -76,9 +74,7 @@ def getGitTag(self) -> Nullable[str]:
if ref.startswith(tagPrefix):
return ref[len(tagPrefix):]
except KeyError:
pass

return None
return None

def getGitRepository(self) -> str:
try:
Expand Down
8 changes: 2 additions & 6 deletions pyVersioning/GitLab.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ def getGitBranch(self) -> Nullable[str]:
try:
return environ['CI_COMMIT_BRANCH']
except KeyError:
pass

return None
return None

def getGitTag(self) -> Nullable[str]:
try:
return environ['CI_COMMIT_TAG']
except KeyError:
pass

return None
return None

def getGitRepository(self) -> str:
try:
Expand Down
9 changes: 2 additions & 7 deletions pyVersioning/Travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# ==================================================================================================================== #
#
"""Travis specific code to collect the build environment."""
from datetime import datetime
from os import environ
from typing import Optional as Nullable, Dict

Expand Down Expand Up @@ -63,17 +62,13 @@ def getGitBranch(self) -> Nullable[str]:
try:
return environ['TRAVIS_BRANCH']
except KeyError:
pass

return None
return None

def getGitTag(self) -> Nullable[str]:
try:
return environ['TRAVIS_TAG']
except KeyError:
pass

return None
return None

def getGitRepository(self) -> str:
try:
Expand Down

0 comments on commit d05060d

Please sign in to comment.