-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgulp_version.py
67 lines (53 loc) · 2.07 KB
/
gulp_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import re
# Workaround for Windows ST2 not having disutils
try:
from distutils.version import LooseVersion
except:
# From distutils/version.py
class LooseVersion():
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
def __init__ (self, vstring=None):
if vstring:
self.parse(vstring)
def __ge__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c >= 0
def parse (self, vstring):
self.vstring = vstring
components = [x for x in self.component_re.split(vstring) if x and x != '.']
for i, obj in enumerate(components):
try:
components[i] = int(obj)
except ValueError:
pass
self.version = components
def _cmp (self, other):
if isinstance(other, str):
other = LooseVersion(other)
if self.version == other.version:
return 0
if self.version < other.version:
return -1
if self.version > other.version:
return 1
#
# Actual class
#
class GulpVersion():
def __init__(self, version_string):
self.version_string = version_string or ""
def supports_tasks_simple(self):
# This is a mess. The new gulp-cli started from version 0 and does support tasks-simple,
# but there's no reliable way to check which one is installed
# So here we are, having to check if the CLI version is _not_ between 3.6.0 and 3.7.0 which works..for now
cli_version = LooseVersion(self.cli_version())
return cli_version >= LooseVersion("3.7.0") or cli_version <= LooseVersion("3.6.0")
def cli_version(self):
return self.get("CLI")
def local_version(self):
return self.get("Local")
def get(self, version_name):
re_match = re.search(version_name + " version (\d+\.\d+\.\d+)", self.version_string)
return re_match.group(1) if re_match else "3.6.0"