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
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on:
push:
pull_request:
# Pushes to this repo's branches already run CI; this covers PRs from forks.
types: [opened, synchronize, reopened]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

# Every job skips PR runs for branches of this repo; their push run already
# reports its checks on the pull request.
jobs:
lint:
name: Lint
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- run: python -m pip install ruff
- name: ruff check
run: ruff check --output-format=github .
- name: ruff format
run: ruff format --check --diff .

test:
name: Test (${{ matrix.os }}, Python ${{ matrix.python }})
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ["3.10", "3.13"]
include:
- os: ubuntu-latest
python: "3.11"
- os: ubuntu-latest
python: "3.12"
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install
run: python -m pip install -e ".[dev]"
- name: Check SQLite FTS5
run: >-
python -c "import sqlite3; print('SQLite', sqlite3.sqlite_version);
sqlite3.connect(':memory:').execute('CREATE VIRTUAL TABLE t USING fts5(x)')"
- name: Run tests
run: python -m pytest -v

build:
name: Build package
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- run: python -m pip install build twine
- name: Build sdist and wheel
run: python -m build
- name: Check metadata
run: python -m twine check --strict dist/*
- name: Smoke-test the wheel
run: |
python -m venv /tmp/wheel-env
/tmp/wheel-env/bin/pip install dist/*.whl
/tmp/wheel-env/bin/markfind --version
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# markfind

[![CI](https://github.com/Alcides1123/markfind/actions/workflows/ci.yml/badge.svg)](https://github.com/Alcides1123/markfind/actions/workflows/ci.yml)

Full-text search over your own browser bookmarks.

Browsers only search bookmark *titles*. markfind downloads the pages you've
Expand Down Expand Up @@ -73,8 +75,13 @@ the `MARKFIND_DB` environment variable.
```sh
python -m pip install -e ".[dev]"
python -m pytest
ruff check . && ruff format --check .
```

Every push runs [CI](.github/workflows/ci.yml): ruff lint and format checks,
the test suite on Linux, Windows and macOS (Python 3.10–3.13), and a package
build with a smoke test of the installed wheel.

Code layout (`src/markfind/`):

- `importers.py` — parses Netscape HTML exports and Chrome JSON
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=69"]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -20,7 +20,7 @@ classifiers = [
]

[project.optional-dependencies]
dev = ["pytest>=8"]
dev = ["pytest>=8", "ruff>=0.15"]

[project.scripts]
markfind = "markfind.cli:main"
Expand All @@ -31,3 +31,11 @@ where = ["src"]
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-q"

[tool.ruff]
line-length = 100
target-version = "py310"

[tool.ruff.lint]
# pycodestyle, pyflakes, isort, bugbear, pyupgrade
select = ["E", "F", "W", "I", "B", "UP"]
4 changes: 3 additions & 1 deletion src/markfind/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def build_parser() -> argparse.ArgumentParser:
p.add_argument("query", nargs="+")
p.add_argument("-n", "--limit", type=int, default=20)
p.add_argument(
"--raw", action="store_true", help="pass the query to SQLite FTS5 unchanged (OR, NEAR, title:...)"
"--raw",
action="store_true",
help="pass the query to SQLite FTS5 unchanged (OR, NEAR, title:...)",
)
p.set_defaults(func=cmd_search)

Expand Down
16 changes: 15 additions & 1 deletion src/markfind/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@

# Elements without an end tag; they can't contain text, so never start a skip.
_VOID = frozenset(
{"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"}
{
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"source",
"track",
"wbr",
}
)

# Main content shorter than this is likely a teaser; use the whole page instead.
Expand Down
15 changes: 12 additions & 3 deletions src/markfind/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def add_bookmarks(self, bookmarks: Iterable[Bookmark]) -> tuple[int, int]:
added = updated = 0
with self.db:
for bm in bookmarks:
row = self.db.execute("SELECT id FROM bookmarks WHERE url = ?", (bm.url,)).fetchone()
row = self.db.execute(
"SELECT id FROM bookmarks WHERE url = ?", (bm.url,)
).fetchone()
if row:
id_ = row[0]
self.db.execute(
Expand All @@ -97,7 +99,12 @@ def add_bookmarks(self, bookmarks: Iterable[Bookmark]) -> tuple[int, int]:
else:
cursor = self.db.execute(
"INSERT INTO bookmarks (url, title, folder, added_at) VALUES (?, ?, ?, ?)",
(bm.url, bm.title, bm.folder, bm.added_at.isoformat() if bm.added_at else None),
(
bm.url,
bm.title,
bm.folder,
bm.added_at.isoformat() if bm.added_at else None,
),
)
id_ = cursor.lastrowid
added += 1
Expand All @@ -106,7 +113,9 @@ def add_bookmarks(self, bookmarks: Iterable[Bookmark]) -> tuple[int, int]:

def _reindex(self, id_: int, body: str | None = None) -> None:
if body is None:
row = self.db.execute("SELECT body FROM bookmarks_fts WHERE rowid = ?", (id_,)).fetchone()
row = self.db.execute(
"SELECT body FROM bookmarks_fts WHERE rowid = ?", (id_,)
).fetchone()
body = row[0] if row else ""
self.db.execute("DELETE FROM bookmarks_fts WHERE rowid = ?", (id_,))
self.db.execute(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_search_title_and_body(store):
Bookmark("https://b.example/", "Untitled", "Dev"),
]
)
(b_id, _), = [p for p in store.pending() if p[1] == "https://b.example/"]
((b_id, _),) = [p for p in store.pending() if p[1] == "https://b.example/"]
store.set_page(b_id, "How to tune SQLite full-text indexes for speed")

assert [r.url for r in store.search("gardening")] == ["https://a.example/"]
Expand All @@ -45,7 +45,7 @@ def test_search_title_and_body(store):

def test_reimport_keeps_page_text(store):
store.add_bookmarks([Bookmark("https://a.example/", "A")])
(id_, _), = store.pending()
((id_, _),) = store.pending()
store.set_page(id_, "kangaroo facts")
store.add_bookmarks([Bookmark("https://a.example/", "A renamed")])

Expand Down
Loading