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.
Files changed (152) hide show
  1. {papers_app-0.3.1 → papers_app-0.3.2}/PKG-INFO +2 -2
  2. {papers_app-0.3.1 → papers_app-0.3.2}/README.md +1 -1
  3. {papers_app-0.3.1 → papers_app-0.3.2}/papers/__init__.py +1 -1
  4. {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/loop.py +1 -2
  5. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/anthropic_api.py +21 -6
  6. {papers_app-0.3.1 → papers_app-0.3.2}/papers/cli.py +69 -16
  7. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader.js +4 -0
  8. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_cli.py +26 -0
  9. {papers_app-0.3.1 → papers_app-0.3.2}/.gitignore +0 -0
  10. {papers_app-0.3.1 → papers_app-0.3.2}/CONTRIBUTING.md +0 -0
  11. {papers_app-0.3.1 → papers_app-0.3.2}/LICENSE +0 -0
  12. {papers_app-0.3.1 → papers_app-0.3.2}/papers/__main__.py +0 -0
  13. {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/__init__.py +0 -0
  14. {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/mcp_server.py +0 -0
  15. {papers_app-0.3.1 → papers_app-0.3.2}/papers/agent/tools.py +0 -0
  16. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/__init__.py +0 -0
  17. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/capabilities.py +0 -0
  18. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/claude_code.py +0 -0
  19. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/codex.py +0 -0
  20. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/errors.py +0 -0
  21. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/openai_compat.py +0 -0
  22. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/providers.py +0 -0
  23. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ai/streaming.py +0 -0
  24. {papers_app-0.3.1 → papers_app-0.3.2}/papers/bibtex.py +0 -0
  25. {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/__init__.py +0 -0
  26. {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/answer.py +0 -0
  27. {papers_app-0.3.1 → papers_app-0.3.2}/papers/chat/store.py +0 -0
  28. {papers_app-0.3.1 → papers_app-0.3.2}/papers/config.py +0 -0
  29. {papers_app-0.3.1 → papers_app-0.3.2}/papers/db.py +0 -0
  30. {papers_app-0.3.1 → papers_app-0.3.2}/papers/figures.py +0 -0
  31. {papers_app-0.3.1 → papers_app-0.3.2}/papers/folders.py +0 -0
  32. {papers_app-0.3.1 → papers_app-0.3.2}/papers/index.py +0 -0
  33. {papers_app-0.3.1 → papers_app-0.3.2}/papers/ingest.py +0 -0
  34. {papers_app-0.3.1 → papers_app-0.3.2}/papers/keys.py +0 -0
  35. {papers_app-0.3.1 → papers_app-0.3.2}/papers/library.py +0 -0
  36. {papers_app-0.3.1 → papers_app-0.3.2}/papers/llm.py +0 -0
  37. {papers_app-0.3.1 → papers_app-0.3.2}/papers/main.py +0 -0
  38. {papers_app-0.3.1 → papers_app-0.3.2}/papers/notes.py +0 -0
  39. {papers_app-0.3.1 → papers_app-0.3.2}/papers/pdf.py +0 -0
  40. {papers_app-0.3.1 → papers_app-0.3.2}/papers/roadmap.py +0 -0
  41. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/__init__.py +0 -0
  42. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/chat.py +0 -0
  43. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/goals.py +0 -0
  44. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/learning.py +0 -0
  45. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/notes.py +0 -0
  46. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/papers.py +0 -0
  47. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/reading.py +0 -0
  48. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/recall.py +0 -0
  49. {papers_app-0.3.1 → papers_app-0.3.2}/papers/routes/settings.py +0 -0
  50. {papers_app-0.3.1 → papers_app-0.3.2}/papers/scholar.py +0 -0
  51. {papers_app-0.3.1 → papers_app-0.3.2}/papers/setup.py +0 -0
  52. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/base.css +0 -0
  53. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/chat.css +0 -0
  54. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/components.css +0 -0
  55. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/goals.css +0 -0
  56. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/library.css +0 -0
  57. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/map.css +0 -0
  58. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/paper.css +0 -0
  59. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/reader.css +0 -0
  60. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/recall.css +0 -0
  61. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/settings.css +0 -0
  62. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/tokens.css +0 -0
  63. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/css/welcome.css +0 -0
  64. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/index.html +0 -0
  65. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/answer.js +0 -0
  66. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/canvas.js +0 -0
  67. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/conversation.js +0 -0
  68. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/render.js +0 -0
  69. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/stream.js +0 -0
  70. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/chat/widgets.js +0 -0
  71. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/components/combobox.js +0 -0
  72. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/components/folderpicker.js +0 -0
  73. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/core.js +0 -0
  74. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/covers.js +0 -0
  75. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/highlights.js +0 -0
  76. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/icons.js +0 -0
  77. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/main.js +0 -0
  78. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/notes.js +0 -0
  79. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/goals.js +0 -0
  80. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/library.js +0 -0
  81. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/map.js +0 -0
  82. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/recall.js +0 -0
  83. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/settings.js +0 -0
  84. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/shared.js +0 -0
  85. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pages/welcome.js +0 -0
  86. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/figures.js +0 -0
  87. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/overview.js +0 -0
  88. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/bar.js +0 -0
  89. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/cite.js +0 -0
  90. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/finish.js +0 -0
  91. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/highlighter.js +0 -0
  92. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/keys.js +0 -0
  93. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/layout.js +0 -0
  94. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/panel.js +0 -0
  95. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/progress.js +0 -0
  96. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/route.js +0 -0
  97. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/selection.js +0 -0
  98. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/state.js +0 -0
  99. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/terms.js +0 -0
  100. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/views.js +0 -0
  101. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/vocab.js +0 -0
  102. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/reader/zoom.js +0 -0
  103. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/review.js +0 -0
  104. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/paper/shared.js +0 -0
  105. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/pdfview.js +0 -0
  106. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/readprefs.js +0 -0
  107. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/speech.js +0 -0
  108. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/textview.js +0 -0
  109. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/theme.js +0 -0
  110. {papers_app-0.3.1 → papers_app-0.3.2}/papers/static/js/tracker.js +0 -0
  111. {papers_app-0.3.1 → papers_app-0.3.2}/papers/storage.py +0 -0
  112. {papers_app-0.3.1 → papers_app-0.3.2}/papers/store.py +0 -0
  113. {papers_app-0.3.1 → papers_app-0.3.2}/pyproject.toml +0 -0
  114. {papers_app-0.3.1 → papers_app-0.3.2}/tests/__init__.py +0 -0
  115. {papers_app-0.3.1 → papers_app-0.3.2}/tests/conftest.py +0 -0
  116. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_abstract_figures.py +0 -0
  117. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_add_link.py +0 -0
  118. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_agent.py +0 -0
  119. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_agent_actions.py +0 -0
  120. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_ai.py +0 -0
  121. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_capabilities.py +0 -0
  122. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_capture.py +0 -0
  123. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_claude_code.py +0 -0
  124. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_conversations.py +0 -0
  125. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_folders.py +0 -0
  126. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_frontend.py +0 -0
  127. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_highlights_notes.py +0 -0
  128. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_keys.py +0 -0
  129. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_learning.py +0 -0
  130. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_library_covers.py +0 -0
  131. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_library_folder.py +0 -0
  132. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_metadata.py +0 -0
  133. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_never_stuck.py +0 -0
  134. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_notes_ask.py +0 -0
  135. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_papers.py +0 -0
  136. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_prepare.py +0 -0
  137. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_progress.py +0 -0
  138. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_prompts.py +0 -0
  139. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_provider_list.py +0 -0
  140. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_providers.py +0 -0
  141. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_recall_refs.py +0 -0
  142. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_review.py +0 -0
  143. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_roadmap.py +0 -0
  144. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_scaffold.py +0 -0
  145. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_search.py +0 -0
  146. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_setup.py +0 -0
  147. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_storage.py +0 -0
  148. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_streaming.py +0 -0
  149. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_tracker.py +0 -0
  150. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_triage.py +0 -0
  151. {papers_app-0.3.1 → papers_app-0.3.2}/tests/test_upload.py +0 -0
  152. {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.1
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.1`) |
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.1`) |
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.1"
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 anthropic.APIError as e:
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
- import anthropic
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 client() -> anthropic.Anthropic:
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 anthropic.Anthropic(api_key=providers.provider_setting("ai_key", "anthropic") or None)
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 anthropic.APIError as e:
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 anthropic.APIError as e:
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
- def check_python(argv: list[str] | None = None) -> None:
32
- """Load the app's libraries before asking anything. On a Python they can't run on (a pre-release, or one newer
33
- than they support) the app would crash halfway through setup; instead it starts itself again on a Python that
34
- works, when uv is there to fetch one, or says in one line what to do."""
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 papers.ai # noqa: F401 (pulls in pydantic and the AI clients, the parts tied to the Python version)
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
- check_python(argv)
69
- from papers import config, setup # after PAPERS_DATA is set
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
- if setup.interactive():
86
- setup.started(url, config.data_dir().resolve())
87
- else:
88
- print(f"Papers {__version__}: your library is in {config.data_dir()}")
89
- print(f"Open {url} (Ctrl+C to stop)")
90
- if not args.no_browser:
91
- threading.Timer(1.2, webbrowser.open, (url,)).start()
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