litdb 2.2.3__tar.gz → 2.2.4__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 (46) hide show
  1. {litdb-2.2.3/src/litdb.egg-info → litdb-2.2.4}/PKG-INFO +16 -10
  2. {litdb-2.2.3 → litdb-2.2.4}/README.org +10 -2
  3. {litdb-2.2.3 → litdb-2.2.4}/pyproject.toml +19 -10
  4. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/app.py +65 -54
  5. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/audio.py +12 -11
  6. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/chat.py +9 -5
  7. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/cli.py +9 -12
  8. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/coa.py +8 -11
  9. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/data_processing.py +3 -3
  10. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/export.py +2 -3
  11. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/filters.py +5 -2
  12. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/install.py +1 -2
  13. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/manage.py +8 -8
  14. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/openalex_commands.py +2 -3
  15. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/research_commands.py +12 -12
  16. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/review.py +0 -1
  17. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/search.py +39 -19
  18. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/tags.py +0 -1
  19. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/crawl.py +8 -9
  20. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/db.py +25 -23
  21. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/doe_collaborators.py +6 -7
  22. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/extract.py +9 -10
  23. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/gpt.py +10 -4
  24. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/images.py +7 -5
  25. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/lab.py +2 -1
  26. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/lsearch.py +3 -2
  27. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/mcp_server.py +20 -17
  28. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/openalex.py +12 -7
  29. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/server.py +1 -2
  30. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/summary.py +5 -5
  31. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/utils.py +2 -1
  32. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/youtube.py +2 -1
  33. {litdb-2.2.3 → litdb-2.2.4/src/litdb.egg-info}/PKG-INFO +16 -10
  34. {litdb-2.2.3 → litdb-2.2.4}/src/litdb.egg-info/requires.txt +4 -7
  35. {litdb-2.2.3 → litdb-2.2.4}/LICENSE +0 -0
  36. {litdb-2.2.3 → litdb-2.2.4}/setup.cfg +0 -0
  37. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/__init__.py +2 -2
  38. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/bibtex.py +0 -0
  39. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/__init__.py +0 -0
  40. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/commands/utilities.py +1 -1
  41. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/pdf.py +2 -2
  42. {litdb-2.2.3 → litdb-2.2.4}/src/litdb/research.py +4 -4
  43. {litdb-2.2.3 → litdb-2.2.4}/src/litdb.egg-info/SOURCES.txt +0 -0
  44. {litdb-2.2.3 → litdb-2.2.4}/src/litdb.egg-info/dependency_links.txt +0 -0
  45. {litdb-2.2.3 → litdb-2.2.4}/src/litdb.egg-info/entry_points.txt +0 -0
  46. {litdb-2.2.3 → litdb-2.2.4}/src/litdb.egg-info/top_level.txt +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: litdb
3
- Version: 2.2.3
3
+ Version: 2.2.4
4
4
  Summary: A literature database tool with GPT integration.
5
5
  Author-email: John Kitchin <jkitchin@andrew.cmu.edu>
6
6
  Maintainer-email: John Kitchin <jkitchin@andrew.cmu.edu>
7
7
  License-Expression: MIT
8
8
  Project-URL: Homepage, https://github.com/jkitchin/litdb
9
+ Requires-Python: >=3.11
9
10
  Description-Content-Type: text/plain
10
11
  License-File: LICENSE
11
12
  Requires-Dist: toml
@@ -36,14 +37,13 @@ Requires-Dist: pillow
36
37
  Requires-Dist: bibtexparser<2
37
38
  Requires-Dist: pandas
38
39
  Requires-Dist: more-itertools
39
- Requires-Dist: nameparser
40
+ Requires-Dist: nameparser<3
40
41
  Requires-Dist: tabulate
41
42
  Requires-Dist: IPython
42
43
  Requires-Dist: gmft
43
- Requires-Dist: ruff>=0.13.3
44
44
  Requires-Dist: torch
45
45
  Requires-Dist: torchvision
