easybib 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.whl
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.
- easybib/cli.py +53 -5
- {easybib-0.2.0.dist-info → easybib-0.3.0.dist-info}/METADATA +32 -3
- easybib-0.3.0.dist-info/RECORD +9 -0
- easybib-0.2.0.dist-info/RECORD +0 -9
- {easybib-0.2.0.dist-info → easybib-0.3.0.dist-info}/WHEEL +0 -0
- {easybib-0.2.0.dist-info → easybib-0.3.0.dist-info}/entry_points.txt +0 -0
- {easybib-0.2.0.dist-info → easybib-0.3.0.dist-info}/top_level.txt +0 -0
easybib/cli.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"""Command-line interface for easybib."""
|
|
2
2
|
|
|
3
|
+
import configparser
|
|
3
4
|
import os
|
|
4
5
|
import argparse
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
|
|
8
|
+
from easybib import __version__
|
|
7
9
|
from easybib.core import (
|
|
8
10
|
extract_cite_keys,
|
|
9
11
|
extract_existing_bib_keys,
|
|
@@ -13,11 +15,52 @@ from easybib.core import (
|
|
|
13
15
|
)
|
|
14
16
|
|
|
15
17
|
|
|
18
|
+
def load_config(config_path):
|
|
19
|
+
"""Read an INI config file and return a dict from the [easybib] section."""
|
|
20
|
+
path = Path(config_path).expanduser()
|
|
21
|
+
if not path.is_file():
|
|
22
|
+
return {}
|
|
23
|
+
config = configparser.ConfigParser()
|
|
24
|
+
config.read(path)
|
|
25
|
+
if "easybib" not in config:
|
|
26
|
+
return {}
|
|
27
|
+
return dict(config["easybib"])
|
|
28
|
+
|
|
29
|
+
|
|
16
30
|
def main():
|
|
31
|
+
# First pass: extract --config so we know which config file to load
|
|
32
|
+
pre_parser = argparse.ArgumentParser(add_help=False)
|
|
33
|
+
pre_parser.add_argument(
|
|
34
|
+
"--config",
|
|
35
|
+
default="~/.easybib.config",
|
|
36
|
+
help="Path to config file (default: ~/.easybib.config)",
|
|
37
|
+
)
|
|
38
|
+
pre_args, _ = pre_parser.parse_known_args()
|
|
39
|
+
|
|
40
|
+
# Load config and build defaults
|
|
41
|
+
cfg = load_config(pre_args.config)
|
|
42
|
+
config_defaults = {}
|
|
43
|
+
if "output" in cfg:
|
|
44
|
+
config_defaults["output"] = cfg["output"]
|
|
45
|
+
if "max-authors" in cfg:
|
|
46
|
+
config_defaults["max_authors"] = int(cfg["max-authors"])
|
|
47
|
+
if "preferred-source" in cfg:
|
|
48
|
+
config_defaults["preferred_source"] = cfg["preferred-source"]
|
|
49
|
+
if "ads-api-key" in cfg:
|
|
50
|
+
config_defaults["ads_api_key"] = cfg["ads-api-key"]
|
|
51
|
+
|
|
17
52
|
parser = argparse.ArgumentParser(
|
|
18
53
|
description="Extract citations and download BibTeX from NASA/ADS"
|
|
19
54
|
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--version", action="version", version=f"%(prog)s {__version__}"
|
|
57
|
+
)
|
|
20
58
|
parser.add_argument("path", help="LaTeX file or directory containing LaTeX files")
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
"--config",
|
|
61
|
+
default="~/.easybib.config",
|
|
62
|
+
help="Path to config file (default: ~/.easybib.config)",
|
|
63
|
+
)
|
|
21
64
|
parser.add_argument(
|
|
22
65
|
"-o", "--output", default="references.bib", help="Output BibTeX file (existing entries are retained)"
|
|
23
66
|
)
|
|
@@ -41,7 +84,7 @@ def main():
|
|
|
41
84
|
)
|
|
42
85
|
parser.add_argument(
|
|
43
86
|
"-s",
|
|
44
|
-
"--source",
|
|
87
|
+
"--preferred-source",
|
|
45
88
|
choices=["ads", "inspire", "auto"],
|
|
46
89
|
default="ads",
|
|
47
90
|
help="Preferred BibTeX source: 'ads' (default), 'inspire', or 'auto' (based on key format)",
|
|
@@ -50,6 +93,11 @@ def main():
|
|
|
50
93
|
"--ads-api-key",
|
|
51
94
|
help="ADS API key (overrides ADS_API_KEY environment variable)",
|
|
52
95
|
)
|
|
96
|
+
|
|
97
|
+
# Apply config file defaults (CLI flags will still override)
|
|
98
|
+
if config_defaults:
|
|
99
|
+
parser.set_defaults(**config_defaults)
|
|
100
|
+
|
|
53
101
|
args = parser.parse_args()
|
|
54
102
|
|
|
55
103
|
# Collect all citation keys
|
|
@@ -80,12 +128,12 @@ def main():
|
|
|
80
128
|
print(key)
|
|
81
129
|
return 0
|
|
82
130
|
|
|
83
|
-
# Check for ADS API key (not required if using --source inspire)
|
|
131
|
+
# Check for ADS API key (not required if using --preferred-source inspire)
|
|
84
132
|
api_key = args.ads_api_key or os.getenv("ADS_API_KEY")
|
|
85
|
-
if not api_key and args.
|
|
133
|
+
if not api_key and args.preferred_source != "inspire":
|
|
86
134
|
print("Error: ADS_API_KEY environment variable not set")
|
|
87
135
|
print("Get your API key from: https://ui.adsabs.harvard.edu/user/settings/token")
|
|
88
|
-
print("(Or use --source inspire to fetch from INSPIRE without an ADS key)")
|
|
136
|
+
print("(Or use --preferred-source inspire to fetch from INSPIRE without an ADS key)")
|
|
89
137
|
return 1
|
|
90
138
|
|
|
91
139
|
# Check for existing bib file and determine which keys to fetch
|
|
@@ -108,7 +156,7 @@ def main():
|
|
|
108
156
|
not_found = []
|
|
109
157
|
for key in sorted(keys_to_fetch):
|
|
110
158
|
print(f"Fetching {key}...", end=" ")
|
|
111
|
-
bibtex, source = fetch_bibtex(key, api_key, args.
|
|
159
|
+
bibtex, source = fetch_bibtex(key, api_key, args.preferred_source)
|
|
112
160
|
if bibtex:
|
|
113
161
|
bibtex = replace_bibtex_key(bibtex, key)
|
|
114
162
|
bibtex = truncate_authors(bibtex, args.max_authors)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: easybib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Automatically fetch BibTeX entries from INSPIRE and ADS for LaTeX projects
|
|
5
5
|
Author-email: Gregory Ashton <gregory.ashton@ligo.org>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -42,17 +42,18 @@ Pass a directory to scan all `.tex` files recursively, or a single `.tex` file.
|
|
|
42
42
|
| Flag | Description |
|
|
43
43
|
|------|-------------|
|
|
44
44
|
| `-o`, `--output` | Output BibTeX file (default: `references.bib`) |
|
|
45
|
-
| `-s`, `--source` | Preferred source: `ads` (default), `inspire`, or `auto` |
|
|
45
|
+
| `-s`, `--preferred-source` | Preferred source: `ads` (default), `inspire`, or `auto` |
|
|
46
46
|
| `-a`, `--max-authors` | Truncate author lists (default: 3, use 0 for no limit) |
|
|
47
47
|
| `-l`, `--list-keys` | List found citation keys and exit (no fetching) |
|
|
48
48
|
| `--fresh` | Ignore existing output file and start from scratch |
|
|
49
49
|
| `--ads-api-key` | ADS API key (overrides `ADS_API_KEY` environment variable) |
|
|
50
|
+
| `--config` | Path to config file (default: `~/.easybib.config`) |
|
|
50
51
|
|
|
51
52
|
### Examples
|
|
52
53
|
|
|
53
54
|
```bash
|
|
54
55
|
# Scan a directory
|
|
55
|
-
easybib ./paper -
|
|
56
|
+
easybib ./paper --preferred-source inspire
|
|
56
57
|
|
|
57
58
|
# Scan a single file
|
|
58
59
|
easybib paper.tex
|
|
@@ -67,6 +68,34 @@ easybib ./paper -l
|
|
|
67
68
|
easybib ./paper -a 0
|
|
68
69
|
```
|
|
69
70
|
|
|
71
|
+
### Config file
|
|
72
|
+
|
|
73
|
+
You can create a config file at `~/.easybib.config` to set persistent defaults, so you don't have to pass the same flags every time:
|
|
74
|
+
|
|
75
|
+
```ini
|
|
76
|
+
[easybib]
|
|
77
|
+
output = references.bib
|
|
78
|
+
max-authors = 3
|
|
79
|
+
preferred-source = ads
|
|
80
|
+
ads-api-key = your-key-here
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
All fields are optional. CLI flags override config file values, which override the built-in defaults.
|
|
84
|
+
|
|
85
|
+
To use a config file at a different location:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
easybib ./paper --config /path/to/my.config
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Source selection
|
|
92
|
+
|
|
93
|
+
The `--preferred-source` flag controls where BibTeX entries are fetched from. The source determines which service provides the BibTeX data, regardless of the key format used in your `.tex` files.
|
|
94
|
+
|
|
95
|
+
- **`ads`** (default) — Fetches BibTeX from ADS. If you use an INSPIRE-style key (e.g. `Author:2020abc`), easybib will cross-reference it via INSPIRE to find the corresponding ADS record, then pull the BibTeX from ADS. Falls back to INSPIRE if ADS lookup fails.
|
|
96
|
+
- **`inspire`** — Fetches BibTeX from INSPIRE. Falls back to ADS if the INSPIRE lookup fails. Does not require an ADS API key unless the fallback is triggered.
|
|
97
|
+
- **`auto`** — Chooses the source based on the key format: ADS bibcodes (e.g. `2016PhRvL.116f1102A`) are fetched from ADS, while INSPIRE-style keys are fetched from INSPIRE. Falls back to the other source if the preferred one fails.
|
|
98
|
+
|
|
70
99
|
### ADS API key
|
|
71
100
|
|
|
72
101
|
When using ADS as the source (the default), provide your API key either via the command line:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
easybib/__init__.py,sha256=zCCoB5obi_21h_a_5LK-Zr4G3VkO6XF6Yft5J8pqruU,721
|
|
2
|
+
easybib/__main__.py,sha256=91xpHXOEBRWH-6SL2xquZoAsyDHasxiEPpCK62izpnU,90
|
|
3
|
+
easybib/cli.py,sha256=Klf-LDAyOWTG8YPWt7l2n2syZQ6MhKQ1gHFF7dKtGcU,6172
|
|
4
|
+
easybib/core.py,sha256=OvXeVF_jV3FZlrdtcztxlbU4tCnN0Voei3luJPe3V_8,10066
|
|
5
|
+
easybib-0.3.0.dist-info/METADATA,sha256=AcjxKqd8nOU6xjc1uS6eZ-3Py_Pb_5Mijo_6Qem_IUQ,4428
|
|
6
|
+
easybib-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
+
easybib-0.3.0.dist-info/entry_points.txt,sha256=IHBiLzF5bW19fQOGvK3e1LKnGcYIL81icdGsvrvZ_Zs,45
|
|
8
|
+
easybib-0.3.0.dist-info/top_level.txt,sha256=Xi0IA9fNmv68UPp2bZCEEIXiQYQy0NweD0J9iqZ-LdQ,8
|
|
9
|
+
easybib-0.3.0.dist-info/RECORD,,
|
easybib-0.2.0.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
easybib/__init__.py,sha256=zCCoB5obi_21h_a_5LK-Zr4G3VkO6XF6Yft5J8pqruU,721
|
|
2
|
-
easybib/__main__.py,sha256=91xpHXOEBRWH-6SL2xquZoAsyDHasxiEPpCK62izpnU,90
|
|
3
|
-
easybib/cli.py,sha256=IBfiZaBgw_-ZqFiY_XzAeODipRdP6XnQJKyFkFRYFXo,4530
|
|
4
|
-
easybib/core.py,sha256=OvXeVF_jV3FZlrdtcztxlbU4tCnN0Voei3luJPe3V_8,10066
|
|
5
|
-
easybib-0.2.0.dist-info/METADATA,sha256=w9_tKSHjtc47nOBgNsDC8PK-6w1XURiHzGRh_Tm6uTY,2982
|
|
6
|
-
easybib-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
-
easybib-0.2.0.dist-info/entry_points.txt,sha256=IHBiLzF5bW19fQOGvK3e1LKnGcYIL81icdGsvrvZ_Zs,45
|
|
8
|
-
easybib-0.2.0.dist-info/top_level.txt,sha256=Xi0IA9fNmv68UPp2bZCEEIXiQYQy0NweD0J9iqZ-LdQ,8
|
|
9
|
-
easybib-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|