Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .pylint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ disable=
too-many-arguments,
too-many-branches,
keyword-arg-before-vararg,
logging-not-lazy,
redefined-builtin,
too-many-public-methods,
bad-continuation,
Expand Down Expand Up @@ -290,14 +289,6 @@ single-line-class-stmt=no
# else.
single-line-if-stmt=no


[LOGGING]

# Logging modules to check that the string format arguments are in logging
# function parameter format
logging-modules=logging


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
Expand Down
6 changes: 2 additions & 4 deletions gitman/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
"""Command-line interface."""

import argparse
import logging
import sys
from typing import Dict, List

from . import __version__, commands, common, exceptions

import log

log = logging.getLogger(__name__)
from . import __version__, commands, common, exceptions


def main(args=None, function=None): # pylint: disable=too-many-statements
Expand Down
6 changes: 2 additions & 4 deletions gitman/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import datetime
import functools
import logging
import os

import log

from . import common, system
from .models import Config, Source, load_config


log = logging.getLogger(__name__)


def restore_cwd(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
Expand Down
27 changes: 15 additions & 12 deletions gitman/common.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Common exceptions, classes, and functions."""

import argparse
import logging
import os
import sys

from . import settings

import log

_log = logging.getLogger(__name__)
from . import settings


class WideHelpFormatter(argparse.HelpFormatter):
Expand All @@ -19,7 +17,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class WarningFormatter(logging.Formatter):
class WarningFormatter(log.logging.Formatter):
"""Logging formatter that displays verbose formatting for WARNING+."""

def __init__(self, default_format, verbose_format, *args, **kwargs):
Expand All @@ -29,7 +27,7 @@ def __init__(self, default_format, verbose_format, *args, **kwargs):

def format(self, record):
# pylint: disable=protected-access
if record.levelno > logging.INFO:
if record.levelno > log.INFO:
self._style._fmt = self.verbose_format
else:
self._style._fmt = self.default_format
Expand Down Expand Up @@ -80,18 +78,18 @@ def configure_logging(count=0):
verbose_format = settings.VERBOSE2_LOGGING_FORMAT

# Set a custom formatter
logging.basicConfig(level=level)
logging.captureWarnings(True)
log.init(level=level)
log.silence('yorm', allow_warning=True)
log.logging.captureWarnings(True)
formatter = WarningFormatter(
default_format, verbose_format, datefmt=settings.LOGGING_DATEFMT
)
logging.root.handlers[0].setFormatter(formatter)
logging.getLogger('yorm').setLevel(max(level, settings.YORM_LOGGING_LEVEL))
log.logging.root.handlers[0].setFormatter(formatter)

# Warn about excessive verbosity
if count > _Config.MAX_VERBOSITY:
msg = "Maximum verbosity level is {}".format(_Config.MAX_VERBOSITY)
logging.warning(msg)
log.warning(msg)
_Config.verbosity = _Config.MAX_VERBOSITY
else:
_Config.verbosity = count
Expand All @@ -115,7 +113,12 @@ def newline():
show("")


def show(*messages, file=sys.stdout, log=_log, **kwargs):
def show(
*messages,
file=sys.stdout,
log=log, # pylint: disable=redefined-outer-name
**kwargs,
):
"""Write to standard output or error if enabled."""
if any(messages):
assert 'color' in kwargs, "Color is required"
Expand Down
6 changes: 2 additions & 4 deletions gitman/git.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"""Utilities to call Git commands."""

import logging
import os
import re
import shutil
from contextlib import suppress

import log

from . import common, settings
from .exceptions import ShellError
from .shell import call, pwd


log = logging.getLogger(__name__)


def git(*args, **kwargs):
return call('git', *args, **kwargs)

Expand Down
5 changes: 1 addition & 4 deletions gitman/models/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
from typing import List

import log
import yorm
from yorm.types import SortedList, String

Expand All @@ -10,9 +10,6 @@
from .source import Source


log = logging.getLogger(__name__)


@yorm.attr(location=String)
@yorm.attr(sources=SortedList.of_type(Source))
@yorm.attr(sources_locked=SortedList.of_type(Source))
Expand Down
5 changes: 0 additions & 5 deletions gitman/models/group.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import logging

import yorm
from yorm.types import AttributeDictionary, List, String

from .. import exceptions


log = logging.getLogger(__name__)


@yorm.attr(name=String)
@yorm.attr(members=List.of_type(String))
class Group(AttributeDictionary):
Expand Down
7 changes: 2 additions & 5 deletions gitman/models/source.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import logging
import os

import log
import yorm
from yorm.types import AttributeDictionary, List, NullableString, String

from .. import common, exceptions, git, shell


log = logging.getLogger(__name__)


@yorm.attr(name=String)
@yorm.attr(type=String)
@yorm.attr(repo=String)
Expand Down Expand Up @@ -274,7 +271,7 @@ def lock(self, rev=None, allow_dirty=False, skip_changes=False):
def _invalid_repository(self):
path = os.path.join(os.getcwd(), self.name)
msg = """

Not a valid repository: {}
During install you can rebuild a repo with a missing .git directory using the --force option
""".format(
Expand Down
3 changes: 0 additions & 3 deletions gitman/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Plugin for Git."""

import argparse
import logging

from . import __version__, common
from .cli import _get_command, _run_command
Expand All @@ -12,8 +11,6 @@
PROG = 'git deps'
DESCRIPTION = "Use GitMan (v{}) to install repositories.".format(__version__)

log = logging.getLogger(__name__)


def main(args=None):
"""Process command-line arguments and run the Git plugin."""
Expand Down
15 changes: 8 additions & 7 deletions gitman/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Program defaults."""

import logging
import os

import log


# Cache settings
CACHE = os.path.expanduser(os.getenv('GITMAN_CACHE', "~/.gitcache"))
Expand All @@ -13,12 +14,12 @@
LEVELED_LOGGING_FORMAT = "%(levelname)s: %(message)s"
VERBOSE_LOGGING_FORMAT = "[%(levelname)-8s] %(message)s"
VERBOSE2_LOGGING_FORMAT = "[%(levelname)-8s] (%(name)s @%(lineno)4d) %(message)s"
QUIET_LOGGING_LEVEL = logging.ERROR
DEFAULT_LOGGING_LEVEL = logging.WARNING
VERBOSE_LOGGING_LEVEL = logging.INFO
VERBOSE2_LOGGING_LEVEL = logging.DEBUG
QUIET_LOGGING_LEVEL = log.ERROR
DEFAULT_LOGGING_LEVEL = log.WARNING
VERBOSE_LOGGING_LEVEL = log.INFO
VERBOSE2_LOGGING_LEVEL = log.DEBUG
LOGGING_DATEFMT = "%Y-%m-%d %H:%M"

# 3rd party settings
YORM_LOGGING_LEVEL = logging.WARNING
SH_LOGGING_LEVEL = logging.WARNING
YORM_LOGGING_LEVEL = log.WARNING
SH_LOGGING_LEVEL = log.WARNING
5 changes: 2 additions & 3 deletions gitman/shell.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Utilities to call shell programs."""

import logging
import os
import subprocess

import log

from . import common
from .exceptions import ShellError


CMD_PREFIX = "$ "
OUT_PREFIX = "> "

log = logging.getLogger(__name__)


def call(name, *args, _show=True, _shell=False, _ignore=False):
"""Call a program with arguments.
Expand Down
4 changes: 1 addition & 3 deletions gitman/system.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Interface to the operating system."""

import logging
import os
import platform
import subprocess


log = logging.getLogger(__name__)
import log


def launch(path):
Expand Down
18 changes: 1 addition & 17 deletions gitman/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unit test configuration file."""

import logging
import os

import pytest
Expand All @@ -15,23 +14,8 @@


def pytest_configure(config):
"""Conigure logging and silence verbose test runner output."""
logging.basicConfig(
level=logging.DEBUG,
format="[%(levelname)-8s] (%(name)s @%(lineno)4d) %(message)s",
)
logging.getLogger('yorm').setLevel(logging.WARNING)

terminal = config.pluginmanager.getplugin('terminal')

class QuietReporter(terminal.TerminalReporter): # type: ignore
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.verbosity = 0
self.showlongtestinfo = False
self.showfspath = False

terminal.TerminalReporter = QuietReporter
terminal.TerminalReporter.showfspath = False


def pytest_runtest_setup(item):
Expand Down
10 changes: 5 additions & 5 deletions gitman/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pylint: disable=no-self-use,unused-variable,expression-not-assigned

import logging
from unittest.mock import Mock, patch

import log
import pytest
from expecter import expect

Expand Down Expand Up @@ -454,10 +454,10 @@ def describe_logging():
@pytest.mark.parametrize("argument,verbosity", argument_verbosity)
def at_each_level(argument, verbosity):
def function(*args, **kwargs):
logging.debug(args)
logging.debug(kwargs)
logging.warning("warning")
logging.error("error")
log.debug(args)
log.debug(kwargs)
log.warning("warning")
log.error("error")
return True

cli.main([argument] if argument else [], function)
Expand Down
Loading