easybib 0.1.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 +66 -10
- easybib-0.3.0.dist-info/METADATA +122 -0
- easybib-0.3.0.dist-info/RECORD +9 -0
- easybib-0.1.0.dist-info/METADATA +0 -76
- easybib-0.1.0.dist-info/RECORD +0 -9
- {easybib-0.1.0.dist-info → easybib-0.3.0.dist-info}/WHEEL +0 -0
- {easybib-0.1.0.dist-info → easybib-0.3.0.dist-info}/entry_points.txt +0 -0
- {easybib-0.1.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,13 +15,54 @@ 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
|
)
|
|
20
|
-
parser.add_argument("directory", help="Directory containing LaTeX files")
|
|
21
55
|
parser.add_argument(
|
|
22
|
-
"
|
|
56
|
+
"--version", action="version", version=f"%(prog)s {__version__}"
|
|
57
|
+
)
|
|
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
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"-o", "--output", default="references.bib", help="Output BibTeX file (existing entries are retained)"
|
|
23
66
|
)
|
|
24
67
|
parser.add_argument(
|
|
25
68
|
"-a",
|
|
@@ -41,18 +84,31 @@ 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)",
|
|
48
91
|
)
|
|
92
|
+
parser.add_argument(
|
|
93
|
+
"--ads-api-key",
|
|
94
|
+
help="ADS API key (overrides ADS_API_KEY environment variable)",
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# Apply config file defaults (CLI flags will still override)
|
|
98
|
+
if config_defaults:
|
|
99
|
+
parser.set_defaults(**config_defaults)
|
|
100
|
+
|
|
49
101
|
args = parser.parse_args()
|
|
50
102
|
|
|
51
103
|
# Collect all citation keys
|
|
52
|
-
|
|
104
|
+
input_path = Path(args.path)
|
|
53
105
|
all_keys = set()
|
|
54
106
|
all_warnings = []
|
|
55
|
-
|
|
107
|
+
if input_path.is_file():
|
|
108
|
+
tex_files = [input_path]
|
|
109
|
+
else:
|
|
110
|
+
tex_files = input_path.glob("**/*.tex")
|
|
111
|
+
for tex_file in tex_files:
|
|
56
112
|
keys, warnings = extract_cite_keys(tex_file)
|
|
57
113
|
all_keys.update(keys)
|
|
58
114
|
all_warnings.extend(warnings)
|
|
@@ -72,12 +128,12 @@ def main():
|
|
|
72
128
|
print(key)
|
|
73
129
|
return 0
|
|
74
130
|
|
|
75
|
-
# Check for ADS API key (not required if using --source inspire)
|
|
76
|
-
api_key = os.getenv("ADS_API_KEY")
|
|
77
|
-
if not api_key and args.
|
|
131
|
+
# Check for ADS API key (not required if using --preferred-source inspire)
|
|
132
|
+
api_key = args.ads_api_key or os.getenv("ADS_API_KEY")
|
|
133
|
+
if not api_key and args.preferred_source != "inspire":
|
|
78
134
|
print("Error: ADS_API_KEY environment variable not set")
|
|
79
135
|
print("Get your API key from: https://ui.adsabs.harvard.edu/user/settings/token")
|
|
80
|
-
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)")
|
|
81
137
|
return 1
|
|
82
138
|
|
|
83
139
|
# Check for existing bib file and determine which keys to fetch
|
|
@@ -100,7 +156,7 @@ def main():
|
|
|
100
156
|
not_found = []
|
|
101
157
|
for key in sorted(keys_to_fetch):
|
|
102
158
|
print(f"Fetching {key}...", end=" ")
|
|
103
|
-
bibtex, source = fetch_bibtex(key, api_key, args.
|
|
159
|
+
bibtex, source = fetch_bibtex(key, api_key, args.preferred_source)
|
|
104
160
|
if bibtex:
|
|
105
161
|
bibtex = replace_bibtex_key(bibtex, key)
|
|
106
162
|
bibtex = truncate_authors(bibtex, args.max_authors)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: easybib
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Automatically fetch BibTeX entries from INSPIRE and ADS for LaTeX projects
|
|
5
|
+
Author-email: Gregory Ashton <gregory.ashton@ligo.org>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/GregoryAshton/easybib
|
|
8
|
+
Project-URL: Repository, https://github.com/GregoryAshton/easybib
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: requests
|
|
12
|
+
Provides-Extra: test
|
|
13
|
+
Requires-Dist: pytest; extra == "test"
|
|
14
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
15
|
+
|
|
16
|
+
# easybib
|
|
17
|
+
|
|
18
|
+
[](https://github.com/GregoryAshton/easybib/actions/workflows/tests.yml)
|
|
19
|
+
[](https://codecov.io/gh/GregoryAshton/easybib)
|
|
20
|
+
|
|
21
|
+
Automatically fetch BibTeX entries from [INSPIRE](https://inspirehep.net/) and [NASA/ADS](https://ui.adsabs.harvard.edu/) for LaTeX projects.
|
|
22
|
+
|
|
23
|
+
easybib scans your `.tex` files for citation keys, looks them up on INSPIRE and/or ADS, and writes a `.bib` file with the results. It handles INSPIRE texkeys (e.g. `Author:2020abc`) and ADS bibcodes (e.g. `2016PhRvL.116f1102A`).
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install easybib
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
easybib /path/to/latex/project
|
|
35
|
+
easybib paper.tex
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Pass a directory to scan all `.tex` files recursively, or a single `.tex` file. BibTeX entries are fetched and written to `references.bib`.
|
|
39
|
+
|
|
40
|
+
### Options
|
|
41
|
+
|
|
42
|
+
| Flag | Description |
|
|
43
|
+
|------|-------------|
|
|
44
|
+
| `-o`, `--output` | Output BibTeX file (default: `references.bib`) |
|
|
45
|
+
| `-s`, `--preferred-source` | Preferred source: `ads` (default), `inspire`, or `auto` |
|
|
46
|
+
| `-a`, `--max-authors` | Truncate author lists (default: 3, use 0 for no limit) |
|
|
47
|
+
| `-l`, `--list-keys` | List found citation keys and exit (no fetching) |
|
|
48
|
+
| `--fresh` | Ignore existing output file and start from scratch |
|
|
49
|
+
| `--ads-api-key` | ADS API key (overrides `ADS_API_KEY` environment variable) |
|
|
50
|
+
| `--config` | Path to config file (default: `~/.easybib.config`) |
|
|
51
|
+
|
|
52
|
+
### Examples
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Scan a directory
|
|
56
|
+
easybib ./paper --preferred-source inspire
|
|
57
|
+
|
|
58
|
+
# Scan a single file
|
|
59
|
+
easybib paper.tex
|
|
60
|
+
|
|
61
|
+
# Use a custom output file
|
|
62
|
+
easybib ./paper -o paper.bib
|
|
63
|
+
|
|
64
|
+
# List citation keys without fetching
|
|
65
|
+
easybib ./paper -l
|
|
66
|
+
|
|
67
|
+
# Keep all authors
|
|
68
|
+
easybib ./paper -a 0
|
|
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
|
+
|
|
99
|
+
### ADS API key
|
|
100
|
+
|
|
101
|
+
When using ADS as the source (the default), provide your API key either via the command line:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
easybib ./paper --ads-api-key your-key-here
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Or as an environment variable:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
export ADS_API_KEY="your-key-here"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Get a key from https://ui.adsabs.harvard.edu/user/settings/token.
|
|
114
|
+
|
|
115
|
+
## How it works
|
|
116
|
+
|
|
117
|
+
1. Scans `.tex` files for `\cite{...}`, `\citep{...}`, `\citet{...}`, and related commands
|
|
118
|
+
2. Filters for keys containing `:` (INSPIRE/ADS format)
|
|
119
|
+
3. Fetches BibTeX from the preferred source, with automatic fallback
|
|
120
|
+
4. Replaces citation keys to match those used in your `.tex` files
|
|
121
|
+
5. Truncates long author lists
|
|
122
|
+
6. Skips keys already present in the output file (use `--fresh` to override)
|
|
@@ -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.1.0.dist-info/METADATA
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: easybib
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Automatically fetch BibTeX entries from INSPIRE and ADS for LaTeX projects
|
|
5
|
-
Author-email: Gregory Ashton <gregory.ashton@ligo.org>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/GregoryAshton/easybib
|
|
8
|
-
Project-URL: Repository, https://github.com/GregoryAshton/easybib
|
|
9
|
-
Requires-Python: >=3.9
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: requests
|
|
12
|
-
|
|
13
|
-
# easybib
|
|
14
|
-
|
|
15
|
-
Automatically fetch BibTeX entries from [INSPIRE](https://inspirehep.net/) and [NASA/ADS](https://ui.adsabs.harvard.edu/) for LaTeX projects.
|
|
16
|
-
|
|
17
|
-
easybib scans your `.tex` files for citation keys, looks them up on INSPIRE and/or ADS, and writes a `.bib` file with the results. It handles INSPIRE texkeys (e.g. `Author:2020abc`) and ADS bibcodes (e.g. `2016PhRvL.116f1102A`).
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pip install easybib
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
easybib /path/to/latex/project
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
This will scan all `.tex` files in the directory, fetch BibTeX entries, and write them to `references.bib`.
|
|
32
|
-
|
|
33
|
-
### Options
|
|
34
|
-
|
|
35
|
-
| Flag | Description |
|
|
36
|
-
|------|-------------|
|
|
37
|
-
| `-o`, `--output` | Output BibTeX file (default: `references.bib`) |
|
|
38
|
-
| `-s`, `--source` | Preferred source: `ads` (default), `inspire`, or `auto` |
|
|
39
|
-
| `-a`, `--max-authors` | Truncate author lists (default: 3, use 0 for no limit) |
|
|
40
|
-
| `-l`, `--list-keys` | List found citation keys and exit (no fetching) |
|
|
41
|
-
| `--fresh` | Ignore existing output file and start from scratch |
|
|
42
|
-
|
|
43
|
-
### Examples
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# Fetch from INSPIRE (no API key needed)
|
|
47
|
-
easybib ./paper -s inspire
|
|
48
|
-
|
|
49
|
-
# Use a custom output file
|
|
50
|
-
easybib ./paper -o paper.bib
|
|
51
|
-
|
|
52
|
-
# List citation keys without fetching
|
|
53
|
-
easybib ./paper -l
|
|
54
|
-
|
|
55
|
-
# Keep all authors
|
|
56
|
-
easybib ./paper -a 0
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### ADS API key
|
|
60
|
-
|
|
61
|
-
When using ADS as the source (the default), set your API key:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
export ADS_API_KEY="your-key-here"
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Get one from https://ui.adsabs.harvard.edu/user/settings/token.
|
|
68
|
-
|
|
69
|
-
## How it works
|
|
70
|
-
|
|
71
|
-
1. Scans `.tex` files for `\cite{...}`, `\citep{...}`, `\citet{...}`, and related commands
|
|
72
|
-
2. Filters for keys containing `:` (INSPIRE/ADS format)
|
|
73
|
-
3. Fetches BibTeX from the preferred source, with automatic fallback
|
|
74
|
-
4. Replaces citation keys to match those used in your `.tex` files
|
|
75
|
-
5. Truncates long author lists
|
|
76
|
-
6. Skips keys already present in the output file (use `--fresh` to override)
|
easybib-0.1.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=nU6DC9IEyycbcjNd7hB7G4OBz4V7R12ETlQTlpdrBng,4237
|
|
4
|
-
easybib/core.py,sha256=OvXeVF_jV3FZlrdtcztxlbU4tCnN0Voei3luJPe3V_8,10066
|
|
5
|
-
easybib-0.1.0.dist-info/METADATA,sha256=Ia24a6a3E73u7LxTndNW9TIIkB3QxkGgIAMwbcbpdBc,2314
|
|
6
|
-
easybib-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
-
easybib-0.1.0.dist-info/entry_points.txt,sha256=IHBiLzF5bW19fQOGvK3e1LKnGcYIL81icdGsvrvZ_Zs,45
|
|
8
|
-
easybib-0.1.0.dist-info/top_level.txt,sha256=Xi0IA9fNmv68UPp2bZCEEIXiQYQy0NweD0J9iqZ-LdQ,8
|
|
9
|
-
easybib-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|