46
- Requires-Dist: fastmcp>=2.13.3
46
+ Requires-Dist: mcp<2,>=1.22
47
47
  Provides-Extra: test
48
48
  Requires-Dist: pytest>=8.0.0; extra == "test"
49
49
  Requires-Dist: pytest-cov>=4.1.0; extra == "test"
@@ -60,7 +60,6 @@ Requires-Dist: langchain_google_genai; extra == "research"
60
60
  Requires-Dist: langchain_anthropic; extra == "research"
61
61
  Requires-Dist: mistune; extra == "research"
62
62
  Requires-Dist: htmldocx; extra == "research"
63
- Requires-Dist: docx; extra == "research"
64
63
  Requires-Dist: md2pdf; extra == "research"
65
64
  Requires-Dist: pypandoc; extra == "research"
66
65
  Provides-Extra: app
@@ -75,7 +74,7 @@ Provides-Extra: image
75
74
  Requires-Dist: pyperclip; extra == "image"
76
75
  Requires-Dist: pillow_heif; extra == "image"
77
76
  Provides-Extra: mcp
78
- Requires-Dist: mcp[cli]; extra == "mcp"
77
+ Requires-Dist: mcp[cli]<2,>=1.22; extra == "mcp"
79
78
  Provides-Extra: audio
80
79
  Requires-Dist: pyaudio; extra == "audio"
81
80
  Requires-Dist: SpeechRecognition; extra == "audio"
@@ -88,7 +87,6 @@ Requires-Dist: langchain_google_genai; extra == "all"
88
87
  Requires-Dist: langchain_anthropic; extra == "all"
89
88
  Requires-Dist: mistune; extra == "all"
90
89
  Requires-Dist: htmldocx; extra == "all"
91
- Requires-Dist: docx; extra == "all"
92
90
  Requires-Dist: md2pdf; extra == "all"
93
91
  Requires-Dist: pypandoc; extra == "all"
94
92
  Requires-Dist: streamlit; extra == "all"
@@ -98,7 +96,7 @@ Requires-Dist: scrapy; extra == "all"
98
96
  Requires-Dist: backoff; extra == "all"
99
97
  Requires-Dist: pyperclip; extra == "all"
100
98
  Requires-Dist: pillow_heif; extra == "all"
101
- Requires-Dist: mcp[cli]; extra == "all"
99
+ Requires-Dist: mcp[cli]<2,>=1.22; extra == "all"
102
100
  Requires-Dist: pyaudio; extra == "all"
103
101
  Requires-Dist: SpeechRecognition; extra == "all"
104
102
  Dynamic: license-file
@@ -111,9 +109,17 @@ Dynamic: license-file
111
109
  <a href="https://github.com/jkitchin/litdb/actions/workflows/build.yml">
112
110
  <img src="https://github.com/jkitchin/litdb/actions/workflows/build.yml/badge.svg" alt="Build Status">
113
111
  </a>
114
- <img src="https://img.shields.io/badge/tests-133_passed,_66_skipped-brightgreen" alt="Tests">
112
+ <a href="https://github.com/jkitchin/litdb/actions/workflows/test.yml">
113
+ <img src="https://github.com/jkitchin/litdb/actions/workflows/test.yml/badge.svg" alt="CI">
114
+ </a>
115
+ <a href="https://pypi.org/project/litdb/">
116
+ <img src="https://img.shields.io/pypi/v/litdb.svg" alt="PyPI">
117
+ </a>
118
+ <a href="https://pepy.tech/projects/litdb">
119
+ <img src="https://static.pepy.tech/personalized-badge/litdb?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads" alt="PyPI Downloads">
120
+ </a>
115
121
  <a href="https://doi.org/10.5281/zenodo.23514948">
116
- <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.23514948.svg" alt="DOI">
122
+ <img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23514948-blue.svg" alt="DOI">
117
123
  </a>
118
124
  #+END_HTML
119
125
 
