bib-ami 0.0.1__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.
bib_ami/__init__.py ADDED
@@ -0,0 +1 @@
1
+
bib_ami/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
bib_ami/bib_ami.py ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env python3
2
+ """bib_ami: A tool to consolidate and clean BibTeX files.
3
+
4
+ This script merges all .bib files from a specified directory into a single output file.
5
+ Future versions will include deduplication, DOI validation, and metadata refreshing.
6
+ """
7
+
8
+ import argparse
9
+ import logging
10
+ from pathlib import Path
11
+
12
+ # Configure logging
13
+ logging.basicConfig(
14
+ level=logging.INFO,
15
+ format="%(asctime)s - %(levelname)s - %(message)s",
16
+ handlers=[logging.StreamHandler()]
17
+ )
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ def merge_bib_files(input_dir: str, output_file: str) -> None:
22
+ """Merge all .bib files from input_dir into a single output_file.
23
+
24
+ Args:
25
+ input_dir (str): Directory containing .bib files.
26
+ output_file (str): Path to the output .bib file.
27
+ """
28
+ input_path = Path(input_dir)
29
+ output_path = Path(output_file)
30
+
31
+ # Validate input directory
32
+ if not input_path.is_dir():
33
+ logger.error(f"Input directory '{input_dir}' does not exist or is not a directory.")
34
+ raise ValueError(f"Invalid input directory: {input_dir}")
35
+
36
+ # Find all .bib files
37
+ bib_files = list(input_path.glob("*.bib"))
38
+ if not bib_files:
39
+ logger.warning(f"No .bib files found in '{input_dir}'.")
40
+ return
41
+
42
+ logger.info(f"Found {len(bib_files)} .bib files in '{input_dir}'.")
43
+
44
+ # Merge files into output
45
+ with output_path.open("w", encoding="utf-8") as outfile:
46
+ for bib_file in bib_files:
47
+ logger.info(f"Processing '{bib_file}'...")
48
+ try:
49
+ with bib_file.open("r", encoding="utf-8") as infile:
50
+ content = infile.read()
51
+ outfile.write(content)
52
+ # Ensure a newline between files to avoid concatenation issues
53
+ outfile.write("\n\n")
54
+ except Exception as e:
55
+ logger.error(f"Failed to read '{bib_file}': {e}")
56
+ continue
57
+
58
+ logger.info(f"Successfully merged {len(bib_files)} files into '{output_file}'.")
59
+
60
+
61
+ # Placeholder for future functionality (commented out)
62
+ """
63
+ def deduplicate_bibtex(input_file: str) -> None:
64
+ # Placeholder for deduplication using bibtexparser
65
+ # Requires: pip install bibtexparser
66
+ pass
67
+
68
+ def validate_dois(input_file: str) -> None:
69
+ # Placeholder for DOI validation using CrossRef/DataCite APIs
70
+ # Requires: pip install requests
71
+ pass
72
+
73
+ def refresh_metadata(input_file: str, output_file: str) -> None:
74
+ # Placeholder for refreshing BibTeX metadata with API data
75
+ # Requires: pip install requests bibtexparser
76
+ pass
77
+ """
78
+
79
+
80
+ def main():
81
+ """Parse command-line arguments and run bib-ami."""
82
+ parser = argparse.ArgumentParser(
83
+ description="Merge BibTeX files from a directory into a single file."
84
+ )
85
+ parser.add_argument(
86
+ "--input-dir",
87
+ default=".",
88
+ help="Directory containing .bib files (default: current directory)."
89
+ )
90
+ parser.add_argument(
91
+ "--output-file",
92
+ default="output.bib",
93
+ help="Output file for merged BibTeX entries (default: output.bib)."
94
+ )
95
+ args = parser.parse_args()
96
+
97
+ try:
98
+ merge_bib_files(args.input_dir, args.output_file)
99
+ except Exception as e:
100
+ logger.error(f"Error during execution: {e}")
101
+ raise
102
+
103
+
104
+ if __name__ == "__main__":
105
+ main()
@@ -0,0 +1,23 @@
1
+ ### 5. License: `LICENSE`
2
+ ```text
3
+ MIT License
4
+
5
+ Copyright (c) 2025 Rolf Carlson
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.1
2
+ Name: bib-ami
3
+ Version: 0.0.1
4
+ Summary: A tool to merge and clean BibTeX files.
5
+ Home-page: https://github.com/hrolfrc/bib-ami
6
+ Author: Rolf Carlson
7
+ Author-email: hrolfrc@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # bib-ami
17
+
18
+ A Python tool to merge and clean BibTeX files. Currently, it consolidates all `.bib` files from a directory into a single output file. Future versions will include deduplication, DOI validation, and metadata refreshing.
19
+
20
+ ## Installation
21
+ ```bash
22
+ pip install bib-ami
@@ -0,0 +1,11 @@
1
+ bib_ami/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
2
+ bib_ami/_version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
3
+ bib_ami/bib_ami.py,sha256=8HdAdr_-bo3lBDVmPgiRT7Bkf-B0_vMBcOqFQX8-MP8,3321
4
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ tests/test_bib_ami.py,sha256=Y-IeU8QYBpg6zSubp4GyOQEJYJfMd9pgisUwVn-64DM,1318
6
+ bib_ami-0.0.1.dist-info/LICENSE,sha256=YTfBTmxz8N1tc3lyJP2QQpc9ln4B69aDvKDoUZxI2Pw,1102
7
+ bib_ami-0.0.1.dist-info/METADATA,sha256=sm3iN-h2s_qsqc7Mw3EUgxeGXw2Z-u5t7KXbqauo2HQ,720
8
+ bib_ami-0.0.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
9
+ bib_ami-0.0.1.dist-info/entry_points.txt,sha256=l_K00_9RbnTjThq_uwBbYj9rUXeAJ9vEh2heuPrR0AE,49
10
+ bib_ami-0.0.1.dist-info/top_level.txt,sha256=XApXpHvCsUKxSYpLsQmbSdaOa55fwHKQX2RL070x6g0,14
11
+ bib_ami-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.37.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bib-ami = bib_ami.bib_ami:main
@@ -0,0 +1,2 @@
1
+ bib_ami
2
+ tests
tests/__init__.py ADDED
File without changes
tests/test_bib_ami.py ADDED
@@ -0,0 +1,38 @@
1
+ import tempfile
2
+ from pathlib import Path
3
+
4
+ from bib_ami.bib_ami import merge_bib_files
5
+
6
+
7
+ # noinspection SpellCheckingInspection
8
+ def test_merge_bib_files():
9
+ # Create temporary directory and test .bib files
10
+ with tempfile.TemporaryDirectory() as tmpdirname:
11
+ # Create two sample .bib files
12
+ bib1 = Path(tmpdirname) / "test1.bib"
13
+ bib2 = Path(tmpdirname) / "test2.bib"
14
+ output = Path(tmpdirname) / "output.bib"
15
+
16
+ with bib1.open("w", encoding="utf-8") as f:
17
+ f.write("@article{test1, title={Test 1}}\n")
18
+ with bib2.open("w", encoding="utf-8") as f:
19
+ f.write("@article{test2, title={Test 2}}\n")
20
+
21
+ # Run merge
22
+ merge_bib_files(tmpdirname, str(output))
23
+
24
+ # Check output file exists and contains both entries
25
+ assert output.exists()
26
+ with output.open("r", encoding="utf-8") as f:
27
+ content = f.read()
28
+ assert "@article{test1" in content
29
+ assert "@article{test2" in content
30
+
31
+
32
+ # noinspection SpellCheckingInspection
33
+ def test_merge_bib_files_no_bib_files():
34
+ with tempfile.TemporaryDirectory() as tmpdirname:
35
+ output = Path(tmpdirname) / "output.bib"
36
+ merge_bib_files(tmpdirname, str(output))
37
+ # Should not fail, just log a warning
38
+ assert not output.exists()