Skip to content

Commit

Permalink
pre-commit autoupdate (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Oct 23, 2023
1 parent 9ddd8af commit a09d2cf
Show file tree
Hide file tree
Showing 17 changed files with 1 addition and 96 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ repos:
rev: v0.4.2
hooks:
- id: conda_envfile_parse
files: environment.yaml
files: environment.yaml
24 changes: 0 additions & 24 deletions GooseBib/bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -348,7 +344,6 @@ def select(
fields = ret

for entry in data:

select = fields[entry["ENTRYTYPE"]]

if ensure_link:
Expand Down Expand Up @@ -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, {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -710,7 +702,6 @@ def clean(
ignored_authors = []

for entry in data:

# find identifiers
iden = get_identifiers(entry)
for key in iden:
Expand Down Expand Up @@ -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
Expand All @@ -928,7 +918,6 @@ def format_journal_arxiv(
break

if len(journal_database) > 0:

revus = []
for entry in data:
if "journal" in entry:
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -1252,7 +1237,6 @@ def GbibClean():
is_unique = True

if not args.force:

overwrite = []

for outpath in outpaths:
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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":
Expand Down Expand Up @@ -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)


Expand Down
4 changes: 0 additions & 4 deletions GooseBib/cli/GbibCheckAuthors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,7 +62,6 @@ def reformatAuthor(text, sep=" "):


def replaceUnicode(text):

# NB list not exhaustive, please extend!
match = [
("ç", r"\c{c}"),
Expand Down Expand Up @@ -97,7 +95,6 @@ def replaceUnicode(text):


def main():

# --------------------------------- parse command line arguments -------------------------------

# parse command-line options/arguments
Expand Down Expand Up @@ -132,7 +129,6 @@ def main():
names = {}

for entry in bib.entries:

# set author separation
sep = ""

Expand Down
5 changes: 0 additions & 5 deletions GooseBib/cli/GbibCheckKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


def replaceUnicode(text):

match = [
("ç", "c"),
("è", "e"),
Expand Down Expand Up @@ -79,7 +78,6 @@ def replaceUnicode(text):


def getPlainLastName(full_name):

last = full_name.split(",")[0]

last = replaceUnicode(last)
Expand All @@ -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
Expand All @@ -120,7 +117,6 @@ def main():
keys = []

for entry in bib.entries:

old_key = entry["ID"]
new_key = entry["ID"]
generated = False
Expand Down Expand Up @@ -183,7 +179,6 @@ def main():
ntimes[new_key] += 1

for idx, (old_key, new_key, generated) in enumerate(keys):

if not generated:
continue

Expand Down
3 changes: 0 additions & 3 deletions GooseBib/cli/GbibCheckLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


def Error(msg, exit_code=1):

print(msg)

sys.exit(exit_code)
Expand All @@ -37,7 +36,6 @@ def Error(msg, exit_code=1):


def urlExists(url):

request = requests.get(url)

if request.status_code == 200:
Expand All @@ -50,7 +48,6 @@ def urlExists(url):


def main():

# --------------------------------- parse command line arguments -------------------------------

# parse command-line options/arguments
Expand Down
2 changes: 0 additions & 2 deletions GooseBib/cli/GbibList.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


def main():

# --------------------------------- parse command line arguments -------------------------------

# parse command-line options/arguments
Expand Down Expand Up @@ -59,7 +58,6 @@ def main():
# -------------

if args["journal"]:

out = []

for entry in bib.entries:
Expand Down
2 changes: 0 additions & 2 deletions GooseBib/cli/GbibParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


def Error(msg, exit_code=1):

print(msg)

sys.exit(exit_code)
Expand All @@ -39,7 +38,6 @@ def Error(msg, exit_code=1):


def main():

# --------------------------------- parse command line arguments -------------------------------

# parse command-line options/arguments
Expand Down
3 changes: 0 additions & 3 deletions GooseBib/cli/GbibSelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


def Error(msg, exit_code=1):

print(msg)

sys.exit(exit_code)
Expand All @@ -36,7 +35,6 @@ def Error(msg, exit_code=1):


def tex2cite(tex):

# extract keys from "cite"
def extract(s):
try:
Expand All @@ -58,7 +56,6 @@ def extract(s):


def main():

# --------------------------------- parse command line arguments -------------------------------

# parse command-line options/arguments
Expand Down
1 change: 0 additions & 1 deletion GooseBib/cli/GbibSelectAlias.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@


def Error(msg, exit_code=1):

print(msg)

sys.exit(exit_code)
Expand Down
Loading

0 comments on commit a09d2cf

Please sign in to comment.