@@ -6,9 +6,17 @@
6
6
  <a href="https://github.com/jkitchin/litdb/actions/workflows/build.yml">
7
7
  <img src="https://github.com/jkitchin/litdb/actions/workflows/build.yml/badge.svg" alt="Build Status">
8
8
  </a>
9
- <img src="https://img.shields.io/badge/tests-133_passed,_66_skipped-brightgreen" alt="Tests">
9
+ <a href="https://github.com/jkitchin/litdb/actions/workflows/test.yml">
10
+ <img src="https://github.com/jkitchin/litdb/actions/workflows/test.yml/badge.svg" alt="CI">
11
+ </a>
12
+ <a href="https://pypi.org/project/litdb/">
13
+ <img src="https://img.shields.io/pypi/v/litdb.svg" alt="PyPI">
14
+ </a>
15
+ <a href="https://pepy.tech/projects/litdb">
16
+ <img src="https://static.pepy.tech/personalized-badge/litdb?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads" alt="PyPI Downloads">
17
+ </a>
10
18
  <a href="https://doi.org/10.5281/zenodo.23514948">
11
- <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.23514948.svg" alt="DOI">
19
+ <img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23514948-blue.svg" alt="DOI">
12
20
  </a>
13
21
  #+END_HTML
14
22
 
@@ -7,7 +7,7 @@ where = ["src"]
7
7
 
8
8
  [project]
9
9
  name = "litdb"
10
- version = "2.2.3"
10
+ version = "2.2.4"
11
11
  authors = [
12
12
  {name = "John Kitchin", email = "jkitchin@andrew.cmu.edu"},
13
13
  ]
@@ -16,6 +16,7 @@ maintainers = [
16
16
  ]
17
17
  description = "A literature database tool with GPT integration."
18
18
  license = "MIT"
19
+ requires-python = ">=3.11"
19
20
  readme = {file = "README.org", content-type = "text/plain"}
