Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hatch for project management #384

Merged
merged 10 commits into from
Dec 14, 2022
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
1 change: 1 addition & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -x

brew install asdf
brew install hatch
source "$(brew --prefix asdf)/libexec/asdf.sh"

# Install latest python
Expand Down
119 changes: 70 additions & 49 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,58 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Install Hatch
run: python -m pip install hatch==1.6.3

- name: Unit Tests
run: ./run_tests.sh
run: hatch run test:unit-tests

# Coveralls integration doesn't properly work at this point, also see below
# - name: Coveralls
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# run: coveralls
- name: Code formatting (black)
run: hatch run test:format

- name: Code linting (pylint)
run: hatch run test:lint

- name: Integration Tests
run: ./run_tests.sh -i
- name: Integration tests
run: |
hatch run qa:install-local
hatch run qa:integration-tests

# Gitlint no longer uses `sh` by default, but for now we're still supporting the manual enablement of it.
# By setting GITLINT_USE_SH_LIB=1, we test whether this still works.
- name: Integration Tests (GITLINT_USE_SH_LIB=1)
- name: Integration tests (GITLINT_USE_SH_LIB=1)
run: |
hatch run qa:integration-tests
env:
GITLINT_USE_SH_LIB: 1
run: ./run_tests.sh -i

- name: Code formatting (black)
run: ./run_tests.sh -f
- name: Build test (gitlint)
run: |
hatch build
jorisroovers marked this conversation as resolved.
Show resolved Hide resolved
hatch clean

- name: Build test (gitlint-core)
run: |
hatch build
hatch clean
working-directory: ./gitlint-core

- name: Docs build (mkdocs)
run: hatch run docs:build

- name: gitlint --version
run: hatch run dev:gitlint --version

- name: PyLint
run: ./run_tests.sh -l
- name: Hatch run gitlint
run: hatch run dev:gitlint --debug
continue-on-error: true

- name: Build tests
run: ./run_tests.sh --build
# Coveralls integration doesn't properly work at this point, also see below
# - name: Coveralls
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# run: coveralls

# Patch the commit-msg hook to make it work in GH CI
# Specifically, within the commit-msg hook, wrap the invocation of gitlint with `script`

# Coveralls GH Action currently doesn't support current non-LCOV reporting format
# For now, still using Travis for unit test coverage reporting
Expand All @@ -72,7 +91,7 @@ jobs:
# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: Gitlint check
run: ./run_tests.sh -g --debug
run: hatch run dev:gitlint --debug
if: ${{ github.event_name != 'pull_request' }}

windows-checks:
Expand All @@ -85,12 +104,6 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit

# Because gitlint is a tool that uses git itself under the hood, we remove git tracking from the checked out
# code by temporarily renaming the .git directory.
# This is to ensure that the tests don't have a dependency on the version control of gitlint itself.
- name: Temporarily remove git version control from code
run: Rename-Item .git ._git

- name: Setup python
uses: actions/setup-python@v4.3.1
with:
Expand All @@ -100,35 +113,43 @@ jobs:
if: matrix.python-version == '3.10'
run: python -m pip install --upgrade pip

- name: Install requirements
run: |
pip install -r requirements.txt
pip install -r test-requirements.txt

- name: gitlint --version
run: gitlint --version
- name: Install Hatch
run: python -m pip install hatch==1.6.3

- name: Unit Tests
run: pytest gitlint-core

- name: Integration tests (continue-on-error:true)
run: pytest -rw -s qa
continue-on-error: true # Known to fail at this point
run: hatch run test:unit-tests

- name: Code formatting (black)
run: black .
run: hatch run test:format

- name: Code linting (pylint)
run: hatch run test:lint

- name: PyLint
run: pylint gitlint-core\gitlint qa --rcfile=".pylintrc" -r n
- name: Build test (gitlint)
run: |
hatch build
hatch clean

- name: Build test (gitlint-core)
run: |
hatch build
hatch clean
working-directory: ./gitlint-core

- name: Docs build (mkdocs)
run: hatch run docs:build

- name: Hatch run gitlint
run: hatch run gitlint --debug
continue-on-error: true

# Re-add git version control so we can run gitlint on itself.
- name: Re-add git version control to code
run: Rename-Item ._git .git
- name: gitlint --version
run: hatch run dev:gitlint --version

# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: Gitlint check
run: gitlint --debug
run: hatch run dev:gitlint --debug
if: ${{ github.event_name != 'pull_request' }}

check: # This job does nothing and is only used for the branch protection
Expand Down
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

27 changes: 7 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
# gitlint: [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) #
# gitlint-core

