Skip to content

Commit

Permalink
Update README, update utils and it's tests, and bump to v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Feb 25, 2024
1 parent cefd079 commit 67f8023
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IDLEAlign
Python IDLE extension to align code by a regular expression

[![Tests](https://github.com/CoolCat467/idlealign/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/CoolCat467/idlemypyextension/actions/workflows/tests.yml)
<!-- BADGIE TIME -->

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/CoolCat467/idlealign/main.svg)](https://results.pre-commit.ci/latest/github/CoolCat467/idlealign/main)
Expand All @@ -10,14 +11,24 @@ Python IDLE extension to align code by a regular expression

<!-- END BADGIE TIME -->

## What does this extension do?
This IDLE extension allows you to align a block of code by a regular
expression selecting the text you would like to have aligned and then
running Format -> Align Selection or `Alt+a` on default.
If `space wrap` is enabled in the dialog that appears, regular expression
match in selected text will have a single space added on both sides. If
disabled, this will not happen. This is very helpful for making large
blocks of assignment statements pretty or for making comments for
your ruff rules in pyproject.toml all match up.

## Installation (Without root permissions)
1) Go to terminal and install with `pip install idlealign[user]`.
2) Run command `idleuserextend; idlealign`. You should see the following
output: `Config should be good! Config should be good!`.
3) Open IDLE, go to `Options` -> `Configure IDLE` -> `Extensions`.
If everything went well, alongside `ZzDummy` there should be and
option called `idlealign`. This is where you can configure how
idlealign works.
option called `idlealign`. This is where you can configure if
idlealign is enabled or not.

## Installation (Legacy, needs root permission)
1) Go to terminal and install with `pip install idlealign`.
Expand Down
2 changes: 1 addition & 1 deletion src/idlealign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__title__ = "idlealign"
__author__ = "CoolCat467"
__license__ = "GNU General Public License Version 3"
__version__ = "0.1.1"
__version__ = "1.0.0"


from idlealign import utils
Expand Down
12 changes: 8 additions & 4 deletions src/idlealign/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def check_installed(
return False


def get_line_selection(line: int) -> tuple[str, str]:
"""Get selection strings for given line."""
return f"{line}.0", f"{line+1}.0"
def get_line_selection(line: int, length: int = 1) -> tuple[str, str]:
"""Get selection strings for given line(s)."""
return f"{line}.0", f"{line+length}.0"


# Stolen from idlelib.searchengine
Expand Down Expand Up @@ -423,7 +423,11 @@ def reload(cls) -> None:
)
setattr(cls, key, value)

def get_line(self, line: int, text_win: Text | None = None) -> str:
def get_line(
self,
line: int,
text_win: Text | None = None,
) -> str:
"""Get the characters from the given line in currently open file."""
if text_win is None:
text_win = self.text
Expand Down
17 changes: 13 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def test_get_required_config() -> None:
)


def test_get_line_selection() -> None:
assert utils.get_line_selection(3) == ("3.0", "4.0")
assert utils.get_line_selection(3, 3) == ("3.0", "6.0")


@pytest.mark.parametrize(
("line", "expected"),
[
Expand All @@ -44,10 +49,6 @@ def test_get_line_col_success(line: str, expected: tuple[int, int]) -> None:
assert utils.get_line_col(line) == expected


def test_get_line_selection() -> None:
assert utils.get_line_selection(3) == ("3.0", "4.0")


@pytest.mark.parametrize(
"line",
[
Expand All @@ -65,6 +66,14 @@ def test_get_line_col_failure(line: str) -> None:
utils.get_line_col(line)


@pytest.mark.parametrize(
("index", "offset", "expect"),
[("3.14", 0, "3.0"), ("3.14", 1, "4.0"), ("2981.23", -1, "2980.0")],
)
def test_get_whole_line(index: str, offset: int, expect: str) -> None:
assert utils.get_whole_line(index, offset) == expect


@pytest.mark.parametrize(
("text", "expect"),
[(" waf", 2), ("cat", 0), (" fish", 5), (" ", 3), ("", 0)],
Expand Down

0 comments on commit 67f8023

Please sign in to comment.