20
21
  dependencies = [
21
22
  # Core dependencies - always installed
@@ -48,16 +49,20 @@ dependencies = [
48
49
  # Data processing and COA
49
50
  "pandas",
50
51
  "more-itertools",
51
- "nameparser",
52
+ "nameparser<3", # 3.0 removed HumanName (used in coa.py, doe_collaborators.py)
52
53
  "tabulate",
53
54
  "IPython",
54
55
  # Table extraction
55
56
  "gmft",
56
- # Development tools
57
- "ruff>=0.13.3",
58
57
  "torch",
59
58
  "torchvision",
60
- "fastmcp>=2.13.3",
59
+ # mcp 2.x removed mcp.server.fastmcp, which mcp_server.py uses
60
+ "mcp>=1.22,<2",
61
+ ]
62
+
63
+ [dependency-groups]
64
+ dev = [
65
+ "ruff>=0.17.5",
61
66
  ]
62
67
 
63
68
  [project.scripts]
@@ -91,7 +96,6 @@ research = [
91
96
  "langchain_anthropic",
92
97
  "mistune",
93
98
  "htmldocx",
94
- "docx",
95
99
  "md2pdf",
96
100
  "pypandoc",
97
101
  ]
@@ -121,7 +125,7 @@ image = [
121
125
 
122
126
  # MCP server for Claude Desktop
123
127
  mcp = [
124
- "mcp[cli]",
128
+ "mcp[cli]>=1.22,<2",
125
129
  ]
126
130
 
127
131
  # Audio recording and transcription (requires external libraries)
@@ -140,7 +144,6 @@ all = [
140
144
  "langchain_anthropic",
141
145
  "mistune",
142
146
  "htmldocx",
143
- "docx",
144
147
  "md2pdf",
145
148
  "pypandoc",
146
149
  "streamlit",
@@ -150,7 +153,7 @@ all = [
150
153
  "backoff",
151
154
  "pyperclip",
152
155
  "pillow_heif",
153
- "mcp[cli]",
156
+ "mcp[cli]>=1.22,<2",
154
157
  "pyaudio",
155
158
  "SpeechRecognition",
156
159
  ]
@@ -201,4 +204,10 @@ exclude_lines = [
201
204
  directory = "htmlcov"
202
205
 
203
206
  # (shell-command "uv build")
204
- # (shell-command "uv publish")
207
+ # (shell-command "uv publish")
208
+ [tool.ruff.lint.per-file-ignores]
209
+ # The Streamlit UI and the MCP tools are top-level boundaries: any error is
210
+ # shown to the user (st.error / tool result) instead of crashing the page or
211
+ # server, and optional metadata parsing falls back silently.
212
+ "src/litdb/app.py" = ["BLE001", "S110"]
213
+ "src/litdb/mcp_server.py" = ["BLE001"]
@@ -190,7 +190,7 @@ def format_citation(extra):
190
190
  parts = []
191
191
 
192
192
  # Authors
193
- if "authorships" in data and data["authorships"]:
193
+ if data.get("authorships"):
194
194
  authors = [a["author"]["display_name"] for a in data["authorships"][:3]]
195
195
  if len(data["authorships"]) > 3:
196
196
  authors.append("et al.")
@@ -303,7 +303,7 @@ def tab_search():
303
303
  try:
304
304
  extra_data = json.loads(extra)
305
305
  doi = extra_data.get("doi") or extra_data.get("id")
306
- if doi and (doi.startswith("http") or doi.startswith("10.")):
306
+ if doi and (doi.startswith(("http", "10."))):
307
307
  dois_to_process.append(doi)
308
308
  except Exception:
309
309
  pass
@@ -405,8 +405,8 @@ Adding: references, citations, and related works...
405
405
  # Execute query if needed
406
406
  if should_run_query:
407
407
  # Vector search - we need to compute embedding first
408
- from sentence_transformers import SentenceTransformer
409
408
  import numpy as np
409
+ from sentence_transformers import SentenceTransformer
410
410
 
411
411
  config = get_config()
412
412
  model = SentenceTransformer(config["embedding"]["model"])
@@ -477,10 +477,11 @@ Adding: references, citations, and related works...
477
477
  cols = st.columns(len(current_tags) + 1)
478
478
  for idx, tag in enumerate(current_tags):
479
479
  with cols[idx]:
480
- if st.button(f"🗑️ {tag}", key=f"rm_tag_v_{i}_{tag}"):
481
- if remove_tag_from_source(source, tag):
482
- st.success(f"Removed tag: {tag}")
483
- st.rerun()
480
+ if st.button(
481
+ f"🗑️ {tag}", key=f"rm_tag_v_{i}_{tag}"
482
+ ) and remove_tag_from_source(source, tag):
483
+ st.success(f"Removed tag: {tag}")
484
+ st.rerun()
484
485
  else:
485
486
  st.caption("No tags yet")
486
487
 
@@ -494,13 +495,16 @@ Adding: references, citations, and related works...
494
495
  label_visibility="collapsed",
495
496
  )
496
497
  with new_tag_col2:
497
- if st.button("➕ Add", key=f"add_tag_v_{i}"):
498
- if new_tag and new_tag.strip():
499
- if add_tag_to_source(source, new_tag.strip()):
500
- st.success(f"Added tag: {new_tag}")
501
- st.rerun()
502
- else:
503
- st.warning("Tag already exists")
498
+ if (
499
+ st.button("➕ Add", key=f"add_tag_v_{i}")
500
+ and new_tag
501
+ and new_tag.strip()
502
+ ):
503
+ if add_tag_to_source(source, new_tag.strip()):
504
+ st.success(f"Added tag: {new_tag}")
505
+ st.rerun()
506
+ else:
507
+ st.warning("Tag already exists")
504
508
 
505
509
  # Check if this is a DOI/OpenAlex entry to show add buttons
506
510
  doi = None
@@ -511,7 +515,7 @@ Adding: references, citations, and related works...
511
515
  except Exception:
512
516
  pass
513
517
 
514
- if doi and (doi.startswith("http") or doi.startswith("10.")):
518
+ if doi and (doi.startswith(("http", "10."))):
515
519
  st.markdown("---")
516
520
  st.markdown("**Add Related Works:**")
517
521
  col1, col2, col3 = st.columns(3)
@@ -642,7 +646,7 @@ Adding: references, citations, and related works...
642
646
  except Exception:
643
647
  pass
644
648
 
645
- if doi and (doi.startswith("http") or doi.startswith("10.")):
649
+ if doi and (doi.startswith(("http", "10."))):
646
650
  st.markdown("---")
647
651
  st.markdown("**Add Related Works:**")
648
652
  col1, col2, col3 = st.columns(3)
@@ -709,8 +713,8 @@ Adding: references, citations, and related works...
709
713
  # Execute queries if needed
710
714
  if should_run_query:
711
715
  # Vector search
712
- from sentence_transformers import SentenceTransformer
713
716
  import numpy as np
717
+ from sentence_transformers import SentenceTransformer
714
718
 
715
719
  config = get_config()
716
720
  model = SentenceTransformer(config["embedding"]["model"])
@@ -794,7 +798,7 @@ Adding: references, citations, and related works...
794
798
  except Exception:
795
799
  pass
796
800
 
797
- if doi and (doi.startswith("http") or doi.startswith("10.")):
801
+ if doi and (doi.startswith(("http", "10."))):
798
802
  st.markdown("---")
799
803
  st.markdown("**Add Related Works:**")
800
804
  col1, col2, col3 = st.columns(3)
@@ -906,7 +910,7 @@ Adding: references, citations, and related works...
906
910
  except Exception:
907
911
  pass
908
912
 
909
- if doi and (doi.startswith("http") or doi.startswith("10.")):
913
+ if doi and (doi.startswith(("http", "10."))):
910
914
  st.markdown("---")
911
915
  st.markdown("**Add Related Works:**")
912
916
  col1, col2, col3 = st.columns(3)
@@ -1252,9 +1256,10 @@ def tab_semantic_scholar_search():
1252
1256
 
1253
1257
  # Abstract
1254
1258
  abstract = paper.get("abstract")
1255
- if abstract:
1256
- if st.checkbox("📄 Show Abstract", key=f"abstract_ss_{i}"):
1257
- st.write(abstract)
1259
+ if abstract and st.checkbox(
1260
+ "📄 Show Abstract", key=f"abstract_ss_{i}"
1261
+ ):
1262
+ st.write(abstract)
1258
1263
 
1259
1264
  # Add paper button
1260
1265
  st.markdown("---")
@@ -1381,10 +1386,11 @@ def tab_suggest_reviewers():
1381
1386
 
1382
1387
  try:
1383
1388
  # Perform vector search to find similar papers
1384
- from sentence_transformers import SentenceTransformer
1385
- import numpy as np
1386
1389
  from collections import Counter
1390
+
1391
+ import numpy as np
1387
1392
  from more_itertools import batched
1393
+ from sentence_transformers import SentenceTransformer
1388
1394
 
1389
1395
  config = get_config()
1390
1396
  db = get_db()
@@ -1646,7 +1652,7 @@ def tab_add_content():
1646
1652
  ).fetchone()
1647
1653
 
1648
1654
  if work_info:
1649
- source, text, extra = work_info
1655
+ _source, _text, extra = work_info
1650
1656
  extra_data = json.loads(extra) if extra else {}
1651
1657
  citation = format_citation(extra)
1652
1658
 
@@ -1669,7 +1675,7 @@ def tab_add_content():
1669
1675
 
1670
1676
  except Exception as e:
1671
1677
  failed_works.append({"doi": doi, "error": str(e)})
1672
- status_text.error(f"✗ Failed {idx}/{len(dois)}: {str(e)}")
1678
+ status_text.error(f"✗ Failed {idx}/{len(dois)}: {e!s}")
1673
1679
 
1674
1680
  progress_bar.progress(idx / len(dois))
1675
1681
 
@@ -1743,10 +1749,9 @@ def tab_add_content():
1743
1749
  with cols[tag_idx]:
1744
1750
  if st.button(
1745
1751
  f"🗑️ {tag}", key=f"rm_tag_add_{idx}_{tag}"
1746
- ):
1747
- if remove_tag_from_source(work["doi"], tag):
1748
- st.success(f"Removed tag: {tag}")
1749
- st.rerun()
1752
+ ) and remove_tag_from_source(work["doi"], tag):
1753
+ st.success(f"Removed tag: {tag}")
1754
+ st.rerun()
1750
1755
  else:
1751
1756
  st.caption("No tags yet")
1752
1757
 
@@ -1760,15 +1765,16 @@ def tab_add_content():
1760
1765
  label_visibility="collapsed",
1761
1766
  )