[![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)
[![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)
Gitlint consists of 2 python packages: [gitlint](https://pypi.org/project/gitlint/)
and [gitlint-core](https://pypi.org/project/gitlint-core/).

Git commit message linter written in python (for Linux and Mac, experimental on Windows), checks your commit messages for style.
The `gitlint` package is just a wrapper package around `gitlint-core[trusted-deps]` which strictly pins gitlint
dependencies to known working versions.

**See [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) for full documentation.**

<a href="http://jorisroovers.github.io/gitlint/" target="_blank">
<img src="docs/images/readme-gitlint.png" />
</a>

## 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).
There are scenarios where users (or OS package managers) may want looser dependency requirements.
In these cases, users can just install `gitlint-core` directly (`pip install gitlint-core`).
1 change: 0 additions & 1 deletion doc-requirements.txt

This file was deleted.

75 changes: 38 additions & 37 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ in mind before you spend the effort. Thanks!
or months before merged code actually gets released - we know that can be frustrating but please understand it's
a well-considered trade-off based on available time.

## Local setup
## Environment setup
### Local setup

To install gitlint for local development:
Gitlint uses [hatch](https://hatch.pypa.io/latest/) for project management.
You do not need to setup a `virtualenv`, hatch will take care of that for you.

```sh
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt -r test-requirements.txt -r doc-requirements.txt
python setup.py develop
pip install hatch
```

## Github Devcontainer
### Github Devcontainer

We provide a devcontainer on github to make it easier to get started with gitlint development using VSCode.

Expand All @@ -59,12 +58,6 @@ To start one, click the plus button under the *Code* dropdown on
![Gitlint Dev Container Instructions](images/dev-container.png)


After setup has finished, you should be able to just activate the virtualenv in the home dir and run the tests:
```sh
. ~/.venv/bin/activate
./run_tests.sh
```

By default we have python 3.11 installed in the dev container, but you can also use [asdf](https://asdf-vm.com/)
(preinstalled) to install additional python versions:

Expand All @@ -83,36 +76,43 @@ asdf list python

## Running tests
```sh
./run_tests.sh # run unit tests and print test coverage
./run_tests.sh gitlint-core/gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test
pytest -k test_body_missing # Alternative way to run a specific test by invoking pytest directly with a keyword expression
./run_tests.sh --no-coverage # run unit tests without test coverage
./run_tests.sh --collect-only --no-coverage # Only collect, don't run unit tests
./run_tests.sh --integration # Run integration tests (requires that you have gitlint installed)
./run_tests.sh --build # Run build tests (=build python package)
./run_tests.sh --format # format checks (black)
./run_tests.sh --stats # print some code stats
./run_tests.sh --git # inception: run gitlint against itself
./run_tests.sh --lint # run pylint checks
./run_tests.sh --all # Run unit, integration, format and gitlint checks
# Gitlint
hatch run dev:gitlint # run the local source copy of gitlint
hatch run dev:gitlint --version # This is just the gitlint binary, any flag will work
hatch run dev:gitlint --debug

# Unit tests
hatch run test:unit-tests # run unit tests
hatch run test:unit-tests gitlint-core/gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test
hatch run test:unit-tests -k test_body_missing_merge_commit # Run a specific tests using a pytest keyword expression
hatch run test:unit-tests-no-cov # run unit tests without test coverage

# Integration tests
hatch run qa:install-local # One-time install: install the local gitlint source copy for integration testing
hatch run qa:integration-tests # Run integration tests

# Formatting check
hatch run test:format # Run formatting checks

# Linting (pylint)
hatch run test:lint # Run pylint
```
## Formatting

We use [black](https://black.readthedocs.io/en/stable/) for code formatting.
To use it, just run black against the code you modified:

```sh
black . # format all python code
black gitlint-core/gitlint/lint.py # format a specific file
hatch run test:black . # format all python code
hatch run test:black gitlint-core/gitlint/lint.py # format a specific file
```

## Documentation
We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from markdown.

To use it:
```sh
pip install -r doc-requirements.txt # install doc requirements
mkdocs serve
hatch run docs:serve
```

Then access the documentation website on [http://localhost:8000]().
Expand All @@ -133,17 +133,18 @@ to split gitlint in 2 packages.

![Gitlint package structure](images/gitlint-packages.png)

### Packaging description

To see the package description in HTML format
To build the packages locally:
```sh
pip install docutils
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
python setup.py --long-description | rst2html.py > output.html
# gitlint
hatch build
hatch clean # cleanup

# gitlint-core
cd gitlint-core
hatch build
hatch clean # cleanup
```


## Tools
We keep a small set of scripts in the `tools/` directory:

Expand Down
3 changes: 0 additions & 3 deletions gitlint-core/MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion gitlint-core/gitlint/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.19.0dev"
__version__ = "0.19.0.dev3"
Loading