Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
Node 24; the v4 and v5 they replace targeted the deprecated Node 20.
- Package metadata lists each supported Python version and macOS, and links
the issue tracker and this changelog.
- `tests/test_rules.py` runs its rules through `samebytes.source` (v0.3.0, a
test extra), the copy the family shares. The import rule now answers on
Python 3.9 instead of skipping there, and async definitions need a
docstring too.

## v0.1.0 (2026-10-20)

Expand Down
5 changes: 3 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ its code is a Windows trap with its reason beside it; README's "Why it looks
the way it does" is the list. Rules:

- **Standard library only, ASCII only, a docstring on every definition.**
`tests/test_rules.py` enforces all three. The supervisor is the one process
that must not fail, so it imports nothing it could lack.
`tests/test_rules.py` enforces all three, through `samebytes.source` (a
test extra). The supervisor is the one process that must not fail, so it
imports nothing it could lack.
- **Never import the app.** It spawns `streamlit run <app>` and watches a
socket; putting the app's imports inside the supervisor is the failure this
design exists to avoid.
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ classifiers = [
dependencies = []

[project.optional-dependencies]
test = ["pytest>=7.0"]
# samebytes is the house-rule checks tests/test_rules.py calls (docs and
# source); test-only, so the package itself still depends on nothing new.
test = ["pytest>=7.0", "samebytes @ git+https://github.com/loggger101/[email protected]"]

[project.urls]
Repository = "https://github.com/loggger101/quietlaunch"
Expand Down
53 changes: 16 additions & 37 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,49 @@
# -*- coding: utf-8 -*-
"""The package's own rules: standard library only, ASCII only, documented."""
"""The package's own rules: standard library only, ASCII only, documented.

The rules are samebytes' (`samebytes.source`), the one copy the repositories
in this family share; what they read is this package's.
"""

import ast
import os
import sys

import pytest
from samebytes import source

import quietlaunch

PKG = os.path.dirname(os.path.abspath(quietlaunch.__file__))
ROOT = os.path.dirname(PKG)
SOURCES = sorted(os.path.join(PKG, f) for f in os.listdir(PKG)
if f.endswith(".py"))


def _tree(path):
"""Parse one package source."""
with open(path, encoding="utf-8") as f:
return ast.parse(f.read(), path)
def test_sources_found():
"""The rules below read real files, not an empty directory."""
assert {os.path.basename(p) for p in SOURCES} >= {"__init__.py", "__main__.py",
"launcher.py"}


@pytest.mark.skipif(sys.version_info < (3, 10),
reason="sys.stdlib_module_names is 3.10+")
@pytest.mark.parametrize("path", SOURCES, ids=os.path.basename)
def test_standard_library_only(path):
"""The supervisor must not fail, so it imports nothing it could lack."""
bad = []
for node in ast.walk(_tree(path)):
if isinstance(node, ast.Import):
names = [a.name for a in node.names]
elif isinstance(node, ast.ImportFrom) and node.level == 0:
names = [node.module]
else:
continue
for name in names:
top = name.split(".")[0]
if top not in sys.stdlib_module_names and top != "__future__":
bad.append(name)
assert not bad
assert source.imports(ROOT, [path])[0] == []


@pytest.mark.parametrize("path", SOURCES, ids=os.path.basename)
def test_ascii_only(path):
"""Windows picks cp1252 for a redirected stdout; nothing here may need more."""
with open(path, "rb") as f:
data = f.read()
bad = [i for i, b in enumerate(data) if b > 127]
assert not bad, "non-ASCII byte at offset %d" % bad[0]
assert source.non_ascii(ROOT, [path]) == ([], 1)


@pytest.mark.parametrize("path", SOURCES, ids=os.path.basename)
def test_every_definition_has_a_docstring(path):
"""The code is mostly Windows traps; a definition without its why gets
"simplified" back into the trap."""
tree = _tree(path)
missing = [n.name for n in ast.walk(tree)
if isinstance(n, (ast.FunctionDef, ast.ClassDef))
and not ast.get_docstring(n)]
assert ast.get_docstring(tree)
assert not missing
bad, n = source.docstrings(ROOT, [path])
assert bad == [] and n >= 1


def test_version_is_the_one_pyproject_reads():
"""pyproject.toml takes its version from `quietlaunch.__version__`."""
root = os.path.dirname(PKG)
with open(os.path.join(root, "pyproject.toml"), encoding="utf-8") as f:
text = f.read()
assert 'version = { attr = "quietlaunch.__version__" }' in text
assert quietlaunch.__version__.count(".") == 2
assert source.version_written_once(ROOT, "quietlaunch") == ([], 1)
Loading