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
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ repos:
entry: poetry run -- nox -s project:fix
stages: [ pre-commit ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
stages: [ pre-commit ]
- id: end-of-file-fixer
stages: [ pre-commit ]
- id: trailing-whitespace
stages: [ pre-commit ]

- repo: local
hooks:
- id: type-check
Expand All @@ -40,3 +30,13 @@ repos:
language: system
entry: poetry run -- nox -s lint:code
stages: [ pre-push ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
stages: [ pre-commit ]
- id: end-of-file-fixer
stages: [ pre-commit ]
- id: trailing-whitespace
stages: [ pre-commit ]
4 changes: 4 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Unreleased

## Bugfixes

* #489: Fixed .pre-commit-config.yaml to use existing nox tasks
315 changes: 221 additions & 94 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions project-template/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"pypi_package_name": "exasol-{{cookiecutter.repo_name}}",
"import_package": "exasol.{{cookiecutter.package_name}}",
"description": "",
"author_full_name": "",
"author_email": "",
"author_full_name": "Exasol AG",
"author_email": "opensource@exasol.com",
"project_short_tag": "",
"python_version_min": "3.9",
"license_year": "{% now 'utc', '%Y' %}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default_stages: [ commit ]
default_stages: [ pre-commit, pre-push ]
repos:

- repo: local
Expand All @@ -8,7 +8,8 @@ repos:
types: [ python ]
pass_filenames: false
language: system
entry: poetry run -- nox -s fix
entry: poetry run -- nox -s project:fix
stages: [ pre-commit ]

- repo: local
hooks:
Expand All @@ -17,7 +18,8 @@ repos:
types: [ python ]
pass_filenames: false
language: system
entry: poetry run -- nox -s type-check
entry: poetry run -- nox -s lint:typing
stages: [ pre-push ]

- repo: local
hooks:
Expand All @@ -26,11 +28,15 @@ repos:
types: [ python ]
pass_filenames: false
language: system
entry: poetry run -- nox -s lint
entry: poetry run -- nox -s lint:code
stages: [ pre-push ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-yaml
stages: [ pre-commit ]
- id: end-of-file-fixer
- id: trailing-whitespace
stages: [ pre-commit ]
- id: trailing-whitespace
stages: [ pre-commit ]
3 changes: 1 addition & 2 deletions project-template/{{cookiecutter.repo_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ homepage = "https://github.com/exasol/{{cookiecutter.repo_name}}"
[tool.poetry.dependencies]

[tool.poetry.group.dev.dependencies]
exasol-toolbox = "^1.1.0"
exasol-toolbox = "^1.6.0"

[build-system]
requires = ["poetry-core>=2.0.0"]
Expand Down Expand Up @@ -69,7 +69,6 @@ ignore_errors = true

[[tool.mypy.overrides]]
module = [
"tests.*",
"test.*",
]
ignore_errors = true
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typer = { extras = ["all"], version = ">=0.7.0" }

[tool.poetry.group.dev.dependencies]
autoimport = "^1.4.0"
cookiecutter = "^2.6.0"

[build-system]
requires = ["poetry-core>=2.0.0"]
Expand Down Expand Up @@ -121,4 +122,4 @@ sphinx-multiversion = 'exasol.toolbox.sphinx.multiversion:main'
[tool.sonar]
projectKey = "com.exasol:python-toolbox"
hostUrl = "https://sonarcloud.io"
organization = "exasol"
organization = "exasol"
25 changes: 25 additions & 0 deletions test/integration/project-template/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess

import pytest

from noxconfig import Config


@pytest.fixture(scope="session")
def cwd(tmp_path_factory):
return tmp_path_factory.mktemp("project_template_test")


@pytest.fixture(scope="session")
def new_project(cwd):
project_name = "project"
repo_name = "repo"
package_name = "package"

subprocess.run(
["cookiecutter", Config.root / "project-template", "-o", cwd, "--no-input",
f"project_name={project_name}", f"repo_name={repo_name}",
f"package_name={package_name}",
], capture_output=True, check=True)

return cwd / repo_name
15 changes: 15 additions & 0 deletions test/integration/project-template/poetry_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import subprocess


def test_poetry_check_passes(new_project):
"""
If this tests fails, this indicates that the `pyproject.toml` is not compatible
with the PTB's default poetry version. Note, that this checks only known poetry
attributes, so there could be keys, like `project-abc = 127`, that are present, but,
as they do not have a meaning for poetry, they are ignored.
"""
output = subprocess.run(["poetry", "check"], cwd=new_project,
capture_output=True, text=True)

assert output.stderr == ""
assert output.stdout == "All set!\n"
76 changes: 76 additions & 0 deletions test/integration/project-template/pre_commit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import subprocess
from pathlib import Path

import pytest


@pytest.fixture(scope="module")
def poetry_path() -> str:
result = subprocess.run(["which", "poetry"], capture_output=True, text=True)
poetry_path = result.stdout.strip()
return poetry_path


@pytest.fixture(scope="module")
def git_path() -> str:
result = subprocess.run(["which", "git"], capture_output=True, text=True)
git_path = result.stdout.strip()
return git_path


@pytest.fixture(scope="module")
def run_command(poetry_path, git_path, new_project):
"""
Run subprocess command with captured output and a limited environment (env).

We restrict the environment as different systems & tools (i.e. PyCharm) include
environment variables which may supersede the ones provided here. In such cases,
this can lead to a breaking alteration in the PTB poetry environment. Thus,
we provide the minimum information needed to execute the pre-commit command.
"""

def _run_command_fixture(command, **kwargs):
defaults = {
"capture_output": True,
"check": True,
"cwd": new_project,
"env": {"PATH": f"{Path(git_path).parent}:{Path(poetry_path).parent}"},
"text": True,

}
config = {**defaults, **kwargs}

return subprocess.run(command, **config)

return _run_command_fixture


@pytest.fixture(scope="module")
def pre_commit(run_command, new_project, poetry_path):
run_command(command=["git", "init"])
run_command([poetry_path, "install"])
run_command([poetry_path, "run", "--", "pre-commit", "install"])


class TestPreCommitConfig:
@staticmethod
def _command(poetry_path: str, stage: str) -> list[str]:
return [poetry_path, "run", "--", "pre-commit", "run", "--hook-stage", stage,
"--files",
"exasol/package/version.py"]

def test_stage_pre_commit(self, pre_commit, poetry_path, run_command):
command = self._command(poetry_path, "pre-commit")
output = run_command(command=command, check=False)

assert "Failed" not in output.stdout
assert "Passed" in output.stdout
assert output.returncode == 0

def test_stage_pre_push(self, pre_commit, poetry_path, run_command):
command = self._command(poetry_path, "pre-push")
output = run_command(command=command, check=False)

assert "Failed" not in output.stdout
assert "Passed" in output.stdout
assert output.returncode == 0