Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1 + removed ruff as main dependency + raises exception on zer…
Browse files Browse the repository at this point in the history
…o targets
Nealium committed Aug 23, 2024
1 parent 53a1afc commit a38fe3c
Showing 14 changed files with 165 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -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}]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -8,4 +8,7 @@ __pycache__
*.pyc
*.cpython-36

# poetry build
dist/
# nix-build
result
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
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -22,6 +22,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
@@ -102,4 +164,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 <neal@joslin.io>"]
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" }
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
@@ -3,7 +3,7 @@
Author: Neal Joslin
Date: 2024-08-17
Email: neal@joslin.io
Description: Wrapper for the `ruff` linter for (neo)vim's quickfix
Description: import entry
"""

from .cli import cli
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: neal@joslin.io
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: neal@joslin.io
@@ -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: neal@joslin.io
Description: Main functionality
Description: Linting and formatting
"""

import re
16 changes: 10 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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:
"""
@@ -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)


@@ -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)
)
@@ -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)


@@ -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)
)
@@ -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
9 changes: 6 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ env_list = type, lint, py{38, 39, 310, 311, 312}
description = run unit tests
allowlist_externals = poetry
commands_pre =
poetry install --no-root --sync --with test
poetry install --no-root --sync --with test -E ruff
commands =
poetry run pytest -vvv {posargs}

@@ -20,8 +20,11 @@ commands =

[testenv:lint]
description = lint source code
deps =
ruff
; deps =
; ruff
; allowlist_externals =
; ruff
; poetry
commands =
ruff check .
ruff format --check .

0 comments on commit a38fe3c

Please sign in to comment.