Compare commits
No commits in common. "e156ea4108b2da69e2a833773d876861d058853a" and "a591fe20e89bf33b02f9e8e57bd57770b5a76e4f" have entirely different histories.
e156ea4108
...
a591fe20e8
11 changed files with 525 additions and 640 deletions
|
|
@ -2,7 +2,7 @@ files: ^halig|tests$
|
||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.6.0
|
rev: v4.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
args: [ --markdown-linebreak-ext=md ]
|
args: [ --markdown-linebreak-ext=md ]
|
||||||
|
|
@ -19,14 +19,20 @@ repos:
|
||||||
args: [ --fix=lf ]
|
args: [ --fix=lf ]
|
||||||
|
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
rev: v0.4.4
|
rev: v0.1.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args:
|
args:
|
||||||
- --fix
|
- --fix
|
||||||
- --exit-non-zero-on-fix
|
- --exit-non-zero-on-fix
|
||||||
- id: ruff-format
|
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.11.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
pass_filenames: false
|
||||||
|
args:
|
||||||
|
- "halig"
|
||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ from halig.settings import Settings
|
||||||
|
|
||||||
class ICommand(ABC):
|
class ICommand(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def run(self): ... # pragma: no cover
|
def run(self):
|
||||||
|
... # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand(ICommand):
|
class BaseCommand(ICommand):
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,8 @@ from halig.commands.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
class NotebooksCommand(BaseCommand):
|
class NotebooksCommand(BaseCommand):
|
||||||
def __init__(
|
def __init__(self, max_depth: int | float, *args, **kwargs):
|
||||||
self,
|
|
||||||
max_depth: int | float,
|
|
||||||
include_notes: bool = False,
|
|
||||||
*args,
|
|
||||||
**kwargs,
|
|
||||||
):
|
|
||||||
self.max_depth = max_depth
|
self.max_depth = max_depth
|
||||||
self.include_notes = include_notes
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def build_tree(self, root_path: Path):
|
def build_tree(self, root_path: Path):
|
||||||
|
|
@ -31,7 +24,7 @@ class NotebooksCommand(BaseCommand):
|
||||||
if item.name != ".git":
|
if item.name != ".git":
|
||||||
item_tree_node = current_tree_node.add(item.name)
|
item_tree_node = current_tree_node.add(item.name)
|
||||||
q.append((item, item_tree_node, depth + 1))
|
q.append((item, item_tree_node, depth + 1))
|
||||||
elif self.include_notes and item.name.endswith(".age"):
|
else:
|
||||||
current_tree_node.add(item.name)
|
current_tree_node.add(item.name)
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ time you perform a search, this flag should be set. Afterwards, you should only
|
||||||
when new notes have been added or older ones have been changed, since it's a slow
|
when new notes have been added or older ones have been changed, since it's a slow
|
||||||
operation"""
|
operation"""
|
||||||
OPTION_PLAIN_HELP = "Show the note as plaintext"
|
OPTION_PLAIN_HELP = "Show the note as plaintext"
|
||||||
OPTION_INCLUDE_NODES_HELP = "Include each notebook's notes when listing"
|
|
||||||
# ARGUMENTS
|
# ARGUMENTS
|
||||||
ARGUMENT_EDIT_NOTE_HELP = """A valid, settings-relative path.
|
ARGUMENT_EDIT_NOTE_HELP = """A valid, settings-relative path.
|
||||||
Be aware that valid can also mean implicit notes, that is, pointing to a
|
Be aware that valid can also mean implicit notes, that is, pointing to a
|
||||||
|
|
|
||||||
|
|
@ -52,17 +52,12 @@ def notebooks(
|
||||||
"-l",
|
"-l",
|
||||||
help=literals.OPTION_LEVEL_HELP,
|
help=literals.OPTION_LEVEL_HELP,
|
||||||
),
|
),
|
||||||
include_notes: bool = Option(False, help=literals.OPTION_INCLUDE_NODES_HELP),
|
|
||||||
config: Optional[Path] = config_option, # noqa: UP007
|
config: Optional[Path] = config_option, # noqa: UP007
|
||||||
):
|
):
|
||||||
if level < 0:
|
if level < 0:
|
||||||
level = float("inf") # type: ignore[assignment]
|
level = float("inf") # type: ignore[assignment]
|
||||||
settings = load_from_file(config)
|
settings = load_from_file(config)
|
||||||
command = NotebooksCommand(
|
command = NotebooksCommand(settings=settings, max_depth=level)
|
||||||
settings=settings,
|
|
||||||
max_depth=level,
|
|
||||||
include_notes=include_notes,
|
|
||||||
)
|
|
||||||
command.run()
|
command.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from rich import print
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
tz = local_timezone()
|
tz = local_timezone()
|
||||||
return pendulum.now(tz) # type: ignore[reportArgumentType]
|
return pendulum.now(tz)
|
||||||
|
|
||||||
|
|
||||||
def capture(fn: Callable):
|
def capture(fn: Callable):
|
||||||
|
|
@ -24,7 +24,7 @@ def capture(fn: Callable):
|
||||||
print(f"[red]{exc}")
|
print(f"[red]{exc}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
print(f"[bold red] Unexpected error: {exc}")
|
print(f"[beld red] Unexpected error: {exc}")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,8 @@ mock_use_standalone_module = true
|
||||||
[tool.pyright]
|
[tool.pyright]
|
||||||
reportMissingImports = false
|
reportMissingImports = false
|
||||||
reportMissingTypeStubs = false
|
reportMissingTypeStubs = false
|
||||||
reportAttributeAccessIssue = false
|
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff]
|
||||||
extend-select = ["W", "C90", "I", "N", "UP", "S", "BLE", "B", "A", "COM", "C4", "DTZ", "T10", "EM", "ISC", "T20", "PT", "RSE", "RET", "SIM", "PTH", "ERA", "PGH", "PL", "TRY", "RUF"]
|
extend-select = ["W", "C90", "I", "N", "UP", "S", "BLE", "B", "A", "COM", "C4", "DTZ", "T10", "EM", "ISC", "T20", "PT", "RSE", "RET", "SIM", "PTH", "ERA", "PGH", "PL", "TRY", "RUF"]
|
||||||
extend-ignore = ["S101", "ISC002"]
|
extend-ignore = ["S101", "ISC002"]
|
||||||
|
|
||||||
|
|
@ -96,7 +95,6 @@ extend-ignore = ["S101", "ISC002"]
|
||||||
python_version = "3.11"
|
python_version = "3.11"
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unused_configs = true
|
warn_unused_configs = true
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
[[tool.mypy.overrides]]
|
||||||
module = [
|
module = [
|
||||||
"pyrage",
|
"pyrage",
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,12 @@ def test_build_tree_max_depth_2(notes, notebooks_command: NotebooksCommand):
|
||||||
work = tree.children[1]
|
work = tree.children[1]
|
||||||
assert personal.label == "Personal"
|
assert personal.label == "Personal"
|
||||||
assert work.label == "Work"
|
assert work.label == "Work"
|
||||||
assert len(work.children) == 1
|
assert len(work.children) == 2
|
||||||
assert len(personal.children) == 0
|
assert len(personal.children) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_build_tree_max_depth_inf(notes, settings):
|
def test_build_tree_max_depth_inf(notes, notebooks_command: NotebooksCommand):
|
||||||
tree = NotebooksCommand(max_depth=float("inf"), settings=settings, include_notes=True).build_tree(
|
tree = notebooks_command.build_tree(notebooks_command.settings.notebooks_root_path)
|
||||||
settings.notebooks_root_path
|
|
||||||
)
|
|
||||||
personal = tree.children[0]
|
personal = tree.children[0]
|
||||||
work = tree.children[1]
|
work = tree.children[1]
|
||||||
assert personal.label == "Personal"
|
assert personal.label == "Personal"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from halig import utils
|
|
||||||
from halig.commands.reencrypt import ReencryptCommand
|
from halig.commands.reencrypt import ReencryptCommand
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,11 +14,3 @@ def test_reencrypt(reencrypt_command):
|
||||||
for note_path in reencrypt_command.traverse():
|
for note_path in reencrypt_command.traverse():
|
||||||
with note_path.open("rb") as f:
|
with note_path.open("rb") as f:
|
||||||
assert reencrypt_command.encryptor.decrypt(f.read()) == b""
|
assert reencrypt_command.encryptor.decrypt(f.read()) == b""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("current_daily")
|
|
||||||
def test_reencrypt_warns_no_matching_key(reencrypt_command, halig_ssh_path, capfd):
|
|
||||||
reencrypt_command.encryptor.identities = []
|
|
||||||
reencrypt_command.run()
|
|
||||||
out, _ = capfd.readouterr()
|
|
||||||
assert f'because no matching keys were found, skipping ...' in out
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,22 @@ def ssh_recipient(halig_ssh_public_key: str) -> Recipient:
|
||||||
return Recipient.from_str(halig_ssh_public_key)
|
return Recipient.from_str(halig_ssh_public_key)
|
||||||
|
|
||||||
|
|
||||||
|
# @pytest.fixture()
|
||||||
|
# def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
||||||
|
# fs.add_real_paths(["/etc/localtime"])
|
||||||
|
# ssh_path = Path("~/.ssh").expanduser()
|
||||||
|
# ssh_path.mkdir(parents=True)
|
||||||
|
#
|
||||||
|
# with (ssh_path / "id_ed25519").open("w") as f:
|
||||||
|
# f.write(halig_ssh_private_key)
|
||||||
|
#
|
||||||
|
# with (ssh_path / "id_ed25519.pub").open("w") as f:
|
||||||
|
# f.write(halig_ssh_public_key)
|
||||||
|
#
|
||||||
|
# halig_path = Path("~/.config/halig").expanduser()
|
||||||
|
# halig_path.mkdir(parents=True)
|
||||||
|
# return halig_path
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def halig_ssh_path(tmp_path: Path, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
def halig_ssh_path(tmp_path: Path, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
||||||
ssh_path = tmp_path / ".ssh"
|
ssh_path = tmp_path / ".ssh"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue