requirements.py
Go to the documentation of this file.
00001 # Software License Agreement (GPL)
00002 #
00003 # \file      requirements.py
00004 # \authors   Paul Bovbel <pbovbel@locusrobotics.com>
00005 # \copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.
00006 #
00007 # This program is free software: you can redistribute it and/or
00008 # modify it under the terms of the GNU General Public License as
00009 # published by the Free Software Foundation, either version 2 of the
00010 # License, or (at your option) any later version.
00011 #
00012 # This program is distributed in the hope that it will be useful, but
00013 # WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015 # General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU General Public License
00018 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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     # Borrowing https://github.com/pypa/pipenv/tree/dde2e52cb8bc9bfca7af6c6b1a4576faf00e84f1/pipenv/vendor/requirements
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


catkin_virtualenv
Author(s): Paul Bovbel
autogenerated on Thu Jun 27 2019 20:04:50