Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ repos:
hooks:
- id: taplo
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
rev: v3.13.0
hooks:
- id: reorder-python-imports
args: [--py37-plus, --add-import, "from __future__ import annotations"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
rev: v0.4.9
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix]
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -31,7 +31,7 @@ repos:
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: [types-all]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"persistent-cache-decorator",
"pyfunctional",
"requests",
"urllib3<2.0.0",
"rich",
"runtool",
"typedfzf",
Expand All @@ -51,7 +52,7 @@ dev = "comma.main:app_main"
',devcon' = "comma.devcon:app_devcon"
',docker' = "comma.docker:app_docker"
',mux' = "comma.misc.tmux:app_mux"
',reflection' = "comma.typer.reflection:_main"
',reflection' = "comma._typer.reflection:_main"
',sh' = "comma.shell_scripts.shell_utils:app_sh"
',sh-script' = "comma.shell_scripts.shell_scripts:app_shell_scripts"

Expand Down
2 changes: 1 addition & 1 deletion src/comma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
else:
logging.basicConfig(
level="DEBUG",
level="INFO",
format="[%(asctime)s] [%(levelname)-7s] [%(module)s] %(filename)s:%(lineno)d %(message)s",
datefmt="%X",
)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/comma/typer/pair2.py → src/comma/_typer/pair2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from typing import NamedTuple
from typing import TypeVar

from comma._typer.pair import Pair
from comma.command import Command
from comma.typer.pair import Pair
from typing_extensions import TypedDict

L = TypeVar("L")
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/comma/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import sys

import typer
from comma._typer.reflection import TyperReflection
from comma.devcon import app_devcon
from comma.docker import app_docker
from comma.misc.tmux import mux
from comma.typer.reflection import TyperReflection
from comma.scratch import app_temp


app_main: typer.Typer = typer.Typer(
Expand All @@ -17,6 +18,7 @@
app_main.command()(mux)
app_main.add_typer(app_docker)
app_main.add_typer(app_devcon)
app_main.add_typer(app_temp)
app_main.add_typer(TyperReflection(app=app_main).get_app())


Expand Down
4 changes: 2 additions & 2 deletions src/comma/misc/dual_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def __enter__(self) -> Self:
"""
self.__stack__ = ExitStack().__enter__()
try:
self.left_writer = self.__stack__.enter_context(open(self.__left__, "w")) # noqa: SIM115
self.right_writer = self.__stack__.enter_context(open(self.__right__, "w")) # noqa: SIM115
self.left_writer = self.__stack__.enter_context(open(self.__left__, "w"))
self.right_writer = self.__stack__.enter_context(open(self.__right__, "w"))
except BaseException:
self.__stack__.close()
raise
Expand Down
66 changes: 66 additions & 0 deletions src/comma/scratch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import annotations

import re
from typing import NamedTuple
from typing import TYPE_CHECKING
from urllib.parse import urljoin

import requests
import typer
from fzf import fzf
from persistent_cache.decorators import persistent_cache
from rich import print

if TYPE_CHECKING:
from collections.abc import Iterable

INDEX_ROOT = "https://pypi.org/simple/"

app_temp: typer.Typer = typer.Typer(
name="temp",
help="temporary commands",
)


@persistent_cache()
def request_url(url: str) -> str:
response = requests.get(url, timeout=5)
return response.text


PATTERN_ATAG = re.compile(r'<a .*href="([^"]*?)".*>(.*?)</a>')


class ATag(NamedTuple):
href: str
text: str
tag: str


def extract_links(response: str, domain: str | None = None) -> Iterable[ATag]:
for find in PATTERN_ATAG.finditer(response):
href, text = find.groups()
yield ATag(urljoin(domain, href), text, find.group(0)) # type:ignore[type-var,arg-type]


@app_temp.command()
def list_projects() -> None:
choice = fzf(
extract_links(request_url(INDEX_ROOT), domain=INDEX_ROOT), #
key=lambda x: x.text, #
)
if choice:
print(f"https://pypi.org/project/{choice.text}/")
print(choice.href)
choice2 = fzf(
extract_links(request_url(choice.href), domain=choice.href), #
key=lambda x: x.text, #
_options={"tac": True},
)
if choice2:
print(choice2.href)
# print(f"{text2} ({href2})")


if __name__ == "__main__":
app_temp()
6 changes: 3 additions & 3 deletions tests/comma_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import gron as gron_pkg
import gum as gum_pkg
import pytest
from comma._typer.reflection import TyperReflection
from comma.main import app_main
from comma.typer.reflection import TyperReflection
from typer.testing import CliRunner

if TYPE_CHECKING:
from collections.abc import Sequence
from collections.abc import Generator
from types import ModuleType
from comma.typer.reflection import TyperNode
from comma._typer.reflection import TyperNode


runner = CliRunner()
Expand All @@ -40,7 +40,7 @@
}


@pytest.mark.parametrize("node", TyperReflection(app=app_main)._traverse_nodes_()) # noqa: SLF001
@pytest.mark.parametrize("node", TyperReflection(app=app_main)._traverse_nodes_())
def test_help(node: TyperNode) -> None:
if node.path in ignore_commands:
return
Expand Down
2 changes: 2 additions & 0 deletions tests/entrypoint_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import shutil
import subprocess
from typing import TYPE_CHECKING

Expand All @@ -22,6 +23,7 @@ def test_help(pair: tuple[str, str]) -> None:
k, v = pair
result = subprocess.run([k, "--help"], check=False, capture_output=True, text=True) # noqa: S603
if result.returncode != 0:
logging.error(shutil.which(k))
logging.error(result.stderr)
msg = f"Error running {k} --help"
raise AssertionError(msg)
Expand Down
78 changes: 0 additions & 78 deletions zfiles/Dockerfile

This file was deleted.