Skip to content

Commit

Permalink
Split into gitlint and gitlint-core to allow unpinning requirements
Browse files Browse the repository at this point in the history
gitlint’s pinned requirements make it difficult to use with other
libraries and tools that have newer requirements, and may hold back
important security updates.  However, the maintainer prefers to expose
pinned requirements by default.

Reconcile this by splitting gitlint into two packages:

* gitlint-core has unpinned requirements by default, but pinned
  requirements with the [trusted-deps] extra.
* gitlint becomes an empty package that requires
  gitlint-core[trusted-deps].

Fixes jorisroovers#162.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Nov 14, 2021
1 parent a8b178c commit 50ef92c
Show file tree
Hide file tree
Showing 121 changed files with 146 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ fail_under = 97

[run]
branch = true
omit=*dist-packages*,*site-packages*,gitlint/tests/*,.venv/*,*virtualenv*
omit=*dist-packages*,*site-packages*,gitlint-core/gitlint/tests/*,.venv/*,*virtualenv*
10 changes: 5 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ jobs:
run: gitlint --version

- name: Tests (sanity)
run: tools\windows\run_tests.bat "gitlint\tests\cli\test_cli.py::CLITests::test_lint"
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py::CLITests::test_lint"

- name: Tests (ignore cli\*)
run: pytest --ignore gitlint\tests\cli -rw -s gitlint
run: pytest --ignore gitlint-core\gitlint\tests\cli -rw -s gitlint-core

- name: Tests (test_cli.py only - continue-on-error:true)
run: tools\windows\run_tests.bat "gitlint\tests\cli\test_cli.py"
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py"
continue-on-error: true # Known to fail at this point

- name: Tests (all - continue-on-error:true)
Expand All @@ -127,10 +127,10 @@ jobs:
continue-on-error: true # Known to fail at this point

- name: PEP8
run: flake8 gitlint qa examples
run: flake8 gitlint-core qa examples

- name: PyLint
run: pylint gitlint qa --rcfile=".pylintrc" -r n
run: pylint gitlint-core\gitlint qa --rcfile=".pylintrc" -r n

# Re-add git version control so we can run gitlint on itself.
- name: Re-add git version control to code
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- id: gitlint
name: gitlint
language: python
additional_dependencies: ["./gitlint-core[trusted-deps]"]
entry: gitlint
args: [--staged, --msg-filename]
stages: [commit-msg]
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ include LICENSE
exclude Vagrantfile
exclude *.yml *.sh *.txt
recursive-exclude examples *
recursive-exclude gitlint/tests *
recursive-exclude qa *
recursive-exclude gitlint-core *
recursive-exclude qa *
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ignore-merge-commits=false
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly
# reference it in the commit message.
files=gitlint/rules.py,README.md
files=gitlint-core/gitlint/rules.py,README.md

[body-match-regex]
# python-style regex that the commit-msg body must match.
Expand Down
6 changes: 3 additions & 3 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ that's open to a lot of change and input.

When contributing code, please consider all the parts that are typically required:

- [Unit tests](https://github.com/jorisroovers/gitlint/tree/main/gitlint/tests) (automatically
- [Unit tests](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/tests) (automatically
[enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Please consider writing
new ones for your functionality, not only updating existing ones to make the build pass.
- [Integration tests](https://github.com/jorisroovers/gitlint/tree/main/qa) (also automatically
Expand Down Expand Up @@ -118,8 +118,8 @@ Then, we suggest taking the following approach to add a Contrib rule:

1. **Write your rule as a [user-defined rule](../user_defined_rules)**. In terms of code, Contrib rules are identical to
user-defined rules, they just happen to have their code sit within the gitlint codebase itself.
2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/main/gitlint/contrib/rules) directory.
3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/main/gitlint/tests/contrib/rules).
2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/contrib/rules) directory.
3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/tests/contrib/rules).
4. **Write documentation**. In particular, you should update the [gitlint/docs/contrib_rules.md](https://github.com/jorisroovers/gitlint/blob/main/docs/contrib_rules.md) file with details on your Contrib rule.
5. **Create a Pull Request**: code review typically requires a bit of back and forth. Thanks for your contribution!

Expand Down
4 changes: 2 additions & 2 deletions docs/user_defined_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class ReleaseConfigurationRule(ConfigurationRule):
```

For all available properties and methods on the `config` object, have a look at the
[LintConfig class](https://github.com/jorisroovers/gitlint/blob/main/gitlint/config.py). Please do not use any
[LintConfig class](https://github.com/jorisroovers/gitlint/blob/main/gitlint-core/gitlint/config.py). Please do not use any
properties or methods starting with an underscore, as those are subject to change.


Expand All @@ -385,7 +385,7 @@ As long as you stick with simple rules that are similar to the sample user-defin
should be able to discover and execute them. While clearly you can run any python code you want in your rules,
you might run into some issues if you don't follow the conventions that gitlint requires.

While the [rule finding source-code](https://github.com/jorisroovers/gitlint/blob/main/gitlint/rule_finder.py) is the
While the [rule finding source-code](https://github.com/jorisroovers/gitlint/blob/main/gitlint-core/gitlint/rule_finder.py) is the
ultimate source of truth, here are some of the requirements that gitlint enforces.

### Rule class requirements
Expand Down
2 changes: 1 addition & 1 deletion examples/gitlint
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ ignore-merge-commits=false
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
files=gitlint/rules.py,README.md
files=gitlint-core/gitlint/rules.py,README.md
1 change: 1 addition & 0 deletions gitlint-core/LICENSE
3 changes: 3 additions & 0 deletions gitlint-core/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include README.md
include LICENSE
recursive-exclude gitlint/tests *
1 change: 1 addition & 0 deletions gitlint-core/README.md
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
# files=gitlint/rules.py,README.md
# files=gitlint-core/gitlint/rules.py,README.md

# [body-match-regex]
# python-style regex that the commit-msg body must match.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions gitlint-core/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
107 changes: 107 additions & 0 deletions gitlint-core/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, find_packages
import io
import re
import os
import platform
import sys


description = "Git commit message linter written in python, checks your commit messages for style."
long_description = """
Great for use as a commit-msg git hook or as part of your gating script in a CI pipeline (e.g. jenkins, github actions).
Many of the gitlint validations are based on `well-known`_ community_ `standards`_, others are based on checks that
we've found useful throughout the years. Gitlint has sane defaults, but you can also easily customize it to your
own liking.
Demo and full documentation on `jorisroovers.github.io/gitlint`_.
To see what's new in the latest release, visit the CHANGELOG_.
Source code on `github.com/jorisroovers/gitlint`_.
.. _well-known: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
.. _community: http://addamhardy.com/blog/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks/
.. _standards: http://chris.beams.io/posts/git-commit/
.. _jorisroovers.github.io/gitlint: https://jorisroovers.github.io/gitlint
.. _CHANGELOG: https://github.com/jorisroovers/gitlint/blob/main/CHANGELOG.md
.. _github.com/jorisroovers/gitlint: https://github.com/jorisroovers/gitlint
"""


# shamelessly stolen from mkdocs' setup.py: https://github.com/mkdocs/mkdocs/blob/master/setup.py
def get_version(package):
"""Return package version as listed in `__version__` in `init.py`."""
init_py = io.open(os.path.join(package, '__init__.py'), encoding="UTF-8").read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)


setup(
name="gitlint-core",
version=get_version("gitlint"),
description=description,
long_description=long_description,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Environment :: Console",
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"License :: OSI Approved :: MIT License"
],
python_requires=">=3.6",
install_requires=[
'Click>=8',
'arrow>=1',
'sh>=1.13.0 ; sys_platform != "win32"',
],
extras_require={
'trusted-deps': [
'Click==8.0.3',
'arrow==1.2.1',
'sh==1.14.2 ; sys_platform != "win32"',
],
},
keywords='gitlint git lint',
author='Joris Roovers',
url='https://jorisroovers.github.io/gitlint',
project_urls={
'Documentation': 'https://jorisroovers.github.io/gitlint',
'Source': 'https://github.com/jorisroovers/gitlint',
},
license='MIT',
package_data={
'gitlint': ['files/*']
},
packages=find_packages(exclude=["examples"]),
entry_points={
"console_scripts": [
"gitlint = gitlint.cli:cli",
],
},
)

# Print a red deprecation warning for python < 3.6 users
if sys.version_info[:2] < (3, 6):
msg = "\033[31mDEPRECATION: You're using a python version that has reached end-of-life. " + \
"Gitlint does not support Python < 3.6" + \
"Please upgrade your Python to 3.6 or above.\033[0m"
print(msg)

# Print a warning message for Windows users
PLATFORM_IS_WINDOWS = "windows" in platform.system().lower()
if PLATFORM_IS_WINDOWS:
msg = "\n\n\n\n\n****************\n" + \
"WARNING: Gitlint support for Windows is still experimental and there are some known issues: " + \
"https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows " + \
"\n*******************"
print(msg)
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
setuptools
wheel==0.37.0
Click==8.0.3
sh==1.14.2; sys_platform != 'win32' # sh is not supported on windows
arrow==1.2.1
-e .
-e ./gitlint-core[trusted-deps]
18 changes: 8 additions & 10 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ handle_test_result(){

run_pep8_check(){
# FLAKE 8
target=${testargs:-"gitlint qa examples"}
target=${testargs:-"gitlint-core qa examples"}
echo -ne "Running flake8..."
RESULT=$(flake8 $target)
local exit_code=$?
Expand All @@ -88,7 +88,7 @@ run_unit_tests(){
clean
# py.test -s => print standard output (i.e. show print statement output)
# -rw => print warnings
target=${testargs:-"gitlint"}
target=${testargs:-"gitlint-core"}
coverage run -m pytest -rw -s $target
TEST_RESULT=$?
if [ $include_coverage -eq 1 ]; then
Expand Down Expand Up @@ -129,7 +129,7 @@ run_git_check(){

run_lint_check(){
echo -ne "Running pylint...${RED}"
target=${testargs:-"gitlint qa"}
target=${testargs:-"gitlint-core/gitlint qa"}
RESULT=$(pylint $target --rcfile=".pylintrc" -r n)
local exit_code=$?
handle_test_result $exit_code "$RESULT"
Expand All @@ -149,14 +149,14 @@ run_build_test(){

# Update the version to include a timestamp
echo -n "Writing new version to file..."
version_file="$temp_dir/gitlint/__init__.py"
version_file="$temp_dir/gitlint-core/gitlint/__init__.py"
version_str="$(cat $version_file)"
version_str="${version_str:0:${#version_str}-1}-$datestr\""
echo "$version_str" > $version_file
echo -e "${GREEN}DONE${NO_COLOR}"
# Attempt to build the package
echo "Building package ..."
pushd "$temp_dir"
pushd "$temp_dir/gitlint-core"
# Copy stdout file descriptor so we can both print output to stdout as well as capture it in a variable
# https://stackoverflow.com/questions/12451278/bash-capture-stdout-to-a-variable-but-still-display-it-in-the-console
exec 5>&1
Expand All @@ -183,7 +183,7 @@ run_stats(){
echo "*** Docs ***"
echo " Markdown: $(cat docs/*.md | wc -l | tr -d " ") lines"
echo "*** Tests ***"
nr_unit_tests=$(py.test gitlint/ --collect-only | grep TestCaseFunction | wc -l)
nr_unit_tests=$(py.test gitlint-core/ --collect-only | grep TestCaseFunction | wc -l)
nr_integration_tests=$(py.test qa/ --collect-only | grep TestCaseFunction | wc -l)
echo " Unit Tests: ${nr_unit_tests//[[:space:]]/}"
echo " Integration Tests: ${nr_integration_tests//[[:space:]]/}"
Expand Down Expand Up @@ -212,10 +212,8 @@ run_stats(){

clean(){
echo -n "Cleaning the *.pyc, site/, build/, dist/ and all __pycache__ directories..."
find gitlint -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null
find qa -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null
find gitlint -iname *.pyc -exec rm -rf {} \; 2> /dev/null
find qa -iname *.pyc -exec rm -rf {} \; 2> /dev/null
find gitlint-core qa -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null
find gitlint-core qa -iname "*.pyc" -exec rm -rf {} \; 2> /dev/null
rm -rf "site" "dist" "build"
echo -e "${GREEN}DONE${NO_COLOR}"
}
Expand Down
50 changes: 4 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, find_packages
import io
import re
import os
import platform
import sys

from setuptools import setup

description = "Git commit message linter written in python, checks your commit messages for style."
long_description = """
Expand All @@ -29,16 +23,11 @@
"""


# shamelessly stolen from mkdocs' setup.py: https://github.com/mkdocs/mkdocs/blob/master/setup.py
def get_version(package):
"""Return package version as listed in `__version__` in `init.py`."""
init_py = io.open(os.path.join(package, '__init__.py'), encoding="UTF-8").read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)

version = "0.17.0dev"

setup(
name="gitlint",
version=get_version("gitlint"),
version=version,
description=description,
long_description=long_description,
classifiers=[
Expand All @@ -60,14 +49,8 @@ def get_version(package):
],
python_requires=">=3.6",
install_requires=[
'Click==8.0.3',
'arrow==1.2.1',
'gitlint-core[trusted-deps]==' + version,
],
extras_require={
':sys_platform != "win32"': [
'sh==1.14.2',
],
},
keywords='gitlint git lint',
author='Joris Roovers',
url='https://jorisroovers.github.io/gitlint',
Expand All @@ -76,29 +59,4 @@ def get_version(package):
'Source': 'https://github.com/jorisroovers/gitlint',
},
license='MIT',
package_data={
'gitlint': ['files/*']
},
packages=find_packages(exclude=["examples"]),
entry_points={
"console_scripts": [
"gitlint = gitlint.cli:cli",
],
},
)

# Print a red deprecation warning for python < 3.6 users
if sys.version_info[:2] < (3, 6):
msg = "\033[31mDEPRECATION: You're using a python version that has reached end-of-life. " + \
"Gitlint does not support Python < 3.6" + \
"Please upgrade your Python to 3.6 or above.\033[0m"
print(msg)

# Print a warning message for Windows users
PLATFORM_IS_WINDOWS = "windows" in platform.system().lower()
if PLATFORM_IS_WINDOWS:
msg = "\n\n\n\n\n****************\n" + \
"WARNING: Gitlint support for Windows is still experimental and there are some known issues: " + \
"https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows " + \
"\n*******************"
print(msg)
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ radon==5.1.0
flake8-polyfill==1.0.2 # Required when installing both flake8 and radon>=4.3.1
pytest==6.2.5;
pylint==2.11.1;
-e .
-r requirements.txt

0 comments on commit 50ef92c

Please sign in to comment.