Completed
Push — master ( 5e51a6...52387f )
by Charles
01:50
created

commit()   A

Complexity

Conditions 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
1
# -*- coding: utf-8 -*-
2
"""
3
    Git fixtures helpers
4
"""
5
6
import os
7
import subprocess
0 ignored issues
show
Unused Code introduced by
The import subprocess seems to be unused.
Loading history...
8
9
from git import Repo
0 ignored issues
show
Configuration introduced by
The import git could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
10
11
def commit(repo, message, author=None, date=None):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
12
    cwd = os.getcwd()
13
14
    os.chdir(repo.working_dir)
15
16
    # need to do a manual commit to allow empty message and set committer date
17
    cmd = 'git commit --allow-empty -m "{}"'.format(message)
18
    if author:
19
        cmd = cmd+' --author="{}"'.format(author)
20
21
    if date:
22
        cmd = 'GIT_COMMITTER_DATE="{}" '.format(date)+cmd+' --date="{}"'.format(date)
23
24
    os.system(cmd)
25
    os.chdir(cwd)
26
27
    return repo.commit('HEAD')
28
29
def tag(repo, version, author=None, date=None):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
30
    commit_obj = commit(repo=repo, message="release: {}".format(version), author=author, date=date)
31
    repo.create_tag(path=version, message=version)
32
33
    return commit_obj
34
35
def branch(repo, branch, start='HEAD'):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility Bug introduced by
branch is re-defining a name which is already available in the outer-scope (previously defined on line 35).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
36
    return repo.create_head(branch, commit=start)
37
38
def clone(remote_repo, path):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
39
    return remote_repo.clone(path)
40
41
def init(email='[email protected]', username='User Test', repo_dir=None):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
42
    cwd = os.getcwd()
43
    if not repo_dir or not os.path.exists(repo_dir):
44
        repo_dir = cwd
45
46
    os.chdir(repo_dir)
47
48
    repo = Repo.init(repo_dir)
49
50
    # git config
51
    with repo.config_writer() as cfg:
52
        cfg.add_section('user')
53
        cfg.set('user', 'email', email)
54
        cfg.set('user', 'name', username)
55
56
        cfg.release()
57
58
    os.chdir(cwd)
59
60
    return repo
61
62
def default_init(version='0.1.2', email='[email protected]', username='User Test',
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many arguments (7/5)
Loading history...
63
        author='User Test <[email protected]>', date='2016-11-20T12:41:30+0000',
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation.
author='User Test <[email protected]>', date='2016-11-20T12:41:30+0000',
^ |
Loading history...
64
        tag_date='2016-11-20T12:42:30+0000', repo_dir=None):
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation.
tag_date='2016-11-20T12:42:30+0000', repo_dir=None):
^ |
Loading history...
65
    repo = init(email=email, username=username, repo_dir=repo_dir)
66
    commit(repo=repo, message='initial commit', author=author, date=date)
67
    tag(repo=repo, version=version, author=author, date=tag_date)
68
69
    return repo
70