Completed
Pull Request — master (#2304)
by Arma
07:07
created

Dumper   B

Complexity

Total Complexity 38

Size/Duplication

Total Lines 149
Duplicated Lines 0 %
Metric Value
wmc 38
dl 0
loc 149
rs 8.4

13 Methods

Rating   Name   Duplication   Size   Complexity  
A _get_file_name() 0 5 1
A _write_to_disk() 0 17 4
A _create_date_folder() 0 10 3
A _get_date_folder() 0 2 1
A _write_marker_to_db() 0 17 3
A wait() 0 2 1
A start() 0 4 2
A stop() 0 3 1
A _write_batch_to_disk() 0 3 1
B _get_batch() 0 16 5
B _update_marker() 0 15 6
A _flush() 0 9 4
B __init__() 0 32 6
1
# -*- coding: utf-8 -*-
2
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3
# contributor license agreements.  See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to You under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License.  You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
17
import os
18
19
from pip.req import parse_requirements
20
21
__all__ = [
22
    'fetch_requirements',
23
    'apply_vagrant_workaround'
24
]
25
26
27
def fetch_requirements(requirements_file_path):
28
    """
29
    Return a list of requirements and links by parsing the provided requirements file.
30
    """
31
    links = []
32
    reqs = []
33
    for req in parse_requirements(requirements_file_path, session=False):
34
        if req.link:
35
            links.append(str(req.link))
36
        reqs.append(str(req.req))
37
    return (reqs, links)
38
39
40
def apply_vagrant_workaround():
41
    """
42
    Function which detects if the script is being executed inside vagrant and if it is, it deletes
43
    "os.link" attribute.
44
    Note: Without this workaround, setup.py sdist will fail when running inside a shared directory
45
    (nfs / virtualbox shared folders).
46
    """
47
    if os.environ.get('USER', None) == 'vagrant':
48
        del os.link
49