diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b1513f..61130ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,4 +56,4 @@ repos: rev: v0.4.2 hooks: - id: conda_envfile_parse - files: environment.yaml \ No newline at end of file + files: environment.yaml diff --git a/GooseBib/bibtex.py b/GooseBib/bibtex.py index cfb8a5b..56b1484 100644 --- a/GooseBib/bibtex.py +++ b/GooseBib/bibtex.py @@ -82,7 +82,6 @@ def read_display_order(bibtex_str: str, tabsize: int = 2) -> (dict, int): matches = list(re.finditer(r"(\@\w*\{)", bibtex_str, re.I)) for m in range(len(matches)): - i = matches[m].start() if m < len(matches) - 1: @@ -209,7 +208,6 @@ class MyBibTexParser(bibtexparser.bparser.BibTexParser): """ def __init__(self, *args, **kwargs): - kwargs.setdefault("homogenize_fields", True) kwargs.setdefault("ignore_nonstandard_types", True) kwargs.setdefault("add_missing_from_crossref", True) @@ -218,7 +216,6 @@ def __init__(self, *args, **kwargs): super().__init__(self, *args, **kwargs) def parse(self, bibtex_str, *args, **kwargs): - order, indent = read_display_order(bibtex_str, kwargs.pop("tabsize", 2)) data = bibtexparser.bparser.BibTexParser.parse(self, bibtex_str, *args, **kwargs) @@ -232,7 +229,6 @@ def parse(self, bibtex_str, *args, **kwargs): return data def __add__(self, other): - self.entries += other.entries self.comments += other.comments self.strings.update(other.strings) @@ -348,7 +344,6 @@ def select( fields = ret for entry in data: - select = fields[entry["ENTRYTYPE"]] if ensure_link: @@ -437,7 +432,6 @@ def _(data, *args, **kwargs) -> Tuple[str, dict]: def _merge(data: list[dict], iforward: ArrayLike, ibackward: ArrayLike, merge: bool) -> list[dict]: - if iforward.size == len(data): return data, {} @@ -609,7 +603,6 @@ def clever_merge(data: list[dict], merge: bool = True) -> list[dict]: @clever_merge.register(bibtexparser.bibdatabase.BibDatabase) def _(data: str, *args, **kwargs) -> bibtexparser.bibdatabase.BibDatabase: - d, merge = clever_merge(data.entries, *args, **kwargs) data.entries = d return data, merge @@ -656,7 +649,6 @@ def manual_merge(data: list[dict], keys: list[Tuple[str, str]]) -> Tuple[list[di @manual_merge.register(bibtexparser.bibdatabase.BibDatabase) def _(data: str, *args, **kwargs) -> Tuple[bibtexparser.bibdatabase.BibDatabase, dict]: - d, merge = manual_merge(data.entries, *args, **kwargs) data.entries = d return data, merge @@ -710,7 +702,6 @@ def clean( ignored_authors = [] for entry in data: - # find identifiers iden = get_identifiers(entry) for key in iden: @@ -904,7 +895,6 @@ def format_journal_arxiv( pattern = ["arxiv", "preprint", "submitted", "in preparation"] for entry in data: - if "doi" in entry: if not re.match(search, entry["doi"]): continue @@ -928,7 +918,6 @@ def format_journal_arxiv( break if len(journal_database) > 0: - revus = [] for entry in data: if "journal" in entry: @@ -1206,7 +1195,6 @@ def GbibClean(): # read input/output filepaths if args.in_place: - assert args.output is None assert not args.diff assert not args.force @@ -1216,7 +1204,6 @@ def GbibClean(): assert all([os.path.isfile(i) for i in sourcepaths]) else: - if args.output is None: raise OSError("Specify --output STR") if os.path.isdir(args.output): @@ -1228,7 +1215,6 @@ def GbibClean(): outpaths = [args.output] if len(args.files) == 1: - filepath = args.files[0] if not os.path.isfile(filepath): raise OSError(f'"{filepath}" does not exist') @@ -1238,7 +1224,6 @@ def GbibClean(): parsed = MyBibTexParser().parse(text) data = parsed.entries else: - for filepath in args.files: if not os.path.isfile(filepath): raise OSError(f'"{filepath}" does not exist') @@ -1252,7 +1237,6 @@ def GbibClean(): is_unique = True if not args.force: - overwrite = [] for outpath in outpaths: @@ -1275,7 +1259,6 @@ def GbibClean(): # formatting for sourcepath, outpath in zip(sourcepaths, outpaths): - if sourcepath is not None: with open(sourcepath) as file: raw = file.read() @@ -1318,20 +1301,17 @@ def GbibClean(): # hand merge duplicates if args.merge: - data, merged = manual_merge(data, args.merge) # clever merge duplicates if args.unique: - data, m = clever_merge(data) merged = {**merged, **m} # rename keys if args.rename: - keys = [entry["ID"] for entry in data] for oldkey, newkey in args.rename: @@ -1347,7 +1327,6 @@ def GbibClean(): # write changed keys if args.unique: - newnames = {k: v for k, v in renamed.items()} for key in merged: @@ -1380,7 +1359,6 @@ def GbibClean(): yaml_dump(args.unique, merged, force=True) elif len(renamed) > 0: - merged = ", ".join([f'"{i}" -> "{renamed[i]}"' for i in renamed]) warnings.warn(f"Renaming conflicts, please check:\n{merged}", Warning) @@ -1399,7 +1377,6 @@ def GbibClean(): file.write(data) if args.diff is not None: - if args.diff_type.lower() == "raw": simple = raw elif args.diff_type.lower() == "plain": @@ -1550,7 +1527,6 @@ def dbsearch_arxiv( @dbsearch_arxiv.register(bibtexparser.bibdatabase.BibDatabase) def _(data: str, *args, **kwargs) -> bibtexparser.bibdatabase.BibDatabase: - return dbsearch_arxiv(data.entries, *args, **kwargs) diff --git a/GooseBib/cli/GbibCheckAuthors.py b/GooseBib/cli/GbibCheckAuthors.py index e01b3dc..87703ac 100644 --- a/GooseBib/cli/GbibCheckAuthors.py +++ b/GooseBib/cli/GbibCheckAuthors.py @@ -29,7 +29,6 @@ def reformatAuthor(text, sep=" "): - # skip authors that cannot be split in first and last name if len(text.split(",")) <= 1: return text @@ -63,7 +62,6 @@ def reformatAuthor(text, sep=" "): def replaceUnicode(text): - # NB list not exhaustive, please extend! match = [ ("ç", r"\c{c}"), @@ -97,7 +95,6 @@ def replaceUnicode(text): def main(): - # --------------------------------- parse command line arguments ------------------------------- # parse command-line options/arguments @@ -132,7 +129,6 @@ def main(): names = {} for entry in bib.entries: - # set author separation sep = "" diff --git a/GooseBib/cli/GbibCheckKeys.py b/GooseBib/cli/GbibCheckKeys.py index 6ad9c5c..dd7dfb2 100644 --- a/GooseBib/cli/GbibCheckKeys.py +++ b/GooseBib/cli/GbibCheckKeys.py @@ -28,7 +28,6 @@ def replaceUnicode(text): - match = [ ("ç", "c"), ("è", "e"), @@ -79,7 +78,6 @@ def replaceUnicode(text): def getPlainLastName(full_name): - last = full_name.split(",")[0] last = replaceUnicode(last) @@ -94,7 +92,6 @@ def getPlainLastName(full_name): def main(): - # parse command-line options/arguments # change keys to simplify implementation: # - remove leading "-" and "--" from options @@ -120,7 +117,6 @@ def main(): keys = [] for entry in bib.entries: - old_key = entry["ID"] new_key = entry["ID"] generated = False @@ -183,7 +179,6 @@ def main(): ntimes[new_key] += 1 for idx, (old_key, new_key, generated) in enumerate(keys): - if not generated: continue diff --git a/GooseBib/cli/GbibCheckLink.py b/GooseBib/cli/GbibCheckLink.py index 1f643f2..01326f8 100644 --- a/GooseBib/cli/GbibCheckLink.py +++ b/GooseBib/cli/GbibCheckLink.py @@ -27,7 +27,6 @@ def Error(msg, exit_code=1): - print(msg) sys.exit(exit_code) @@ -37,7 +36,6 @@ def Error(msg, exit_code=1): def urlExists(url): - request = requests.get(url) if request.status_code == 200: @@ -50,7 +48,6 @@ def urlExists(url): def main(): - # --------------------------------- parse command line arguments ------------------------------- # parse command-line options/arguments diff --git a/GooseBib/cli/GbibList.py b/GooseBib/cli/GbibList.py index 427cc81..0fcf773 100644 --- a/GooseBib/cli/GbibList.py +++ b/GooseBib/cli/GbibList.py @@ -27,7 +27,6 @@ def main(): - # --------------------------------- parse command line arguments ------------------------------- # parse command-line options/arguments @@ -59,7 +58,6 @@ def main(): # ------------- if args["journal"]: - out = [] for entry in bib.entries: diff --git a/GooseBib/cli/GbibParse.py b/GooseBib/cli/GbibParse.py index e45d0e1..b556320 100644 --- a/GooseBib/cli/GbibParse.py +++ b/GooseBib/cli/GbibParse.py @@ -29,7 +29,6 @@ def Error(msg, exit_code=1): - print(msg) sys.exit(exit_code) @@ -39,7 +38,6 @@ def Error(msg, exit_code=1): def main(): - # --------------------------------- parse command line arguments ------------------------------- # parse command-line options/arguments diff --git a/GooseBib/cli/GbibSelect.py b/GooseBib/cli/GbibSelect.py index c987bf5..6bcbaab 100644 --- a/GooseBib/cli/GbibSelect.py +++ b/GooseBib/cli/GbibSelect.py @@ -26,7 +26,6 @@ def Error(msg, exit_code=1): - print(msg) sys.exit(exit_code) @@ -36,7 +35,6 @@ def Error(msg, exit_code=1): def tex2cite(tex): - # extract keys from "cite" def extract(s): try: @@ -58,7 +56,6 @@ def extract(s): def main(): - # --------------------------------- parse command line arguments ------------------------------- # parse command-line options/arguments diff --git a/GooseBib/cli/GbibSelectAlias.py b/GooseBib/cli/GbibSelectAlias.py index 8b6c4fa..7d06360 100644 --- a/GooseBib/cli/GbibSelectAlias.py +++ b/GooseBib/cli/GbibSelectAlias.py @@ -35,7 +35,6 @@ def Error(msg, exit_code=1): - print(msg) sys.exit(exit_code) diff --git a/GooseBib/journals.py b/GooseBib/journals.py index 614e524..f04fcad 100644 --- a/GooseBib/journals.py +++ b/GooseBib/journals.py @@ -69,7 +69,6 @@ def __init__( index: list[int] = None, abbreviation_is_acronym: bool = False, ): - if index: assert name is None assert abbreviation is None @@ -229,7 +228,6 @@ class JournalList: """ def __init__(self, data: dict[Journal] | list[Journal] = None): - self.count = 0 if data is None: @@ -392,7 +390,6 @@ def tolist(self) -> list[dict]: ret = [] for i in range(np.max(self.index) + 1): - i = self.index == i e = Journal( variations=self.names[i], @@ -687,7 +684,6 @@ def generate_default(domain: str) -> dict[Journal]: domain = domain.lower() if domain == "physics": - # basic list from JabRef db = download_from_jabref("geology_physics", "geology_physics_variations") @@ -1088,7 +1084,6 @@ def generate_default(domain: str) -> dict[Journal]: ) elif domain == "mechanics": - db = download_from_jabref("mechanical") _database_merge( @@ -1228,7 +1223,6 @@ def generate_default(domain: str) -> dict[Journal]: ) elif domain == "pnas": - db = generate_default("physics") name = "Proceedings of the National Academy of Sciences" alias = "Proceedings of the National Academy of Sciences of the United States of America" @@ -1244,7 +1238,6 @@ def generate_default(domain: str) -> dict[Journal]: db[name].unique() elif domain == "pnas-usa": - db = generate_default("physics") name = "Proceedings of the National Academy of Sciences of the United States of America" alias = "Proceedings of the National Academy of Sciences" @@ -1260,7 +1253,6 @@ def generate_default(domain: str) -> dict[Journal]: db[name].unique() elif domain == "arxiv": - db = dict(arXiv=Journal(name="arXiv preprint", abbreviation="arXiv")) r = generate_default("physics") @@ -1361,7 +1353,6 @@ def load(*args: str) -> JournalList: db = [] for arg in args: - found = False name = arg.lower() @@ -1383,5 +1374,4 @@ def load(*args: str) -> JournalList: if __name__ == "__main__": - update_default() diff --git a/GooseBib/recognise.py b/GooseBib/recognise.py index 3a8ddae..cecb2e2 100644 --- a/GooseBib/recognise.py +++ b/GooseBib/recognise.py @@ -14,7 +14,6 @@ def doi() -> str: @doi.register(str) def _(*args) -> str: - match = [ ( re.compile(r"(.*)(http)(s?)(://)([^\s]*)(doi.org/)([^\s]*)(.*)", re.IGNORECASE), @@ -53,7 +52,6 @@ def _(*args) -> str: @doi.register(dict) def _(entry) -> str: - for key in ["doi"]: if key in entry: return doi(entry[key]) @@ -73,7 +71,6 @@ def arxivid() -> str: @arxivid.register(str) def _(*args) -> str: - match = [ ( re.compile( @@ -113,7 +110,6 @@ def _(*args) -> str: @arxivid.register(dict) def _(entry) -> str: - for key in ["arxivid", "eprint"]: if key in entry: return arxivid(entry[key]) diff --git a/tests/test_GbibClean.py b/tests/test_GbibClean.py index 7b8e0fe..bfa10e0 100644 --- a/tests/test_GbibClean.py +++ b/tests/test_GbibClean.py @@ -16,7 +16,6 @@ class Test_GooseBib(unittest.TestCase): """ def test_inplace(self): - source = os.path.join(dirname, "library_mendeley.bib") output = os.path.join(dirname, "output.bib") shutil.copy2(source, output) @@ -30,7 +29,6 @@ def test_inplace(self): data = yaml.load(file.read(), Loader=yaml.FullLoader) for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -42,7 +40,6 @@ def test_inplace(self): os.remove(output) def test_mendeley(self): - source = os.path.join(dirname, "library_mendeley.bib") output = os.path.join(dirname, "output.bib") data = os.path.join(dirname, "library.yaml") @@ -55,7 +52,6 @@ def test_mendeley(self): data = yaml.load(file.read(), Loader=yaml.FullLoader) for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -67,7 +63,6 @@ def test_mendeley(self): os.remove(output) def test_hidden_doi_arxiv(self): - source = os.path.join(dirname, "library_hidden_doi_arxiv.bib") output = os.path.join(dirname, "output.bib") data = os.path.join(dirname, "library.yaml") @@ -80,7 +75,6 @@ def test_hidden_doi_arxiv(self): data = yaml.load(file.read(), Loader=yaml.FullLoader) for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -92,7 +86,6 @@ def test_hidden_doi_arxiv(self): os.remove(output) def test_missing_doi_arxiv(self): - source = os.path.join(dirname, "library_missing_doi_arxiv.bib") output = os.path.join(dirname, "output.yaml") data = os.path.join(dirname, "library.yaml") @@ -122,7 +115,6 @@ def test_missing_doi_arxiv(self): os.remove(output) def test_arxiv_preprint(self): - source = os.path.join(dirname, "library_arxiv_preprint.bib") output = os.path.join(dirname, "output.bib") data = os.path.join(dirname, "library_arxiv_preprint.yaml") @@ -137,7 +129,6 @@ def test_arxiv_preprint(self): data = yaml.load(file.read(), Loader=yaml.FullLoader) for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -149,7 +140,6 @@ def test_arxiv_preprint(self): os.remove(output) def test_authorsep(self): - source = os.path.join(dirname, "library_mendeley.bib") output = os.path.join(dirname, "output.bib") data = os.path.join(dirname, "library.yaml") @@ -168,7 +158,6 @@ def test_authorsep(self): data[key]["author"] = data[key]["author"].replace("C.B.", "C. B.") for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -180,7 +169,6 @@ def test_authorsep(self): os.remove(output) def test_no_title(self): - source = os.path.join(dirname, "library_mendeley.bib") output = os.path.join(dirname, "output.bib") subprocess.check_output(["GbibClean", "-f", "--no-title", "-o", output, source]) @@ -194,7 +182,6 @@ def test_no_title(self): os.remove(output) def test_journalrename(self): - lookup = dict( official={ "IJSS": "International Journal of Solids and Structures", @@ -214,7 +201,6 @@ def test_journalrename(self): ) for key in lookup: - source = os.path.join(dirname, "library_mendeley.bib") output = os.path.join(dirname, "output.bib") data = os.path.join(dirname, "library.yaml") @@ -232,7 +218,6 @@ def test_journalrename(self): data["DeGeus2013"]["journal"] = lookup[key]["MRS"] for entry in bib.entries: - d = data[entry["ID"]] for key in d: @@ -245,5 +230,4 @@ def test_journalrename(self): if __name__ == "__main__": - unittest.main() diff --git a/tests/test_bibtex.py b/tests/test_bibtex.py index 32e159a..72b1401 100644 --- a/tests/test_bibtex.py +++ b/tests/test_bibtex.py @@ -9,7 +9,6 @@ class Test_bibtex(unittest.TestCase): """ def test_clever_merge(self): - text = """ @article{DeGeus2021, author = {De Geus, T.W.J}, @@ -79,5 +78,4 @@ def test_clever_merge(self): if __name__ == "__main__": - unittest.main() diff --git a/tests/test_journals.py b/tests/test_journals.py index 7273aa2..423b7d5 100644 --- a/tests/test_journals.py +++ b/tests/test_journals.py @@ -11,7 +11,6 @@ class Test_journals(unittest.TestCase): """ def test_Journal(self): - name = "name" abbreviation = "abbr" acronym = "acro" @@ -94,7 +93,6 @@ def test_Journal(self): self.assertEqual(assume, dict(entry)) def test_JournalList(self): - lst = bib.journals.JournalList() lst.names = np.array(["a", "b", "c", "a", "d"]) lst.index = np.array([0, 0, 3, 2, 2]) @@ -123,7 +121,6 @@ def test_JournalList(self): self.assertEqual(assume, [dict(i) for i in lst.tolist()]) def test_JournalList_no_force_first(self): - lst = bib.journals.JournalList() lst.names = np.array(["a", "b", "c", "a", "d"]) lst.index = np.array([0, 0, 3, 2, 2]) @@ -152,7 +149,6 @@ def test_JournalList_no_force_first(self): self.assertEqual(assume, [dict(i) for i in lst.tolist()]) def test_JournalList_map(self): - lst = bib.journals.JournalList() lst.names = np.array(["a", "b", "c", "a", "d"]) lst.index = np.array([0, 0, 3, 2, 2]) @@ -167,7 +163,6 @@ def test_JournalList_map(self): self.assertEqual(lst.map2acronym(["b", "foo", "d"]), ["a", "foo", "a"]) def test_JournalList_map_no_force_first(self): - lst = bib.journals.JournalList() lst.names = np.array(["a", "b", "c", "a", "d"]) lst.index = np.array([0, 0, 3, 2, 2]) @@ -182,7 +177,6 @@ def test_JournalList_map_no_force_first(self): self.assertEqual(lst.map2acronym(["b", "foo", "d"]), ["d", "foo", "d"]) def test_load(self): - variations = [ "Proc. Nat. Acad. Sci.", "Proc. Nat. Acad. Sci. U. S. A", @@ -212,5 +206,4 @@ def test_load(self): if __name__ == "__main__": - unittest.main() diff --git a/tests/test_recognise.py b/tests/test_recognise.py index e710b9a..2fcb4c3 100644 --- a/tests/test_recognise.py +++ b/tests/test_recognise.py @@ -9,7 +9,6 @@ class Test_recognise(unittest.TestCase): """ def test_doi(self): - doi = "10.1073/pnas.1906551116" self.assertEqual(doi, bib.recognise.doi(f"https://doi.org/{doi}")) self.assertEqual(doi, bib.recognise.doi(f"https://dx.doi.org/{doi}")) @@ -24,7 +23,6 @@ def test_doi(self): self.assertEqual(doi, bib.recognise.doi(f"doi:{doi}")) def test_arxiv(self): - arxivid = "1904.07635" self.assertEqual(arxivid, bib.recognise.arxivid(f"https://arxiv.org/abs/{arxivid}")) self.assertEqual(arxivid, bib.recognise.arxivid(*[f"https://arxiv.org/abs/{arxivid}"])) @@ -44,5 +42,4 @@ def test_arxiv(self): if __name__ == "__main__": - unittest.main() diff --git a/tests/test_reformat.py b/tests/test_reformat.py index 6c6e41a..d248471 100644 --- a/tests/test_reformat.py +++ b/tests/test_reformat.py @@ -9,7 +9,6 @@ class Test_reformat(unittest.TestCase): """ def test_abbreviate_firstname(self): - self.assertEqual( bib.reformat.abbreviate_firstname("de Geus, Thomas Willem Jan"), "de Geus, T. W. J.", @@ -83,31 +82,25 @@ def test_abbreviate_firstname(self): ) def test_protect_math(self): - simple = r"$\tau$" self.assertEqual(bib.reformat.protect_math(simple), simple) def test_rm_unicode(self): - simple = r"$de Geus, Tom$" self.assertEqual(bib.reformat.rm_unicode(simple), simple) def test_rm_accents(self): - self.assertEqual(bib.reformat.rm_accents("école"), "ecole") self.assertEqual(bib.reformat.rm_accents("École"), "Ecole") def test_name2key(self): - self.assertEqual(bib.reformat.name2key("de Geus, Tom"), "DeGeus") def test_page_range(self): - self.assertEqual(bib.reformat.number_range("1-6"), "1--6") self.assertEqual(bib.reformat.number_range("47–58"), "47--58") self.assertEqual(bib.reformat.number_range("100"), "100") if __name__ == "__main__": - unittest.main() diff --git a/tests/test_tex.py b/tests/test_tex.py index e248701..497ddd4 100644 --- a/tests/test_tex.py +++ b/tests/test_tex.py @@ -9,12 +9,10 @@ class Test_tex(unittest.TestCase): """ def test_list_cise(self): - key = "DeGeus2021" mytext = r"The authors of \cite{DeGeus2021} claim that ..." self.assertEqual(bib.tex.list_cite(mytext), [key]) if __name__ == "__main__": - unittest.main()