Skip to content

Commit

Permalink
Closes #1 + removed ruff as main dependency + raises exception on zer…
Browse files Browse the repository at this point in the history
…o targets
  • Loading branch information
Nealium committed Aug 24, 2024
1 parent 53a1afc commit 8d4e842
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ indent_size = 4
indent_style = space
insert_final_newline = true

[{*.json,*.yml,*.yaml}]
[{*.md,*.yml,*.yaml,*.nix}]
indent_size = 2

[{Makefile,*.mk}]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ jobs:
run: tox -vv --notest
- name: Run test suite
run: tox --skip-pkg-install
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
GITHUB_SHA: $GITHUB_SHA

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ __pycache__
*.pyc
*.cpython-36

# poetry build
dist/
# nix-build
result

# tox / pipeline outputs
coverage.xml
codacy-coverage-reporter
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
all:
poetry run python -m src.ruff_quickfix
run:
poetry run ruff-quickfix

mrun:
python -m src.ruff-quickfix

build:
poetry build

test:
poetry run pytest
Expand Down
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

# ruff-quickfix

[![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
[![Version](https://img.shields.io/pypi/v/ruff-quickfix?style=for-the-badge)](https://pypi.org/project/ruff-quickfix/)
![Python Versions](https://img.shields.io/pypi/pyversions/ruff-quickfix?style=for-the-badge&logo=python&logoColor=white)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=for-the-badge)](https://python-poetry.org/)

![Python 3.8](http://img.shields.io/badge/python-3.8-3776AB.svg)
![Python 3.9](http://img.shields.io/badge/python-3.9-3776AB.svg)
![Python 3.10](http://img.shields.io/badge/python-3.10-3776AB.svg)
![Python 3.11](http://img.shields.io/badge/python-3.11-3776AB.svg)
![Python 3.12](http://img.shields.io/badge/python-3.12-3776AB.svg)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Nealium/ruff-quickfix/tox.yml?style=for-the-badge)
![Codacy grade](https://img.shields.io/codacy/grade/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)
![Codacy coverage](https://img.shields.io/codacy/coverage/604aba9fddc14c739a9148cd71efe5c4?style=for-the-badge)

</div>

Expand All @@ -22,6 +21,68 @@ using an LSP. Also this is an excuse to learn publishing.

![Screenshot](screenshot.png)

## Install

### [pipx](https://github.com/pypa/pipx) *(recommended)*

**Note:** Normal pip works as well, though you should give pipx a try!

* [PyPi](https://pypi.org/project/ruff-quickfix/): `pipx install ruff-quickfix`
* [GitHub](https://github.com/Nealium/ruff-quickfix): `pipx install git+https://github.com/Nealium/ruff-quickfix`
* If you don't already have ruff you include it as an "extra"
* `pipx install ruff-quickfix[ruff]`
* if zsh: `pipx install ruff-quickfix\[ruff\]`

### Source

Clone project: `git clone https://github.com/Nealium/ruff-quickfix.git`

* Pipx: `pipx install .`
* Pip: `pip install .`
* Poetry: `poetry install`
* From Wheel:
* `poetry install`
* `poetry build`
* `pipx install dist/*.whl`

### [Home Manager](https://github.com/nix-community/home-manager) *(nix)*

**Note!** This **will** crash on the first run as the sha256 isn't *real*. Once
it crashes the error message will provide the *actual* sha256 that is required.

1. Insert items into `home.nix`
2. Replace `rev` with the most recent commit's hash
3. Run
4. Replace placeholder `sha256` with actual hash from error message
5. Re-run
6. Validate: `ruff-quickfix --help`

```nix
{ config, pkgs, ... }:
let
# other stuff..
ruff-quickfix = import
(pkgs.fetchFromGitHub
{
owner = "Nealium";
repo = "ruff-quickfix";
# "commit hash" (can be found on GitHub)
rev = "{commit-hash}";
# placeholder hash (replace after 1st run)
sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
) { inherit pkgs; };
in
home.packages = [
# other packages..
ruff-quickfix
]
```

## Config

### Neovim
Expand Down Expand Up @@ -102,4 +163,5 @@ command Pruff call s:ProjectRuffMake()
## Extras

Inside the extras directory you will find files that allow you to easily toggle
between pylint and ruff, as well as a standalone file of ruff-quickfix.
between pylint and ruff. It also contains a standalone file of ruff-quickfix
that doesn't require on [click](https://click.palletsprojects.com)
20 changes: 20 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ pkgs ? import <nixpkgs> {} }:

with pkgs;

python312Packages.buildPythonPackage {
pname = "ruff-quickfix";
version = "0.1.1";
pyproject = true;

src = ./.;

nativeBuildInputs = [
python312Packages.poetry-core
ruff
];

propagatedBuildInputs = with python312Packages; [
click
];
}
7 changes: 5 additions & 2 deletions poetry.lock

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

14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
[tool.poetry]
name = "ruff-quickfix"
version = "0.1.0"
version = "0.1.1"
description = "Wrapper for the `ruff` command for (neo)vim's quickfix"
authors = ["Neal Joslin <[email protected]>"]
readme = "README.md"
license = "LICENSE"
keywords = ["ruff", "cli", "vim", "neovim", "nvim", "quickfix"]
repository = "https://github.com/Nealium/ruff-quickfix"
keywords = ["ruff", "cli", "vim", "neovim", "nvim", "quickfix"]
packages = [
{ include = "ruff_quickfix", from = "src" },
]

[tool.poetry.scripts]
ruff-quickfix = "ruff_quickfix.cli:cli"
ruff-quickfix = "ruff_quickfix:cli"

[tool.poetry.dependencies]
python = "^3.8"
click = "^8.1.7"
ruff = "^0.6.1"
ruff = { version = "^0.6.1", optional = true }

[tool.poetry.extras]
ruff = ["ruff"]

[tool.poetry.group.dev.dependencies]
pre-commit = { version = "^3.8.0", python = "^3.9" }
Expand Down
16 changes: 16 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with import <nixpkgs> { };

mkShell {
name = "ruff-qf-dev";

buildInputs = [
ruff
python312Packages.poetry-core
python312Packages.click
python312Packages.mypy
python312Packages.pytest
python312Packages.pytest-click
python312Packages.pytest-cov
python312Packages.tox
];
}
2 changes: 1 addition & 1 deletion src/ruff_quickfix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Neal Joslin
Date: 2024-08-17
Email: [email protected]
Description: Wrapper for the `ruff` linter for (neo)vim's quickfix
Description: import entry
"""

from .cli import cli
Expand Down
13 changes: 13 additions & 0 deletions src/ruff_quickfix/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
File: ruff_quickfix/__main__.py
Author: Neal Joslin
Date: 2024-08-21
Email: [email protected]
Description: module entry
"""

# TODO (Neal): figure out how to test this line
from . import cli # pragma: no cover

if __name__ == "__main__": # pragma: no cover
cli(obj={})
11 changes: 5 additions & 6 deletions src/ruff_quickfix/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
File: cli
File: ruff_quickfix/cli
Author: Neal Joslin
Date: 2024-08-17
Email: [email protected]
Expand All @@ -10,16 +10,15 @@

import click

from .main import lint
from .lint import lint


@click.command()
@click.argument("targets", nargs=-1)
def cli(targets: list[str]) -> None:
"""Ruff wrapper for (neo)vim's quickfix"""
if not len(targets):
msg = "No targets"
raise click.UsageError(msg)
for path in targets:
lint(path)


if __name__ == "__main__": # pragma: no cover
cli(obj={})
6 changes: 3 additions & 3 deletions src/ruff_quickfix/main.py → src/ruff_quickfix/lint.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
File: ruff_quickfix/main.py
File: ruff_quickfix/lint.py
Author: Neal Joslin
Date: 2024-08-17
Date: 2024-08-21
Email: [email protected]
Description: Main functionality
Description: Linting and formatting
"""

import re
Expand Down
16 changes: 10 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

from click.testing import CliRunner

# Exit code constants
EXIT_SUCCESS = 0
EXIT_MISUSE = 2


def test_cli_file_single(tmp_path: Path, cli_runner: CliRunner) -> None:
"""
Expand All @@ -30,7 +34,7 @@ def test_cli_file_single(tmp_path: Path, cli_runner: CliRunner) -> None:
"""
file_path = create_temp_file(tmp_path, "test.py")
result = cli_runner.invoke(cli, [file_path])
assert result.exit_code == 0
assert result.exit_code == EXIT_SUCCESS
assert result.output == get_file_messages(file_path)


Expand All @@ -45,7 +49,7 @@ def test_cli_file_multiple(tmp_path: Path, cli_runner: CliRunner) -> None:
file_path_0 = create_temp_file(tmp_path, "test0.py")
file_path_1 = create_temp_file(tmp_path, "test1.py")
result = cli_runner.invoke(cli, [file_path_0, file_path_1])
assert result.exit_code == 0
assert result.exit_code == EXIT_SUCCESS
assert result.output == (
get_file_messages(file_path_0) + get_file_messages(file_path_1)
)
Expand All @@ -61,7 +65,7 @@ def test_cli_single_directory(tmp_path: Path, cli_runner: CliRunner) -> None:
"""
file_path = create_temp_file(tmp_path, "test.py")
result = cli_runner.invoke(cli, [str(tmp_path.resolve())])
assert result.exit_code == 0
assert result.exit_code == EXIT_SUCCESS
assert result.output == get_file_messages(file_path)


Expand All @@ -76,7 +80,7 @@ def test_cli_multiple_directory(tmp_path: Path, cli_runner: CliRunner) -> None:
file_path_0 = create_temp_file(tmp_path, "test0.py")
file_path_1 = create_temp_file(tmp_path, "test1.py")
result = cli_runner.invoke(cli, [str(tmp_path.resolve())])
assert result.exit_code == 0
assert result.exit_code == EXIT_SUCCESS
assert result.output == (
get_file_messages(file_path_0) + get_file_messages(file_path_1)
)
Expand All @@ -90,5 +94,5 @@ def test_cli_none(cli_runner: CliRunner) -> None:
cli_runner (CliRunner): click runner
"""
result = cli_runner.invoke(cli)
assert result.exit_code == 0
assert result.output == ""
assert result.exit_code == EXIT_MISUSE
assert "Error: No targets" in result.output
17 changes: 12 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ env_list = type, lint, py{38, 39, 310, 311, 312}

[testenv]
description = run unit tests
allowlist_externals = poetry
allowlist_externals =
poetry
bash
./codacy-coverage-reporter
passenv =
CODACY_PROJECT_TOKEN
GITHUB_SHA
commands_pre =
poetry install --no-root --sync --with test
poetry install --no-root --sync --with test -E ruff
commands =
poetry run pytest -vvv {posargs}
poetry run pytest --cov --cov-report xml --cov-report term -vvv {posargs}
bash -c "curl -Ls -o codacy-coverage-reporter \"$(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | contains(\"codacy-coverage-reporter-linux\"))) | .[0].browser_download_url')\""
bash -c "chmod +x codacy-coverage-reporter"
./codacy-coverage-reporter report -r coverage.xml

[testenv:type]
description = run type checks
Expand All @@ -20,8 +29,6 @@ commands =

[testenv:lint]
description = lint source code
deps =
ruff
commands =
ruff check .
ruff format --check .
Expand Down

0 comments on commit 8d4e842

Please sign in to comment.