Add static typing for vcs module
This commit is contained in:
parent
914ea66cc3
commit
0a2d3cc3e0
|
@ -19,6 +19,8 @@
|
|||
|
||||
import os
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
class FolderSet:
|
||||
'''Utility class to help support Git and Monotone.
|
||||
|
@ -27,18 +29,18 @@ class FolderSet:
|
|||
"mtn automate inventory."
|
||||
'''
|
||||
|
||||
def __init__(self, names):
|
||||
self.folders = f = []
|
||||
def __init__(self, names: List[str]) -> None:
|
||||
self.folders: List[str] = []
|
||||
for name in names:
|
||||
name = os.path.abspath(name)
|
||||
# ensure all names end with os.sep
|
||||
if not name.endswith(os.sep):
|
||||
name += os.sep
|
||||
f.append(name)
|
||||
self.folders.append(name)
|
||||
|
||||
# returns True if the given abspath is a file that should be included in
|
||||
# the interesting file subset
|
||||
def contains(self, abspath):
|
||||
def contains(self, abspath: str) -> bool:
|
||||
if not abspath.endswith(os.sep):
|
||||
abspath += os.sep
|
||||
for f in self.folders:
|
||||
|
|
|
@ -30,7 +30,7 @@ from diffuse.vcs.vcs_interface import VcsInterface
|
|||
# Mercurial support
|
||||
class Hg(VcsInterface):
|
||||
def __init__(self, root: str):
|
||||
VcsInterface.__init__(self, root)
|
||||
super().__init__(root)
|
||||
self.working_rev: Optional[str] = None
|
||||
|
||||
def _getPreviousRevision(self, prefs, rev):
|
||||
|
|
|
@ -33,7 +33,7 @@ from diffuse.vcs.vcs_interface import VcsInterface
|
|||
# SVK support subclasses from this
|
||||
class Svn(VcsInterface):
|
||||
def __init__(self, root: str):
|
||||
VcsInterface.__init__(self, root)
|
||||
super().__init__(root)
|
||||
self.url: Optional[str] = None
|
||||
|
||||
@staticmethod
|
||||
|
@ -61,7 +61,7 @@ class Svn(VcsInterface):
|
|||
m = int(rev)
|
||||
return str(max(m > 1, 0))
|
||||
|
||||
def _getURL(self, prefs):
|
||||
def _getURL(self, prefs: Preferences) -> Optional[str]:
|
||||
if self.url is None:
|
||||
vcs, prefix = self._getVcs(), self._getURLPrefix()
|
||||
n = len(prefix)
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from diffuse.preferences import Preferences
|
||||
|
||||
|
||||
class VcsInterface:
|
||||
class VcsInterface(metaclass=ABCMeta):
|
||||
"""Interface for the VCSs."""
|
||||
|
||||
PathRevisionPair = Tuple[Optional[str], Optional[str]]
|
||||
|
@ -32,15 +33,19 @@ class VcsInterface:
|
|||
"""The object will initialized with the repository's root folder."""
|
||||
self.root = root
|
||||
|
||||
@abstractmethod
|
||||
def getFileTemplate(self, prefs: Preferences, name: str) -> PathRevisionList:
|
||||
"""Indicates which revisions to display for a file when none were explicitly
|
||||
requested."""
|
||||
|
||||
@abstractmethod
|
||||
def getCommitTemplate(self, prefs, rev, names):
|
||||
"""Indicates which file revisions to display for a commit."""
|
||||
|
||||
@abstractmethod
|
||||
def getFolderTemplate(self, prefs, names):
|
||||
"""Indicates which file revisions to display for a set of folders."""
|
||||
|
||||
@abstractmethod
|
||||
def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
|
||||
"""Returns the contents of the specified file revision"""
|
||||
|
|
|
@ -186,7 +186,8 @@ def _get_svk_repo(path: str, prefs: Preferences) -> Optional[VcsInterface]:
|
|||
# find working copies by parsing the config file
|
||||
with open(svkconfig, 'r', encoding='utf-8') as f:
|
||||
ss: List[str] = utils.readlines(f)
|
||||
projs, sep = [], os.sep
|
||||
projs: List[str] = []
|
||||
sep = os.sep
|
||||
# find the separator character
|
||||
for s in ss:
|
||||
if s.startswith(' sep: ') and len(s) > 7:
|
||||
|
|
Loading…
Reference in New Issue