papers-app 0.3.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {papers_app-0.3.1 → papers_app-0.3.2}/PKG-INFO +2 -2
- {papers_app-0.3.1 → papers_app-0.3.2}/README.md +1 -1
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/__init__.py +1 -1
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/loop.py +1 -2
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/anthropic_api.py +21 -6
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/cli.py +69 -16
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader.js +4 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_cli.py +26 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/.gitignore +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/CONTRIBUTING.md +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/LICENSE +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/__main__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/__init__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/mcp_server.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/tools.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/__init__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/capabilities.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/claude_code.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/codex.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/errors.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/openai_compat.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/providers.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/streaming.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/bibtex.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/__init__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/answer.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/store.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/config.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/db.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/figures.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/folders.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/index.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/ingest.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/keys.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/library.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/llm.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/main.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/notes.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/pdf.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/roadmap.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/__init__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/chat.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/goals.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/learning.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/notes.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/papers.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/reading.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/recall.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/settings.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/scholar.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/setup.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/base.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/chat.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/components.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/goals.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/library.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/map.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/paper.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/reader.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/recall.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/settings.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/tokens.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/welcome.css +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/index.html +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/answer.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/canvas.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/conversation.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/render.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/stream.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/widgets.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/components/combobox.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/components/folderpicker.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/core.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/covers.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/highlights.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/icons.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/main.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/notes.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/goals.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/library.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/map.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/recall.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/settings.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/shared.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/welcome.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/figures.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/overview.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/bar.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/cite.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/finish.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/highlighter.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/keys.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/layout.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/panel.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/progress.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/route.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/selection.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/state.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/terms.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/views.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/vocab.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/zoom.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/review.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/shared.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pdfview.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/readprefs.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/speech.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/textview.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/theme.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/tracker.js +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/storage.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/papers/store.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/pyproject.toml +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/__init__.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/conftest.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_abstract_figures.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_add_link.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_agent.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_agent_actions.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_ai.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_capabilities.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_capture.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_claude_code.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_conversations.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_folders.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_frontend.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_highlights_notes.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_keys.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_learning.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_library_covers.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_library_folder.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_metadata.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_never_stuck.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_notes_ask.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_papers.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_prepare.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_progress.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_prompts.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_provider_list.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_providers.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_recall_refs.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_review.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_roadmap.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_scaffold.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_search.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_setup.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_storage.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_streaming.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_tracker.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_triage.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_upload.py +0 -0
- {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_vocabulary.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: papers-app
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: An AI reading companion for research papers: skim, read, ask, recall. Runs on your computer.
|
|
5
5
|
Project-URL: Homepage, https://github.com/hBouanane/papers
|
|
6
6
|
Project-URL: Issues, https://github.com/hBouanane/papers/issues
|
|
@@ -163,7 +163,7 @@ Then open http://localhost:8000 and choose the AI in Settings. What each part me
|
|
|
163
163
|
| `-d --name papers` | run in the background, named `papers` (`docker stop papers` / `docker start papers`) |
|
|
164
164
|
| `-p 8000:8000` | the app inside listens on port 8000; this makes it http://localhost:8000 on your computer |
|
|
165
165
|
| `-v papers-data:/data` | your library (database, PDFs, figures) lives in `/data` inside the container; this keeps it in a Docker volume called `papers-data`, so it survives updates and restarts. Use a folder instead with `-v ~/Papers-data:/data` |
|
|
166
|
-
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.
|
|
166
|
+
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.2`) |
|
|
167
167
|
|
|
168
168
|
To update: `docker pull ghcr.io/hbouanane/papers:latest`, then `docker rm -f papers` and the same `docker run` again
|
|
169
169
|
(the volume keeps your library). From a clone you can also build it yourself with `docker compose up -d`; see
|
|
@@ -131,7 +131,7 @@ Then open http://localhost:8000 and choose the AI in Settings. What each part me
|
|
|
131
131
|
| `-d --name papers` | run in the background, named `papers` (`docker stop papers` / `docker start papers`) |
|
|
132
132
|
| `-p 8000:8000` | the app inside listens on port 8000; this makes it http://localhost:8000 on your computer |
|
|
133
133
|
| `-v papers-data:/data` | your library (database, PDFs, figures) lives in `/data` inside the container; this keeps it in a Docker volume called `papers-data`, so it survives updates and restarts. Use a folder instead with `-v ~/Papers-data:/data` |
|
|
134
|
-
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.
|
|
134
|
+
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.2`) |
|
|
135
135
|
|
|
136
136
|
To update: `docker pull ghcr.io/hbouanane/papers:latest`, then `docker rm -f papers` and the same `docker run` again
|
|
137
137
|
(the volume keeps your library). From a clone you can also build it yourself with `docker compose up -d`; see
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""Papers: an AI reading companion for research papers."""
|
|
2
|
-
__version__ = "0.3.
|
|
2
|
+
__version__ = "0.3.2"
|
|
@@ -16,7 +16,6 @@ import sys
|
|
|
16
16
|
import tempfile
|
|
17
17
|
from dataclasses import asdict, dataclass
|
|
18
18
|
|
|
19
|
-
import anthropic
|
|
20
19
|
import httpx
|
|
21
20
|
|
|
22
21
|
from papers import config, llm
|
|
@@ -207,7 +206,7 @@ def _anthropic(paper: dict, system: list[dict], messages: list[dict]):
|
|
|
207
206
|
final = stream.get_final_message()
|
|
208
207
|
except TypeError as e:
|
|
209
208
|
raise AIError(anthropic_api.NOT_SET_UP) from e
|
|
210
|
-
except
|
|
209
|
+
except anthropic_api.sdk().APIError as e:
|
|
211
210
|
raise AIError(f"Claude request failed: {e}") from e
|
|
212
211
|
uses = [b for b in final.content if b.type == "tool_use"]
|
|
213
212
|
if final.stop_reason != "tool_use" or not uses:
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
"""The Anthropic API, with a key saved in Settings or ANTHROPIC_API_KEY (pay per use).
|
|
2
|
-
|
|
1
|
+
"""The Anthropic API, with a key saved in Settings or ANTHROPIC_API_KEY (pay per use).
|
|
2
|
+
|
|
3
|
+
The `anthropic` package takes several seconds to import (far longer the first time, before Python has compiled
|
|
4
|
+
it), so it's loaded when it's first used, not when the app starts: most starts never talk to this API at all.
|
|
5
|
+
"""
|
|
3
6
|
from pydantic import BaseModel
|
|
4
7
|
|
|
5
8
|
from papers.ai import providers
|
|
@@ -9,9 +12,21 @@ from papers.ai.streaming import as_messages
|
|
|
9
12
|
NOT_SET_UP = "Claude is not set up. In Settings, choose your Claude subscription, or set ANTHROPIC_API_KEY and restart."
|
|
10
13
|
|
|
11
14
|
|
|
12
|
-
def
|
|
15
|
+
def sdk():
|
|
16
|
+
"""The `anthropic` package, imported on first use."""
|
|
17
|
+
import anthropic
|
|
18
|
+
return anthropic
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __getattr__(name: str): # `anthropic_api.anthropic` still works, for code and tests that reach for it
|
|
22
|
+
if name == "anthropic":
|
|
23
|
+
return sdk()
|
|
24
|
+
raise AttributeError(name)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def client():
|
|
13
28
|
# A key saved in Settings wins; otherwise the SDK uses ANTHROPIC_API_KEY.
|
|
14
|
-
return
|
|
29
|
+
return sdk().Anthropic(api_key=providers.provider_setting("ai_key", "anthropic") or None)
|
|
15
30
|
|
|
16
31
|
|
|
17
32
|
def request(method: str, **kwargs):
|
|
@@ -19,7 +34,7 @@ def request(method: str, **kwargs):
|
|
|
19
34
|
response = getattr(client().messages, method)(model=providers.claude_model(), max_tokens=16000, **kwargs)
|
|
20
35
|
except TypeError as e:
|
|
21
36
|
raise AIError(NOT_SET_UP) from e
|
|
22
|
-
except
|
|
37
|
+
except sdk().APIError as e:
|
|
23
38
|
raise AIError(f"Claude request failed: {e}") from e
|
|
24
39
|
if response.stop_reason == "refusal":
|
|
25
40
|
raise AIError("The model declined this request.")
|
|
@@ -42,7 +57,7 @@ def stream(system: list[dict], content: str | list[dict], effort: str = "medium"
|
|
|
42
57
|
raise AIError("The model declined this request.")
|
|
43
58
|
except TypeError as e:
|
|
44
59
|
raise AIError(NOT_SET_UP) from e
|
|
45
|
-
except
|
|
60
|
+
except sdk().APIError as e:
|
|
46
61
|
raise AIError(f"Claude request failed: {e}") from e
|
|
47
62
|
|
|
48
63
|
|
|
@@ -15,7 +15,10 @@ import socket
|
|
|
15
15
|
import subprocess
|
|
16
16
|
import sys
|
|
17
17
|
import threading
|
|
18
|
+
import time
|
|
19
|
+
import urllib.request
|
|
18
20
|
import webbrowser
|
|
21
|
+
from contextlib import contextmanager
|
|
19
22
|
|
|
20
23
|
from papers import __version__
|
|
21
24
|
|
|
@@ -28,15 +31,38 @@ def port_free(host: str, port: int) -> bool:
|
|
|
28
31
|
GOOD_PYTHON = "3.13" # a released Python every library here supports
|
|
29
32
|
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
@contextmanager
|
|
35
|
+
def working(message: str):
|
|
36
|
+
"""A spinner with a few words while something slow happens, so the terminal never just sits there.
|
|
37
|
+
Loading the libraries takes seconds, and much longer the first time after installing."""
|
|
38
|
+
if not (sys.stdout.isatty() and not os.environ.get("CI")):
|
|
39
|
+
yield
|
|
40
|
+
return
|
|
41
|
+
from rich.console import Console
|
|
42
|
+
with Console().status(f"[dim]{message}[/]", spinner="dots", spinner_style="#6f8cf0"):
|
|
43
|
+
yield
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def python_problem() -> str | None:
|
|
47
|
+
"""Load the app's libraries; the reason, if this Python can't run them (a pre-release, or one too new)."""
|
|
35
48
|
try:
|
|
36
|
-
import
|
|
49
|
+
import pydantic
|
|
50
|
+
|
|
51
|
+
import papers.ai # noqa: F401 (the AI clients and everything they pull in)
|
|
52
|
+
|
|
53
|
+
class Probe(pydantic.BaseModel): # how pydantic reads a written-out type is what breaks first
|
|
54
|
+
value: "str"
|
|
55
|
+
return None
|
|
56
|
+
except Exception as e: # anything: these are other packages' errors
|
|
57
|
+
return f"{type(e).__name__}: {str(e).splitlines()[0] if str(e) else ''}"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def check_python(argv: list[str] | None = None, why: str | None = None) -> None:
|
|
61
|
+
"""On a Python the libraries can't run on, the app would crash halfway through setup. Instead it starts itself
|
|
62
|
+
again on a Python that works, when uv is there to fetch one, or says in one line what to do."""
|
|
63
|
+
why = why or python_problem()
|
|
64
|
+
if not why:
|
|
37
65
|
return
|
|
38
|
-
except Exception as e: # anything: these are other packages' import errors
|
|
39
|
-
why = f"{type(e).__name__}: {str(e).splitlines()[0] if str(e) else ''}"
|
|
40
66
|
version = sys.version.split()[0]
|
|
41
67
|
uvx = shutil.which("uvx")
|
|
42
68
|
if uvx and not os.environ.get("PAPERS_PYTHON_RETRY"): # once: never loop
|
|
@@ -52,6 +78,21 @@ def check_python(argv: list[str] | None = None) -> None:
|
|
|
52
78
|
raise SystemExit(1)
|
|
53
79
|
|
|
54
80
|
|
|
81
|
+
def wait_until_up(host: str, port: int, patience: float = 120) -> bool:
|
|
82
|
+
"""True once the app answers on its port (False after `patience` seconds)."""
|
|
83
|
+
address = f"http://{'127.0.0.1' if host in ('0.0.0.0', '::') else host}:{port}/api/health"
|
|
84
|
+
until = time.monotonic() + patience
|
|
85
|
+
while time.monotonic() < until:
|
|
86
|
+
try:
|
|
87
|
+
with urllib.request.urlopen(address, timeout=2) as answer:
|
|
88
|
+
if answer.status == 200:
|
|
89
|
+
return True
|
|
90
|
+
except OSError:
|
|
91
|
+
pass
|
|
92
|
+
time.sleep(0.25)
|
|
93
|
+
return False
|
|
94
|
+
|
|
95
|
+
|
|
55
96
|
def main(argv: list[str] | None = None) -> None:
|
|
56
97
|
parser = argparse.ArgumentParser(prog="papers", description="An AI reading companion for research papers.")
|
|
57
98
|
parser.add_argument("--port", type=int, default=int(os.environ.get("PAPERS_PORT", 8000)))
|
|
@@ -65,8 +106,12 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
65
106
|
|
|
66
107
|
if args.data:
|
|
67
108
|
os.environ["PAPERS_DATA"] = os.path.abspath(os.path.expanduser(args.data))
|
|
68
|
-
|
|
69
|
-
|
|
109
|
+
with working("Loading Papers…"):
|
|
110
|
+
why = python_problem()
|
|
111
|
+
if not why:
|
|
112
|
+
from papers import config, setup # after PAPERS_DATA is set
|
|
113
|
+
if why:
|
|
114
|
+
check_python(argv, why)
|
|
70
115
|
|
|
71
116
|
if args.command == "setup":
|
|
72
117
|
if not setup.interactive():
|
|
@@ -82,13 +127,21 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
82
127
|
if not port_free(args.host, args.port):
|
|
83
128
|
print(f"Port {args.port} is in use. Is Papers already running? Open {url}, or start with --port 8001.")
|
|
84
129
|
raise SystemExit(1)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
130
|
+
def announce() -> None:
|
|
131
|
+
"""Say where the app is, and open it, once it really answers: a link that leads to an error page is
|
|
132
|
+
worse than a few seconds of "Starting"."""
|
|
133
|
+
with working("Starting Papers…"):
|
|
134
|
+
ready = wait_until_up(args.host, args.port)
|
|
135
|
+
if setup.interactive():
|
|
136
|
+
setup.started(url, config.data_dir().resolve())
|
|
137
|
+
else:
|
|
138
|
+
print(f"Papers {__version__}: your library is in {config.data_dir()}", flush=True)
|
|
139
|
+
print(f"Open {url} (Ctrl+C to stop)", flush=True)
|
|
140
|
+
if not ready:
|
|
141
|
+
print(" It is taking long to start. If the page doesn't open yet, wait a moment and reload it.")
|
|
142
|
+
if not args.no_browser:
|
|
143
|
+
webbrowser.open(url)
|
|
144
|
+
threading.Thread(target=announce, daemon=True).start()
|
|
92
145
|
|
|
93
146
|
import uvicorn
|
|
94
147
|
uvicorn.run("papers.main:app", host=args.host, port=args.port, log_level="warning")
|
|
@@ -40,6 +40,10 @@ export async function readerPage(id, stale) {
|
|
|
40
40
|
const r = readerState({ id, paper: p, language, view: p.has_pdf && (innerWidth >= 700 || !p.text) ? "pdf" : "text" });
|
|
41
41
|
const bar = setupBar(r);
|
|
42
42
|
setupRoute(r);
|
|
43
|
+
// A scan is pictures of pages: it can be read, but there are no words to select, highlight or explain.
|
|
44
|
+
if (p.has_pdf && !p.text && !p.preparing) {
|
|
45
|
+
setTimeout(() => toast("This PDF is a scan (pictures of pages), so its text can't be selected or explained. A version with real text will work."), 1200);
|
|
46
|
+
}
|
|
43
47
|
const notes = noteStore(id);
|
|
44
48
|
const vocab = setupVocab(r);
|
|
45
49
|
const views = createViews(r, { notes, vocab, fitBar: bar.fit });
|
|
@@ -42,3 +42,29 @@ def test_with_uv_it_starts_again_on_a_python_that_works(monkeypatch, capsys):
|
|
|
42
42
|
with pytest.raises(SystemExit) as stop:
|
|
43
43
|
cli.check_python([])
|
|
44
44
|
assert stop.value.code == 1 and len(ran) == 1
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_the_link_waits_for_the_app_to_answer(monkeypatch):
|
|
48
|
+
answers = iter([OSError("refused"), OSError("refused"), "up"])
|
|
49
|
+
|
|
50
|
+
class Up:
|
|
51
|
+
status = 200
|
|
52
|
+
__enter__ = lambda self: self
|
|
53
|
+
__exit__ = lambda self, *a: None
|
|
54
|
+
|
|
55
|
+
def fake_open(address, timeout):
|
|
56
|
+
got = next(answers)
|
|
57
|
+
if isinstance(got, OSError):
|
|
58
|
+
raise got
|
|
59
|
+
return Up()
|
|
60
|
+
monkeypatch.setattr(cli.urllib.request, "urlopen", fake_open)
|
|
61
|
+
monkeypatch.setattr(cli.time, "sleep", lambda s: None)
|
|
62
|
+
assert cli.wait_until_up("0.0.0.0", 8000) is True
|
|
63
|
+
assert next(answers, "used up") == "used up" # it asked three times, and stopped at the first answer
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_starting_does_not_load_the_slow_anthropic_library():
|
|
67
|
+
import subprocess
|
|
68
|
+
import sys
|
|
69
|
+
code = "import sys, papers.main; print('anthropic' in sys.modules)"
|
|
70
|
+
assert subprocess.run([sys.executable, "-c", code], capture_output=True, text=True).stdout.strip() == "False"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|