1762
1767
  with new_tag_col2:
1763
- if st.button("➕ Add", key=f"add_tag_btn_{idx}"):
1764
- if new_tag and new_tag.strip():
1765
- if add_tag_to_source(
1766
- work["doi"], new_tag.strip()
1767
- ):
1768
- st.success(f"Added tag: {new_tag}")
1769
- st.rerun()
1770
- else:
1771
- st.warning("Tag already exists")
1768
+ if (
1769
+ st.button("➕ Add", key=f"add_tag_btn_{idx}")
1770
+ and new_tag
1771
+ and new_tag.strip()
1772
+ ):
1773
+ if add_tag_to_source(work["doi"], new_tag.strip()):
1774
+ st.success(f"Added tag: {new_tag}")
1775
+ st.rerun()
1776
+ else:
1777
+ st.warning("Tag already exists")
1772
1778
 
1773
1779
  # Add Related Works buttons
1774
1780
  st.markdown("---")
@@ -1874,8 +1880,10 @@ def tab_add_content():
1874
1880
 
1875
1881
  if fromtext_submitted:
1876
1882
  if text_input:
1877
- import requests
1878
1883
  from difflib import SequenceMatcher
1884
+
1885
+ import requests
1886
+
1879
1887
  from litdb.chat import get_completion
