bib-optimizer 0.3.5__tar.gz → 0.4.0__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.
- {bib_optimizer-0.3.5/src/bib_optimizer.egg-info → bib_optimizer-0.4.0}/PKG-INFO +11 -18
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/README.md +10 -17
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/pyproject.toml +2 -2
- bib_optimizer-0.4.0/src/bib_optimizer/__init__.py +2 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer/__main__.py +1 -1
- bib_optimizer-0.4.0/src/bib_optimizer/helpers.py +68 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0/src/bib_optimizer.egg-info}/PKG-INFO +11 -18
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer.egg-info/SOURCES.txt +1 -0
- bib_optimizer-0.3.5/src/bib_optimizer/__init__.py +0 -2
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/LICENSE +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/MANIFEST.in +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/setup.cfg +0 -0
- /bib_optimizer-0.3.5/src/bib_optimizer/helpers.py → /bib_optimizer-0.4.0/src/bib_optimizer/helpers_old.py +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer.egg-info/dependency_links.txt +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer.egg-info/entry_points.txt +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer.egg-info/requires.txt +0 -0
- {bib_optimizer-0.3.5 → bib_optimizer-0.4.0}/src/bib_optimizer.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bib_optimizer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Clean and optimize bib file.
|
|
5
5
|
Author-email: Ka Wa Yip <yipkawa@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -53,7 +53,7 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
53
53
|
Dynamic: license-file
|
|
54
54
|
|
|
55
55
|
<figure>
|
|
56
|
-
<img src="logo.png" alt="logo" height="143" />
|
|
56
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/logo.png?raw=True" alt="logo" height="143" />
|
|
57
57
|
<!-- <figcaption>An elephant at sunset</figcaption> -->
|
|
58
58
|
</figure>
|
|
59
59
|
|
|
@@ -122,21 +122,14 @@ _🐍 This requires Python 3.8 or newer versions_
|
|
|
122
122
|
|
|
123
123
|
You may test the installation using the sample input files (`sample_main.tex` and `sample_ref.bib`) located in the test folder.
|
|
124
124
|
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
<figure>
|
|
135
|
-
<img src="sample_ref_opt_shot.png" alt="sample_ref_opt_shot" height="199" />
|
|
136
|
-
<figcaption>
|
|
137
|
-
<i>A sample <code>ref_opt.bib</code> after running
|
|
138
|
-
<code>bibopt sample_main.tex sample_ref.bib ref_opt.bib</code></i>
|
|
139
|
-
</figcaption>
|
|
140
|
-
</figure>
|
|
125
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_main_shot.png?raw=True" alt="sample_main_shot" height="200"/> <img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_shot.png?raw=True" alt="sample_ref_shot" height="200" />
|
|
126
|
+
|
|
127
|
+
_`sample_main.tex` and `sample_ref.bib`_
|
|
128
|
+
|
|
129
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_opt_shot.png?raw=True" alt="sample_ref_opt_shot" height="200" />
|
|
130
|
+
|
|
131
|
+
_A sample `ref_opt.bib` after running `bibopt sample_main.tex sample_ref.bib ref_opt.bib`_
|
|
132
|
+
|
|
133
|
+
---
|
|
141
134
|
|
|
142
135
|
♥ Lastly executed on Python `3.10` on 2025-04-16.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<figure>
|
|
2
|
-
<img src="logo.png" alt="logo" height="143" />
|
|
2
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/logo.png?raw=True" alt="logo" height="143" />
|
|
3
3
|
<!-- <figcaption>An elephant at sunset</figcaption> -->
|
|
4
4
|
</figure>
|
|
5
5
|
|
|
@@ -68,21 +68,14 @@ _🐍 This requires Python 3.8 or newer versions_
|
|
|
68
68
|
|
|
69
69
|
You may test the installation using the sample input files (`sample_main.tex` and `sample_ref.bib`) located in the test folder.
|
|
70
70
|
|
|
71
|
-
<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
<figure>
|
|
81
|
-
<img src="sample_ref_opt_shot.png" alt="sample_ref_opt_shot" height="199" />
|
|
82
|
-
<figcaption>
|
|
83
|
-
<i>A sample <code>ref_opt.bib</code> after running
|
|
84
|
-
<code>bibopt sample_main.tex sample_ref.bib ref_opt.bib</code></i>
|
|
85
|
-
</figcaption>
|
|
86
|
-
</figure>
|
|
71
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_main_shot.png?raw=True" alt="sample_main_shot" height="200"/> <img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_shot.png?raw=True" alt="sample_ref_shot" height="200" />
|
|
72
|
+
|
|
73
|
+
_`sample_main.tex` and `sample_ref.bib`_
|
|
74
|
+
|
|
75
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_opt_shot.png?raw=True" alt="sample_ref_opt_shot" height="200" />
|
|
76
|
+
|
|
77
|
+
_A sample `ref_opt.bib` after running `bibopt sample_main.tex sample_ref.bib ref_opt.bib`_
|
|
78
|
+
|
|
79
|
+
---
|
|
87
80
|
|
|
88
81
|
♥ Lastly executed on Python `3.10` on 2025-04-16.
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "bib_optimizer"
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "0.4.0"
|
|
10
10
|
description = "Clean and optimize bib file."
|
|
11
11
|
authors = [
|
|
12
12
|
{ name="Ka Wa Yip", email="yipkawa@gmail.com" },
|
|
@@ -40,7 +40,7 @@ dev = ["black", "bumpver", "isort", "mypy", "pytest"]
|
|
|
40
40
|
bibopt = "bib_optimizer.__main__:main"
|
|
41
41
|
|
|
42
42
|
[tool.bumpver]
|
|
43
|
-
current_version = "0.
|
|
43
|
+
current_version = "0.4.0"
|
|
44
44
|
version_pattern = "MAJOR.MINOR.PATCH"
|
|
45
45
|
commit_message = "bump version {old_version} -> {new_version}"
|
|
46
46
|
commit = true
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import bibtexparser
|
|
2
|
+
import re
|
|
3
|
+
from bibtexparser.bwriter import BibTexWriter
|
|
4
|
+
|
|
5
|
+
def _augment_func(filecontent, all_keys, temp_citations):
|
|
6
|
+
for e in re.findall(r'\\cite[tp]?\{([^}]+)\}', filecontent):
|
|
7
|
+
for c in e.split(','):
|
|
8
|
+
c = c.strip()
|
|
9
|
+
if c not in temp_citations:
|
|
10
|
+
all_keys.append(c)
|
|
11
|
+
temp_citations.add(c)
|
|
12
|
+
|
|
13
|
+
return all_keys, temp_citations
|
|
14
|
+
|
|
15
|
+
def bib_opt(filename, input_bib, output_bib):
|
|
16
|
+
with open(filename, 'r', encoding='utf-8') as file:
|
|
17
|
+
lines = file.readlines()
|
|
18
|
+
filtered_lines = [line for line in lines if not line.lstrip().startswith('%')]
|
|
19
|
+
filecontent = ''.join(filtered_lines)
|
|
20
|
+
|
|
21
|
+
with open(input_bib, 'r', encoding='utf-8') as bibfile:
|
|
22
|
+
bib_database = bibtexparser.load(bibfile)
|
|
23
|
+
|
|
24
|
+
allowed_keys = []
|
|
25
|
+
all_keys = []
|
|
26
|
+
temp_citations = set()
|
|
27
|
+
|
|
28
|
+
split_pattern = r'(.*?)(\\input[^\n]*\n)(.*?)((?=\\input)|\Z)'
|
|
29
|
+
matches = re.findall(split_pattern, filecontent, flags=re.DOTALL)
|
|
30
|
+
split_results = [(before, after.strip()) for before, input_line, after, _ in matches]
|
|
31
|
+
|
|
32
|
+
input_pattern_extended = r'\\input\s*(?:{([^}]+)}|([^\s\n]+))'
|
|
33
|
+
matches = re.findall(input_pattern_extended, filecontent)
|
|
34
|
+
input_files_extended = [m[0] if m[0] else m[1] for m in matches]
|
|
35
|
+
|
|
36
|
+
if not split_results:
|
|
37
|
+
all_keys, temp_citations = _augment_func(filecontent, all_keys, temp_citations)
|
|
38
|
+
else:
|
|
39
|
+
for split_result, input_file_extended in zip(split_results, input_files_extended):
|
|
40
|
+
all_keys, temp_citations = _augment_func(split_result[0], all_keys, temp_citations)
|
|
41
|
+
|
|
42
|
+
if ".tex" not in input_file_extended:
|
|
43
|
+
input_file_extended += ".tex"
|
|
44
|
+
|
|
45
|
+
with open(input_file_extended, 'r', encoding='utf-8') as file:
|
|
46
|
+
_lines = file.readlines()
|
|
47
|
+
|
|
48
|
+
_filtered_lines = [line for line in _lines if not line.lstrip().startswith('%')]
|
|
49
|
+
_filecontent = ''.join(_filtered_lines)
|
|
50
|
+
|
|
51
|
+
all_keys, temp_citations = _augment_func(_filecontent, all_keys, temp_citations)
|
|
52
|
+
all_keys, temp_citations = _augment_func(split_result[1], all_keys, temp_citations)
|
|
53
|
+
|
|
54
|
+
for k in all_keys:
|
|
55
|
+
allowed_keys.append(k)
|
|
56
|
+
|
|
57
|
+
entry_dict = {entry.get('ID'): entry for entry in bib_database.entries}
|
|
58
|
+
filtered_entries = [entry_dict[key] for key in allowed_keys if key in entry_dict]
|
|
59
|
+
|
|
60
|
+
writer = BibTexWriter()
|
|
61
|
+
writer.indent = ' '
|
|
62
|
+
writer.order_entries_by = None
|
|
63
|
+
|
|
64
|
+
new_bib_database = bibtexparser.bibdatabase.BibDatabase()
|
|
65
|
+
new_bib_database.entries = filtered_entries
|
|
66
|
+
|
|
67
|
+
with open(output_bib, 'w', encoding='utf-8') as bibfile:
|
|
68
|
+
bibfile.write(writer.write(new_bib_database))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bib_optimizer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Clean and optimize bib file.
|
|
5
5
|
Author-email: Ka Wa Yip <yipkawa@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -53,7 +53,7 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
53
53
|
Dynamic: license-file
|
|
54
54
|
|
|
55
55
|
<figure>
|
|
56
|
-
<img src="logo.png" alt="logo" height="143" />
|
|
56
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/logo.png?raw=True" alt="logo" height="143" />
|
|
57
57
|
<!-- <figcaption>An elephant at sunset</figcaption> -->
|
|
58
58
|
</figure>
|
|
59
59
|
|
|
@@ -122,21 +122,14 @@ _🐍 This requires Python 3.8 or newer versions_
|
|
|
122
122
|
|
|
123
123
|
You may test the installation using the sample input files (`sample_main.tex` and `sample_ref.bib`) located in the test folder.
|
|
124
124
|
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
<figure>
|
|
135
|
-
<img src="sample_ref_opt_shot.png" alt="sample_ref_opt_shot" height="199" />
|
|
136
|
-
<figcaption>
|
|
137
|
-
<i>A sample <code>ref_opt.bib</code> after running
|
|
138
|
-
<code>bibopt sample_main.tex sample_ref.bib ref_opt.bib</code></i>
|
|
139
|
-
</figcaption>
|
|
140
|
-
</figure>
|
|
125
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_main_shot.png?raw=True" alt="sample_main_shot" height="200"/> <img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_shot.png?raw=True" alt="sample_ref_shot" height="200" />
|
|
126
|
+
|
|
127
|
+
_`sample_main.tex` and `sample_ref.bib`_
|
|
128
|
+
|
|
129
|
+
<img src="https://github.com/kwyip/bib_optimizer/blob/main/sample_ref_opt_shot.png?raw=True" alt="sample_ref_opt_shot" height="200" />
|
|
130
|
+
|
|
131
|
+
_A sample `ref_opt.bib` after running `bibopt sample_main.tex sample_ref.bib ref_opt.bib`_
|
|
132
|
+
|
|
133
|
+
---
|
|
141
134
|
|
|
142
135
|
♥ Lastly executed on Python `3.10` on 2025-04-16.
|
|
@@ -5,6 +5,7 @@ pyproject.toml
|
|
|
5
5
|
src/bib_optimizer/__init__.py
|
|
6
6
|
src/bib_optimizer/__main__.py
|
|
7
7
|
src/bib_optimizer/helpers.py
|
|
8
|
+
src/bib_optimizer/helpers_old.py
|
|
8
9
|
src/bib_optimizer.egg-info/PKG-INFO
|
|
9
10
|
src/bib_optimizer.egg-info/SOURCES.txt
|
|
10
11
|
src/bib_optimizer.egg-info/dependency_links.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|