requirements.py
Go to the documentation of this file.
1 # Software License Agreement (GPL)
2 #
3 # \file requirements.py
4 # \authors Paul Bovbel <pbovbel@locusrobotics.com>
5 # \copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.
6 #
7 # This program is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation, either version 2 of the
10 # License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import re
20 
21 from packaging.requirements import InvalidRequirement
22 
23 
24 class VcsRequirement(object):
25  '''A non-semver requirement from a version control system.
26  eg. svn+http://myrepo/svn/MyApp#egg=MyApp
27  '''
28 
29  # Borrowing https://github.com/pypa/pipenv/tree/dde2e52cb8bc9bfca7af6c6b1a4576faf00e84f1/pipenv/vendor/requirements
30  VCS_SCHEMES = [
31  'git',
32  'git+https',
33  'git+ssh',
34  'git+git',
35  'hg+http',
36  'hg+https',
37  'hg+static-http',
38  'hg+ssh',
39  'svn',
40  'svn+svn',
41  'svn+http',
42  'svn+https',
43  'svn+ssh',
44  'bzr+http',
45  'bzr+https',
46  'bzr+ssh',
47  'bzr+sftp',
48  'bzr+ftp',
49  'bzr+lp',
50  ]
51 
52  name_regex = re.compile(
53  r'^(?P<scheme>{0})://'.format(r'|'.join(
54  [scheme.replace('+', r'\+') for scheme in VCS_SCHEMES])) +
55  r'((?P<login>[^/@]+)@)?'
56  r'(?P<path>[^#@]+)'
57  r'(@(?P<revision>[^#]+))?'
58  r'(#egg=(?P<name>[^&]+))?$'
59  )
60 
61  def __init__(self, string):
62  self.string = string
63 
64  match = self.name_regex.search(self.string)
65  if match is None:
66  raise InvalidRequirement("No match for {}".format(self.name_regex.pattern))
67 
68  self.name = match.group('name')
69  if self.name is None:
70  raise InvalidRequirement("No project name '#egg=<name>' was provided")
71 
72  def __str__(self):
73  return self.string


catkin_virtualenv
Author(s): Paul Bovbel
autogenerated on Mon Jul 1 2019 19:33:08