Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'group' #12

Open
inoue0426 opened this issue Oct 12, 2023 · 2 comments
Open

AttributeError: 'NoneType' object has no attribute 'group' #12

inoue0426 opened this issue Oct 12, 2023 · 2 comments

Comments

@inoue0426
Copy link

Hi,

I got this error, maybe related to parse error.

processing old revision
Traceback (most recent call last):
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/bin/latexdiffcite", line 8, in <module>
    sys.exit(main())
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/lib/python3.10/site-packages/latexdiffcite/latexdiffcite.py", line 163, in main
    run(parsed_args)
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/lib/python3.10/site-packages/latexdiffcite/latexdiffcite.py", line 296, in run
    process_revision('old')
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/lib/python3.10/site-packages/latexdiffcite/latexdiffcite.py", line 361, in process_revision
    read_bibfile(oldnew)
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/lib/python3.10/site-packages/latexdiffcite/latexdiffcite.py", line 481, in read_bibfile
    bibarg = find_bibliography_arg(getattr(FileContents, 'tex_' + oldnew))
  File "/Users/yoshitakainoue/.pyenv/versions/miniforge3-4.10.1-5/envs/py310/lib/python3.10/site-packages/latexdiffcite/latexdiffcite.py", line 496, in find_bibliography_arg
    bibfile = re.search(r'$[^%]*\\bibliography\s*{(.*?)}', s, flags=re.M).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Do you know how to fix this?

@tobiscode
Copy link

Hi,

this is a result of the regex search not finding any linked bibliography files in the tex file. This can be due to other commands being used to specify the bibliography files, e.g., \addbibresource instead of \bibliography.

One way out is to specify to use the BBL file directly using the --bbl option explicitly. latexdiffcite file -h is a bit ambiguous here, as the default is actually to not look for one, but setting it to the working directory should work.

The (in my opinion) better alternative is to fix the latexdiffcite.py script to simply look for those other commands. Here's what I changed in my local version to make everything work again, including with multiple files:

@@ -478,8 +478,9 @@ def read_bibfile(oldnew):
     '''Reads contents of bibtex files'''
     # get bibtex file
-    bibarg = find_bibliography_arg(getattr(FileContents, 'tex_' + oldnew))
-    find_bibfiles(bibarg, oldnew)
+    bibargs = find_bibliography_args(getattr(FileContents, 'tex_' + oldnew))
+    for bibarg in bibargs:
+        find_bibfiles(bibarg, oldnew)
     bibfiles = getattr(Files, 'bib_' + oldnew + '_path')
     # read bibtex files
@@ -489,13 +490,16 @@ def read_bibfile(oldnew):
             getattr(FileContents, 'bib_' + oldnew).append(f.read())
-def find_bibliography_arg(s):
+def find_bibliography_args(s):
     '''Looks through string for \bibliography{} command and retrieves the argument'''
+    bibfiles = []
     log.debug('searching for \\bibliography{} entry in tex file')
-    bibfile = re.search(r'$[^%]*\\bibliography\s*{(.*?)}', s, flags=re.M).group(1)
-    log.debug('bibliography argument found: %s', bibfile)
-    return bibfile
+    bibfiles.extend(re.findall(r'^\s*\\bibliography\s*{(.*?)}', s, flags=re.M))
+    log.debug('searching for \\addbibresource{} entries in tex file')
+    bibfiles.extend(re.findall(r'^\s*\\addbibresource\s*{(.*?)}', s, flags=re.M))
+    log.debug('bibliography arguments found: %s', str(bibfiles))
+    return bibfiles

Hope that helps! Happy to submit a PR if it's welcome @twilsonco @cmeeren .

Cheers

@twilsonco
Copy link
Owner

Thanks @tobiscode,

I agree the best approach is to modify the source to check for all applicable bibliography commands.

I’ll be using this tool again for some paper revisions soon, and will update things then.

A PR would be welcome since you already have the changes working.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants