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

Modernize tests, fix test errors #73

Merged
merged 3 commits into from
Nov 16, 2024
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
17 changes: 7 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ on:
types: [published]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
python-version: ["3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup, Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Checkout
uses: actions/checkout@v4
- name: Setup, Python 3.12
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: "3.12"
architecture: x64
- name: Deploy with Python ${{ matrix.python-version }}
- name: Deploy with Python 3.12
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
run: |
Expand Down
59 changes: 18 additions & 41 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -1,94 +1,71 @@
name: Testing

on:
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Select Python 3.10
uses: actions/setup-python@v2
uses: actions/checkout@v4
- name: Select Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install

- name: Run black formatter check
run: poetry run black --check --diff toml_sort tests

- name: Run docformatter check
run: poetry run docformatter --check --recursive toml_sort tests

- name: Run isort check
run: poetry run isort --check toml_sort tests

- name: Run mypy check
run: poetry run mypy toml_sort

- name: Run pylint
run: poetry run pylint toml_sort tests

- name: Run linting
run: poetry run nox -s lint
- name: Run static type checking
run: poetry run nox -s typecheck
tests:
needs: [lint]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup, Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/checkout@v4
- name: Select Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install

- name: Run Tests
run: poetry run pytest tests

run: poetry run nox -s tests
coverage:
needs: [lint]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Select Python 3.10
uses: actions/setup-python@v2
uses: actions/checkout@v4
- name: Select Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install

- name: Run Coverage
env:
WITH_COVERAGE: true
run: poetry run pytest --cov=toml_sort --cov-report=term-missing tests
run: poetry run nox -s coverage
31 changes: 0 additions & 31 deletions .pre-commit-config.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions .pre-commit-hooks.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.24.0

### Fixed

- Only write to disk if file contents changed

### Removed

- Dropped support for Python 3.7 and 3.8.
- Removed sphinx documentation.

## 0.23.1

### Fixed
Expand Down
77 changes: 42 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
.PHONY: help
help: ## Print this help menu
help: ## Print this help menu
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: require
require: ## Check that prerequisites are installed.
@if ! command -v python3 > /dev/null; then \
printf "\033[1m\033[31mERROR\033[0m: python3 not installed\n" >&2 ; \
exit 1; \
fi
@if ! python3 -c "import sys; sys.exit(sys.version_info < (3,8))"; then \
printf "\033[1m\033[31mERROR\033[0m: python 3.8+ required\n" >&2 ; \
exit 1; \
fi
@if ! command -v poetry > /dev/null; then \
printf "\033[1m\033[31mERROR\033[0m: poetry not installed.\n" >&2 ; \
printf "Please install with 'python3 -mpip install --user poetry'\n" >&2 ; \
exit 1; \
fi

.PHONY: setup
setup: ## Set up the local development environment
setup: require .setup_complete ## Set up the local development environment

.setup_complete: poetry.lock ## Internal helper to run the setup.
poetry install
poetry run pre-commit install
touch .setup_complete

.PHONY: fix
fix: ## Fix all files in-place
poetry run nox -s $@

.PHONY: test
test: ## Run the tests, but only for current Python version
poetry run tox -e py
.PHONY: lint
lint: ## Run linters on all files
poetry run nox -s $@

.PHONY: test-all
test-all: ## Run the tests for all relevant Python version
poetry run tox
.PHONY: typecheck
typecheck: ## Run static type checks
poetry run nox -s $@

.PHONY: tests
tests: ## Run unit tests
poetry run nox -s $@

.PHONY: publish
publish: ## Build & publish the new version
publish: ## Build & publish the new version
poetry build
poetry publish

.PHONY: format
format: ## Autoformat all files in the repo. WARNING: changes files in-place
poetry run black toml_sort tests
poetry run isort toml_sort tests
poetry run docformatter --recursive --in-place toml_sort tests

.PHONY: build-docs
build-docs: docs/autogen-requirements.txt ## Build the Sphinx docs
sphinx-build -M html docs docs/_build

.PHONY: serve-docs
serve-docs: build-docs ## Simple development server for Sphinx docs
@echo "Serving documentation locally."
@echo "Open browser with 'make open-docs'"
@find docs toml_sort | entr -ps "$(MAKE) build-docs"

.PHONY: open-docs
open-docs: ## Open Sphinx docs index in a browser
gio open docs/_build/html/index.html

.PHONY: clean-docs
clean-docs: ## Clean the docs
rm -r docs/_build

docs/autogen-requirements.txt: poetry.lock ## Autogenerate the requirements.txt
poetry export --dev --format requirements.txt --output $@ && git add $@
.PHONY: clean
clean: ## Remove local development environment
if poetry env list | grep -q Activated; then \
poetry env remove python3; \
fi
rm -f .setup_complete
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
[![license](https://img.shields.io/pypi/l/toml-sort.svg)](https://python.org/pypi/toml-sort)
[![image-python-versions](https://img.shields.io/badge/python->=3.7-blue)](https://python.org/pypi/jedi-language-server)
[![image-pypi-downloads](https://pepy.tech/badge/toml-sort)](https://pepy.tech/project/toml-sort)
[![readthedocs-status](https://readthedocs.org/projects/toml-sort/badge/?version=latest)](https://toml-sort.readthedocs.io/en/latest/?badge=latest)

A command line utility to sort and format your toml files.

Read the latest documentation here: <https://toml-sort.readthedocs.io/en/latest/>

## Installation

```bash
Expand Down Expand Up @@ -134,6 +131,7 @@ ignore_case = true
```

### Configuration Overrides

The `pyproject.toml` configuration file also supports configuration overrides, which are not available as command-line arguments. These overrides allow for fine-grained control of sort options for particular keys.

Only the following options can be included in an override:
Expand All @@ -146,7 +144,7 @@ inline_tables = true
inline_arrays = true
```

In the example configuration, `path.to.key` is the key to match. Keys are matched using the [Python fnmatch function](https://docs.python.org/3/library/fnmatch.html), so glob-style wildcards are supported.
In the example configuration, `path.to.key` is the key to match. Keys are matched using the [Python fnmatch function](https://docs.python.org/3/library/fnmatch.html), so glob-style wildcards are supported.

For instance, to disable sorting the table in the following TOML file:

Expand Down Expand Up @@ -325,7 +323,7 @@ make setup
**Run Tests**

```bash
make test
make tests
```

## Written by
Expand Down
4 changes: 0 additions & 4 deletions mypy.ini

This file was deleted.

41 changes: 41 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Configure nox."""

import nox

NOX_SESSION = nox.session(python=False)


@NOX_SESSION
def fix(session: nox.Session):
"""Fix files inplace."""
session.run("ruff", "format", "-s", ".")
session.run("ruff", "check", "-se", "--fix", ".")


@NOX_SESSION
def lint(session: nox.Session):
"""Check file formatting that only have to do with formatting."""
session.run("ruff", "format", "--check", ".")
session.run("ruff", "check", ".")


@NOX_SESSION
def typecheck(session: nox.Session):
session.run("mypy", "toml_sort")


@NOX_SESSION
def tests(session: nox.Session):
session.run("pytest", "tests")


@NOX_SESSION
def coverage(session: nox.Session):
session.run(
"pytest",
"--cov",
"toml_sort",
"--cov-report",
"term-missing",
"tests",
)
Loading
Loading