Skip to content

Commit

Permalink
Merge pull request #122 from AstuteSource/pre-commit
Browse files Browse the repository at this point in the history
feat: Enable pre-commit
  • Loading branch information
laurennevill authored Dec 12, 2023
2 parents 61059c9 + 639489f commit 94649d0
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 34 deletions.
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# configuring pre-commit hooks for chasten.
# this ensures users do not commit problematic code
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
files: '\.py$'
- id: check-case-conflict
- id: check-merge-conflict
- id: forbid-submodules
- id: trailing-whitespace

- repo: local
hooks:
- id: fix-linting
files: '\.py$'
entry: poetry run task lint --fix
language: system
name: Fix Linting
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ If the issue already exists, share any helpful information that you have gained

Any changes being made to our program must first be done in a branch or fork. Once you (and your fellow contributors) are done making changes, you may create a pull request (PR) to the [main repository](https://github.com/AstuteSource/chasten).

### Pre-Commit Hooks

Enabling pre-commit hooks on your system will save you from accidentally making
unwanted changes, such as incorrect formatting, committing merge conflicts, etc.

You can enable pre-commit hooks after installing `poetry`:

```sh
poetry install
poetry run task pre-commit-install # this sets up pre-commit hooks
```

Now, when you make commits, our specific checks will run. This will give you
greater confidence that your contributions align with our standards!

### Branches

Branches are one of the possible features of GitHub that you could use to make changes to our project. Learn about branches [here](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches).
Expand Down
2 changes: 1 addition & 1 deletion chasten/configApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class config_App(App):
color: black;
}
"""
Check: ClassVar = ["", "1", False] # noqa: RUF012
Check: ClassVar = ["", "1", False]
Valid: bool = False

def on_input_changed(self, event: Input.Changed) -> None:
Expand Down
18 changes: 9 additions & 9 deletions chasten/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setup(

def print_diagnostics(verbose: bool, **configurations: Any) -> None:
"""Display all variables input to the function."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
# display diagnostic information for each configuration keyword argument
if verbose:
console.print(":sparkles: Configured with these parameters:")
Expand All @@ -53,7 +53,7 @@ def print_diagnostics(verbose: bool, **configurations: Any) -> None:

def opt_print_log(verbose: bool, **contents: Any) -> None:
"""Produce logging information and only print when not verbose."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
# iterate through each of the configuration keyword arguments
for current in contents:
# print the name and the value of the keyword argument
Expand All @@ -66,7 +66,7 @@ def opt_print_log(verbose: bool, **contents: Any) -> None:

def print_header() -> None:
"""Display tool details in the header."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
console.print()
console.print(
constants.chasten.Emoji + constants.markers.Space + constants.chasten.Tagline
Expand All @@ -76,29 +76,29 @@ def print_header() -> None:

def print_server() -> None:
"""Display server details in the header."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
console.print(constants.output.Syslog)
console.print()


def print_test_start() -> None:
"""Display details about the test run."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
console.print(constants.output.Test_Start)
console.print()


def print_test_finish() -> None:
"""Display details about the test run."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
console.print()
console.print(":sparkles: Finished running test suite for the specified program")
console.print()


def print_footer() -> None:
"""Display concluding details in the footer."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
console.print()


Expand Down Expand Up @@ -136,7 +136,7 @@ def shorten_file_name(file_name: str, max_length: int) -> str:

def print_list_contents(container: List[Path]) -> None:
"""Display the contents of the list in an easy-to-read fashion."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
# group all of the files by the directory that contains them;
# note that this is important because the contain can contain
# paths that specify files in different directories
Expand All @@ -159,7 +159,7 @@ def print_list_contents(container: List[Path]) -> None:

def print_analysis_details(chasten: results.Chasten, verbose: bool = False) -> None:
"""Print all of the verbose debugging details for the results of an analysis."""
global console # noqa: disable=PLW0603
global console # noqa: PLW0602
# 1) Note: see the BaseModel definitions in results.py for more details
# about the objects and their relationships
# 2) Note: the _match object that is inside of a Match BaseModel subclass
Expand Down
4 changes: 2 additions & 2 deletions chasten/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SyslogUDPHandler(socketserver.BaseRequestHandler):

def handle(self):
"""Receive a message and then display it in output and log it to a file."""
global logger # noqa: disable=PLW0603
global logger # noqa: PLW0602
# receive the message from the syslog logging client
message = bytes.decode(
self.request[0].strip(), encoding=constants.server.Utf8_Encoding
Expand All @@ -38,7 +38,7 @@ def handle(self):

def start_syslog_server():
"""Start a syslog server."""
global logger # noqa: disable=PLW0603
global logger # noqa: PLW0602
# always log all of the messages to a file
logger.setLevel(logging.DEBUG)
# create a RotatingFileHandler such that:
Expand Down
147 changes: 126 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ numpy = "^1.25.2"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
black = "^23.3.0"
ruff = "^0.0.277"
ruff = "^0.1.7"
taskipy = "^1.11.0"
mypy = "^1.4.1"
isort = "^5.12.0"
Expand All @@ -53,6 +53,7 @@ types-pyyaml = "^6.0.12.10"
types-jsonschema = "^4.17.0.9"
types-requests = "^2.31.0.10"
hypothesis-jsonschema = "^0.22.1"
pre-commit = "^3.5.0"
pytest-clarity = "^1.0.1"
pytest-randomly = "^3.13.0"
pytest-pretty = "^1.2.0"
Expand Down Expand Up @@ -119,6 +120,7 @@ test-api = { cmd = "{openai-test}", help = "Run openai powered test cases", use_
not-openai-test = { cmd = "{not-openai-test}", help = "Run openai powered test cases", use_vars = true }
test-coverage = { cmd = "{coverage-test-command}", help = "Run coverage monitoring for the test suite", use_vars = true }
test-coverage-silent = { cmd = "{coverage-test-command-silent}", help = "Run coverage monitoring for tests without output", use_vars = true }
pre-commit-install = { cmd = "pre-commit install", help = "Install or update pre-commit hooks" }

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 94649d0

Please sign in to comment.