-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
dist_utils.py
58 lines (47 loc) · 1.74 KB
/
dist_utils.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
# -*- coding: utf-8 -*-
# Copyright 2020 The StackStorm Authors
# Copyright (C) 2020 Extreme Networks, Inc - All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
import os
import re
import sys
from distutils.version import StrictVersion
__all__ = [
'apply_vagrant_workaround',
'get_version_string',
'parse_version_string'
]
def apply_vagrant_workaround():
"""
Function which detects if the script is being executed inside vagrant and if it is, it deletes
"os.link" attribute.
Note: Without this workaround, setup.py sdist will fail when running inside a shared directory
(nfs / virtualbox shared folders).
"""
if os.environ.get('USER', None) == 'vagrant':
del os.link
def get_version_string(init_file):
"""
Read __version__ string for an init file.
"""
with open(init_file, 'r') as fp:
content = fp.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
content, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError('Unable to find version string in %s.' % (init_file))
# alias for get_version_string
parse_version_string = get_version_string