1880
1888
 
1881
1889
  with st.spinner("Extracting references using LLM..."):
@@ -2176,8 +2184,8 @@ Text:
2176
2184
  file_submitted = st.form_submit_button("Add File")
2177
2185
 
2178
2186
  if file_submitted and uploaded_file:
2179
- import tempfile
2180
2187
  import pathlib
2188
+ import tempfile
2181
2189
 
2182
2190
  # Save uploaded file to temporary location
2183
2191
  with tempfile.NamedTemporaryFile(
@@ -2189,9 +2197,10 @@ Text:
2189
2197
  try:
2190
2198
  with st.spinner(f"Processing {uploaded_file.name}..."):
2191
2199
  # Import the add logic
2192
- from litdb.commands.manage import add as cli_add
2193
2200
  from click import Context
2194
2201
 
2202
+ from litdb.commands.manage import add as cli_add
2203
+
2195
2204
  # Call the add function
2196
2205
  with Context(cli_add) as ctx:
2197
2206
  ctx.invoke(cli_add, sources=[tmp_path])
@@ -2222,9 +2231,10 @@ Text:
2222
2231
  try:
2223
2232
  with st.spinner(f"Processing {url_input}..."):
2224
2233
  # Import the add logic
2225
- from litdb.commands.manage import add as cli_add
2226
2234
  from click import Context
2227
2235
 
2236
+ from litdb.commands.manage import add as cli_add
2237
+
2228
2238
  # Call the add function
2229
2239
  with Context(cli_add) as ctx:
2230
2240
  ctx.invoke(cli_add, sources=[url_input])
@@ -2301,9 +2311,10 @@ Text:
2301
2311
  successfully_added = []
2302
2312
  failed_to_add = []
2303
2313
 
2304
- from litdb.commands.manage import add as cli_add
2305
2314
  from click import Context
2306
2315
 
2316
+ from litdb.commands.manage import add as cli_add
2317
+
2307
2318
  for i, fname in enumerate(new_files):
2308
2319
  status_text.text(
2309
2320
  f"Adding {i + 1}/{len(new_files)}: {fname.name}"
@@ -2504,9 +2515,10 @@ def tab_manage_filters():
2504
2515
  st.session_state.update_filters_clicked = False
2505
2516
 
2506
2517
  # Import here where we actually use it
2507
- from litdb.db import update_filter
2508
2518
  import os
2509
2519
 
2520
+ from litdb.db import update_filter
2521
+
2510
2522
  # Set offline mode to speed up embeddings
2511
2523
  os.environ["TRANSFORMERS_OFFLINE"] = "1"
2512
2524
 
@@ -2553,11 +2565,9 @@ def tab_manage_filters():
2553
2565
  status_text.info(f"✓ Filter {idx}/{len(filters)}: No new works")
2554
2566
 
2555
2567
  except Exception as e:
2556
- error_msg = f"Filter {idx}: {str(e)}"
2568
+ error_msg = f"Filter {idx}: {e!s}"
2557
2569
  errors.append(error_msg)
2558
- status_text.error(
2559
- f"✗ Filter {idx}/{len(filters)}: Error - {str(e)}"
2560
- )
2570
+ status_text.error(f"✗ Filter {idx}/{len(filters)}: Error - {e!s}")
2561
2571
 
2562
2572
  progress_bar.progress(idx / len(filters))
2563
2573
 
@@ -2723,7 +2733,7 @@ def tab_manage_filters():
2723
2733
 
2724
2734
  except Exception as e:
2725
2735
  st.caption(
2726
- f"Error formatting article {idx}: {str(e)}"
2736
+ f"Error formatting article {idx}: {e!s}"
2727
2737
  )
2728
2738
  else:
2729
2739
  st.info(
@@ -2733,7 +2743,7 @@ def tab_manage_filters():
2733
2743
  st.warning("Could not parse filter expression")
2734
2744
 
2735
2745
  except Exception as e:
2736
- st.error(f"Error loading articles: {str(e)}")
2746
+ st.error(f"Error loading articles: {e!s}")
2737
2747
 
2738
2748
  st.markdown("---")
2739
2749
  else:
@@ -3113,10 +3123,10 @@ focus the response and ask them what they would like.""",
3113
3123
  st.session_state.research_step = "results"
3114
3124
  st.rerun()
3115
3125
 
3116
- except Exception as inner_e:
3126
+ except Exception:
3117
3127
  status_placeholder.empty()
3118
3128
  progress_bar.empty()
3119
- raise inner_e
3129
+ raise
3120
3130
 
3121
3131
  except ImportError:
3122
3132
  st.error("Deep research requires gpt_researcher to be installed")
@@ -3262,8 +3272,9 @@ def tab_nsf_coa():
3262
3272
  "Generating COA... This may take a few minutes depending on publication count."
3263
3273
  ):
3264
3274
  try:
3265
- import tempfile
3266
3275
  import os
3276
+ import tempfile
3277
+
3267
3278
  from litdb.coa import get_coa
3268
3279
 
3269
3280
  # Create a temporary directory to store the file
@@ -1,10 +1,11 @@
1
1
  """Library for audio sources."""
2
2
 
3
- import requests
4
- from transformers import pipeline
5
3
  import os
6
4
  import tempfile
7
5
 
6
+ import requests
7
+ from transformers import pipeline
8
+
8
9
 
9
10
  def is_audio_url(url):
10
11
  """Check if a given URL points to an audio file.
@@ -63,7 +64,7 @@ def get_audio_text(path):
63
64
  except requests.exceptions.RequestException as e:
64
65
  print(f"Error fetching audio from URL: {e}")
65
66
  return None
66
- except Exception as e:
67
+ except Exception as e: # noqa: BLE001 - whisper/ffmpeg raise many types
67
68
  print(f"Error during transcription: {e}")
68
69
  return None
69
70
 
@@ -73,9 +74,10 @@ def record():
73
74
 
74
75
  Returns the audio filename it is recorded in.
75
76
  """
76
- import pyaudio
77
- import wave
78
77
  import threading
78
+ import wave
79
+
80
+ import pyaudio
79
81
 
80
82
  # Parameters for recording
81
83
  FORMAT = pyaudio.paInt16
@@ -112,12 +114,11 @@ def record():
112
114
  stream.close()
113
115
 
114
116
  # Save the recorded data as a WAV file
115
- wf = wave.open(audio_file, "wb")
116
- wf.setnchannels(CHANNELS)
117
- wf.setsampwidth(audio.get_sample_size(FORMAT))
118
- wf.setframerate(RATE)
119
- wf.writeframes(b"".join(frames))
120
- wf.close()
117
+ with wave.open(audio_file, "wb") as wf:
118
+ wf.setnchannels(CHANNELS)
119
+ wf.setsampwidth(audio.get_sample_size(FORMAT))
120
+ wf.setframerate(RATE)
121
+ wf.writeframes(b"".join(frames))
121
122
  print(" Done recording. Transcribing...")
122
123
 
123
124
  # Event to signal when to stop recording
@@ -33,9 +33,9 @@ except ImportError:
33
33
  full_jitter = None
34
34
 
35
35
 
36
- from .utils import get_config
36
+ from .audio import get_audio_text, record
37
37
  from .db import get_db
38
- from .audio import record, get_audio_text
38
+ from .utils import get_config
39
39
 
40
40
  warnings.filterwarnings("ignore")
41
41
 
@@ -155,7 +155,9 @@ def expand_prompt(prompt):
155
155
  pattern = r"(^<(.+)$)"
156
156
  matches = re.findall(pattern, prompt, re.MULTILINE)
157
157
  for _match, cmd in matches:
158
- result = subprocess.run(cmd.strip(), shell=True, text=True, capture_output=True)
158
+ result = subprocess.run(
159
+ cmd.strip(), shell=True, text=True, capture_output=True, check=False
160
+ )
159
161
  prompt = prompt.replace(_match, result.stdout)
160
162
 
161
163
  return prompt
@@ -344,8 +346,10 @@ The following subcommands can be used:
344
346
 
345
347
  elif prompt == "!save":
346
348
  with open(input("Filename (chat.txt): ") or "chat.txt", "w") as f:
347
- for message in messages:
348
- f.write(f"{message['role']}: {message['content']}\n\n")
349
+ f.writelines(
350
+ f"{message['role']}: {message['content']}\n\n"
351
+ for message in messages
352
+ )
349
353
  continue
350
354
 
351
355
  elif prompt == "!restart":
@@ -3,29 +3,27 @@
3
3
  The main command is litdb. There are subcommands for the actions.
4
4
  """
5
5
 
6
+ import logging
6
7
  import warnings
7
8
 
8
9
  import click
9
-
10
- from .db import get_db
10
+ from transformers.utils import logging as tulogging
11
11
 
12
12
  # Import command modules
13
13
  from .commands import (
14
- manage,
15
- search,
14
+ data_processing,
16
15
  export,
17
- tags,
18
- review,
19
16
  filters,
17
+ install,
18
+ manage,
20
19
  openalex_commands,
21
20
  research_commands,
22
- data_processing,
21
+ review,
22
+ search,
23
+ tags,
23
24
  utilities,
24
- install,
25
25
  )
26
-
27
- import logging
28
- from transformers.utils import logging as tulogging
26
+ from .db import get_db
29
27
 
30
28
  # Disable all Transformers logging
31
29
  tulogging.set_verbosity_error()
@@ -49,7 +47,6 @@ except SystemExit:
49
47
  @click.group()
50
48
  def cli():
51
49
  """Group command for litdb."""
52
- pass
53
50
 
54
51
 
55
52
  # Register commands from manage module