-
Notifications
You must be signed in to change notification settings - Fork 1
Bugfix/489 fix precommit targets #492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0293297
Fix nox tasks for .pre-commit-config.yaml
ArBridgeman 0489160
Add test to verify generated pyproject.toml passes basic poetry inspe…
ArBridgeman 5342292
Tests should be in one directory type; if it differs for an existing …
ArBridgeman 1100ed3
Bump to exasol-toolbox 1.6.0
ArBridgeman 715d8b8
Add isolated test to run pre-commit hooks to ensure they work
ArBridgeman a4560dc
Update dependencies
ArBridgeman a122405
Test clean up
ArBridgeman e53c673
Switch author_full_name and author_email to be default
ArBridgeman e171d67
Add comment to make clear why env is separately set
ArBridgeman 1b88520
Add cookiecutter as a dev dependency in the PTB
ArBridgeman cba87c3
Remove install as pre-commit included in PTB dependencies
ArBridgeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"}, | ||
ArBridgeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.