From dcc28a9a987457acf9e2c8249a9df5e40143eba3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 11 Mar 2023 09:03:07 +0100 Subject: Merging upstream version 0.19.1. Signed-off-by: Daniel Baumann --- gitlint-core/LICENSE | 23 +++- gitlint-core/MANIFEST.in | 3 - gitlint-core/README.md | 27 ++++- gitlint-core/gitlint/__init__.py | 9 +- gitlint-core/gitlint/cache.py | 2 +- gitlint-core/gitlint/cli.py | 70 +++++------ gitlint-core/gitlint/config.py | 35 +++--- .../gitlint/contrib/rules/authors_commit.py | 1 - gitlint-core/gitlint/deprecation.py | 1 - gitlint-core/gitlint/display.py | 14 +-- gitlint-core/gitlint/exception.py | 2 - gitlint-core/gitlint/git.py | 22 ++-- gitlint-core/gitlint/hooks.py | 10 +- gitlint-core/gitlint/lint.py | 4 +- gitlint-core/gitlint/options.py | 3 +- gitlint-core/gitlint/rule_finder.py | 27 ++--- gitlint-core/gitlint/rules.py | 38 +++--- gitlint-core/gitlint/shell.py | 19 ++- gitlint-core/gitlint/tests/base.py | 49 +++++--- gitlint-core/gitlint/tests/cli/test_cli.py | 101 ++++++++++++--- gitlint-core/gitlint/tests/cli/test_cli_hooks.py | 135 ++++++++++----------- gitlint-core/gitlint/tests/config/test_config.py | 12 +- .../gitlint/tests/config/test_config_builder.py | 9 +- .../gitlint/tests/config/test_config_precedence.py | 6 +- .../gitlint/tests/config/test_rule_collection.py | 1 + .../tests/contrib/rules/test_authors_commit.py | 9 +- .../contrib/rules/test_conventional_commit.py | 6 +- .../contrib/rules/test_disallow_cleanup_commits.py | 7 +- .../tests/contrib/rules/test_signedoff_by.py | 7 +- .../gitlint/tests/contrib/test_contrib_rules.py | 4 +- .../tests/expected/cli/test_cli/test_debug_1 | 12 +- .../cli/test_cli/test_input_stream_debug_2 | 3 +- .../cli/test_cli/test_lint_multiple_commits_csv_1 | 8 ++ .../cli/test_cli/test_lint_staged_msg_filename_2 | 6 +- .../expected/cli/test_cli/test_lint_staged_stdin_2 | 6 +- .../tests/expected/cli/test_cli/test_named_rules_2 | 3 +- gitlint-core/gitlint/tests/git/test_git.py | 16 ++- gitlint-core/gitlint/tests/git/test_git_commit.py | 22 ++-- gitlint-core/gitlint/tests/git/test_git_context.py | 4 +- .../gitlint/tests/rules/test_body_rules.py | 6 +- .../tests/rules/test_configuration_rules.py | 26 +++- .../gitlint/tests/rules/test_meta_rules.py | 5 +- gitlint-core/gitlint/tests/rules/test_rules.py | 13 +- .../gitlint/tests/rules/test_title_rules.py | 14 +-- .../gitlint/tests/rules/test_user_rules.py | 23 ++-- .../tests/samples/user_rules/my_commit_rules.py | 4 +- .../samples/user_rules/parent_package/__init__.py | 2 +- gitlint-core/gitlint/tests/test_cache.py | 2 +- gitlint-core/gitlint/tests/test_deprecation.py | 5 +- gitlint-core/gitlint/tests/test_display.py | 5 +- gitlint-core/gitlint/tests/test_hooks.py | 32 ++--- gitlint-core/gitlint/tests/test_lint.py | 7 +- gitlint-core/gitlint/tests/test_options.py | 17 ++- gitlint-core/gitlint/tests/test_utils.py | 4 +- gitlint-core/gitlint/utils.py | 36 +++--- gitlint-core/pyproject.toml | 71 +++++++++++ gitlint-core/setup.cfg | 2 - gitlint-core/setup.py | 109 ----------------- 58 files changed, 616 insertions(+), 503 deletions(-) mode change 120000 => 100644 gitlint-core/LICENSE delete mode 100644 gitlint-core/MANIFEST.in mode change 120000 => 100644 gitlint-core/README.md create mode 100644 gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_multiple_commits_csv_1 create mode 100644 gitlint-core/pyproject.toml delete mode 100644 gitlint-core/setup.cfg delete mode 100644 gitlint-core/setup.py (limited to 'gitlint-core') diff --git a/gitlint-core/LICENSE b/gitlint-core/LICENSE deleted file mode 120000 index ea5b606..0000000 --- a/gitlint-core/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/gitlint-core/LICENSE b/gitlint-core/LICENSE new file mode 100644 index 0000000..122bd28 --- /dev/null +++ b/gitlint-core/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Joris Roovers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/gitlint-core/MANIFEST.in b/gitlint-core/MANIFEST.in deleted file mode 100644 index 375cec1..0000000 --- a/gitlint-core/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include README.md -include LICENSE -recursive-exclude gitlint/tests * diff --git a/gitlint-core/README.md b/gitlint-core/README.md deleted file mode 120000 index 32d46ee..0000000 --- a/gitlint-core/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/gitlint-core/README.md b/gitlint-core/README.md new file mode 100644 index 0000000..dfbbe7f --- /dev/null +++ b/gitlint-core/README.md @@ -0,0 +1,26 @@ +# Gitlint-core + +# gitlint: [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) # + +[![Tests](https://github.com/jorisroovers/gitlint/workflows/Tests%20and%20Checks/badge.svg)](https://github.com/jorisroovers/gitlint/actions?query=workflow%3A%22Tests+and+Checks%22) +[![Coverage Status](https://coveralls.io/repos/github/jorisroovers/gitlint/badge.svg?branch=fix-coveralls)](https://coveralls.io/github/jorisroovers/gitlint?branch=fix-coveralls) +[![PyPi Package](https://img.shields.io/pypi/v/gitlint.png)](https://pypi.python.org/pypi/gitlint) +![Supported Python Versions](https://img.shields.io/pypi/pyversions/gitlint.svg) + +Git commit message linter written in python, checks your commit messages for style. + +**See [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) for full documentation.** + + + + + +## Contributing ## +All contributions are welcome and very much appreciated! + +**I'm [looking for contributors](https://github.com/jorisroovers/gitlint/issues/134) that are interested in taking a more active co-maintainer role as it's becoming increasingly difficult for me to find time to maintain gitlint. Please leave a comment in [#134](https://github.com/jorisroovers/gitlint/issues/134) if you're interested!** + +See [jorisroovers.github.io/gitlint/contributing](http://jorisroovers.github.io/gitlint/contributing) for details on +how to get started - it's easy! + +We maintain a [loose project plan on Github Projects](https://github.com/users/jorisroovers/projects/1/views/1). diff --git a/gitlint-core/gitlint/__init__.py b/gitlint-core/gitlint/__init__.py index ad6b570..a2339fd 100644 --- a/gitlint-core/gitlint/__init__.py +++ b/gitlint-core/gitlint/__init__.py @@ -1 +1,8 @@ -__version__ = "0.19.0dev" +import sys + +if sys.version_info >= (3, 8): + from importlib import metadata # pragma: nocover +else: + import importlib_metadata as metadata # pragma: nocover + +__version__ = metadata.version("gitlint-core") diff --git a/gitlint-core/gitlint/cache.py b/gitlint-core/gitlint/cache.py index b84c904..a3dd0c8 100644 --- a/gitlint-core/gitlint/cache.py +++ b/gitlint-core/gitlint/cache.py @@ -13,7 +13,7 @@ class PropertyCache: return self._cache[cache_key] -def cache(original_func=None, cachekey=None): # pylint: disable=unused-argument +def cache(original_func=None, cachekey=None): """Cache decorator. Caches function return values. Requires the parent class to extend and initialize PropertyCache. Usage: diff --git a/gitlint-core/gitlint/cli.py b/gitlint-core/gitlint/cli.py index 387072e..619f006 100644 --- a/gitlint-core/gitlint/cli.py +++ b/gitlint-core/gitlint/cli.py @@ -1,22 +1,22 @@ -# pylint: disable=bad-option-value,wrong-import-position -# We need to disable the import position checks because of the windows check that we need to do below import copy import logging import os import platform import stat import sys + import click import gitlint -from gitlint.lint import GitLinter +from gitlint import hooks from gitlint.config import LintConfigBuilder, LintConfigError, LintConfigGenerator -from gitlint.deprecation import LOG as DEPRECATED_LOG, DEPRECATED_LOG_FORMAT +from gitlint.deprecation import DEPRECATED_LOG_FORMAT +from gitlint.deprecation import LOG as DEPRECATED_LOG +from gitlint.exception import GitlintError from gitlint.git import GitContext, GitContextError, git_version -from gitlint import hooks +from gitlint.lint import GitLinter from gitlint.shell import shell from gitlint.utils import LOG_FORMAT -from gitlint.exception import GitlintError # Error codes GITLINT_SUCCESS = 0 @@ -40,8 +40,6 @@ LOG = logging.getLogger("gitlint.cli") class GitLintUsageError(GitlintError): """Exception indicating there is an issue with how gitlint is used.""" - pass - def setup_logging(): """Setup gitlint logging""" @@ -49,7 +47,7 @@ def setup_logging(): # Root log, mostly used for debug root_log = logging.getLogger("gitlint") root_log.propagate = False # Don't propagate to child loggers, the gitlint root logger handles everything - root_log.setLevel(logging.ERROR) + root_log.setLevel(logging.WARN) handler = logging.StreamHandler() formatter = logging.Formatter(LOG_FORMAT) handler.setFormatter(formatter) @@ -69,10 +67,11 @@ def log_system_info(): LOG.debug("Git version: %s", git_version()) LOG.debug("Gitlint version: %s", gitlint.__version__) LOG.debug("GITLINT_USE_SH_LIB: %s", os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]")) - LOG.debug("DEFAULT_ENCODING: %s", gitlint.utils.DEFAULT_ENCODING) + LOG.debug("TERMINAL_ENCODING: %s", gitlint.utils.TERMINAL_ENCODING) + LOG.debug("FILE_ENCODING: %s", gitlint.utils.FILE_ENCODING) -def build_config( # pylint: disable=too-many-arguments +def build_config( target, config_path, c, @@ -172,11 +171,9 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec): from_commit_msg = GitContext.from_commit_msg if lint_config.staged: LOG.debug("Fetching additional meta-data from staged commit") - from_commit_msg = ( - lambda message: GitContext.from_staged_commit( # pylint: disable=unnecessary-lambda-assignment - message, lint_config.target - ) - ) + + def from_commit_msg(message): + return GitContext.from_staged_commit(message, lint_config.target) # Order of precedence: # 1. Any data specified via --msg-filename @@ -208,7 +205,7 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec): if refspec: # 3.1.1 Not real refspec, but comma-separated list of commit hashes if "," in refspec: - commit_hashes = [hash.strip() for hash in refspec.split(",")] + commit_hashes = [hash.strip() for hash in refspec.split(",") if hash] return GitContext.from_local_repository(lint_config.target, commit_hashes=commit_hashes) # 3.1.2 Real refspec return GitContext.from_local_repository(lint_config.target, refspec=refspec) @@ -247,43 +244,43 @@ class ContextObj: # fmt: off -@click.group(invoke_without_command=True, context_settings={'max_content_width': 120}, +@click.group(invoke_without_command=True, context_settings={"max_content_width": 120}, epilog="When no COMMAND is specified, gitlint defaults to 'gitlint lint'.") -@click.option('--target', envvar='GITLINT_TARGET', +@click.option("--target", envvar="GITLINT_TARGET", type=click.Path(exists=True, resolve_path=True, file_okay=False, readable=True), help="Path of the target git repository. [default: current working directory]") -@click.option('-C', '--config', envvar='GITLINT_CONFIG', +@click.option("-C", "--config", envvar="GITLINT_CONFIG", type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True), help=f"Config file location [default: {DEFAULT_CONFIG_FILE}]") -@click.option('-c', multiple=True, +@click.option("-c", multiple=True, help="Config flags in format .