Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import re
00020
00021 from packaging.requirements import InvalidRequirement
00022
00023
00024 class VcsRequirement(object):
00025 '''A non-semver requirement from a version control system.
00026 eg. svn+http://myrepo/svn/MyApp#egg=MyApp
00027 '''
00028
00029
00030 VCS_SCHEMES = [
00031 'git',
00032 'git+https',
00033 'git+ssh',
00034 'git+git',
00035 'hg+http',
00036 'hg+https',
00037 'hg+static-http',
00038 'hg+ssh',
00039 'svn',
00040 'svn+svn',
00041 'svn+http',
00042 'svn+https',
00043 'svn+ssh',
00044 'bzr+http',
00045 'bzr+https',
00046 'bzr+ssh',
00047 'bzr+sftp',
00048 'bzr+ftp',
00049 'bzr+lp',
00050 ]
00051
00052 name_regex = re.compile(
00053 r'^(?P<scheme>{0})://'.format(r'|'.join(
00054 [scheme.replace('+', r'\+') for scheme in VCS_SCHEMES])) +
00055 r'((?P<login>[^/@]+)@)?'
00056 r'(?P<path>[^#@]+)'
00057 r'(@(?P<revision>[^#]+))?'
00058 r'(#egg=(?P<name>[^&]+))?$'
00059 )
00060
00061 def __init__(self, string):
00062 self.string = string
00063
00064 match = self.name_regex.search(self.string)
00065 if match is None:
00066 raise InvalidRequirement("No match for {}".format(self.name_regex.pattern))
00067
00068 self.name = match.group('name')
00069 if self.name is None:
00070 raise InvalidRequirement("No project name '#egg=<name>' was provided")
00071
00072 def __str__(self):
00073 return self.string