Modify

Opened 3 years ago

Closed 3 years ago

#8593 closed defect (fixed)

Bib add error!

Reported by: anonymous Owned by: Amfortas
Priority: normal Component: TracBibPlugin
Severity: critical Keywords: BibAdd
Cc: kenric_lam@… Trac Release: 0.11

Description

I got the following error when I add the bibtex file :

Error: Macro BibAdd(attachment:test.bib) failed

local variable 's' referenced before assignment

Attachments (2)

test.bib (1.4 KB) - added by anonymous 3 years ago.
bibtexparse.diff (959 bytes) - added by Amfortas 3 years ago.
'%' is not a start of a comment in bibtex

Download all attachments as: .zip

Change History (39)

comment:1 Changed 3 years ago by Amfortas

Can you please attach the used bibtex file, because I can't reproduce the error with my bibtex files.

Changed 3 years ago by anonymous

comment:2 Changed 3 years ago by anonymous

Please find the attached bibtex file. I used several bibtex files and the errors are the same.

comment:3 follow-up: Changed 3 years ago by anonymous

Anyone resolved this issue?!

I have the same problem with any .bib file. I'm using this syntax:

BibAdd(attachment:test.bib)?

BibRef?

And I get over and over the same error that was mentioned at the top of this ticket report.

comment:4 in reply to: ↑ 3 Changed 3 years ago by kenric_lam@…

  • Severity changed from blocker to critical

Replying to anonymous:

Anyone resolved this issue?!

I have the same problem with any .bib file. I'm using this syntax:

BibAdd(attachment:test.bib)?

BibRef?

And I get over and over the same error that was mentioned at the top of this ticket report.

Your error is not the same. It seems that you haven't enable the plugin. I found that my problem is due to unsupported characters in the url field.

comment:5 in reply to: ↑ description Changed 3 years ago by falkb

Replying to anonymous:

local variable 's' referenced before assignment

Looks like a trivial problem of variable scope. Switch on DEBUG log level and post the appropriate logging. Then the chance for a patch increases. P.S.: First, I thought it's a plugin for adding bible psalms to the wiki :)

comment:6 Changed 3 years ago by anonymous

Sorry,

my explanation was bad. The error I have is:

Error: Macro BibAdd(attachment:test.bib) failed
local variable 's' referenced before assignment

and I had correctly enable the plugin ....

comment:7 Changed 3 years ago by anonymous

Hi again,

I use the DEBUG log level as previously suggested and I'm get the following output in log file:

2012-01-05 11:45:08,224 Trac[formatter] DEBUG: Executing Wiki macro BibAdd by provider <tracbib.tracbib.BibAddMacro object at 0x102a6d910>
2012-01-05 11:45:08,225 Trac[attachment] DEBUG: Trying to open attachment at /Users/ejmp/Documents/publish/trac/projects/PhDKnowledgeCluster/attachments/wiki/WikiStart/test.bib
2012-01-05 11:45:08,333 Trac[formatter] ERROR: Macro BibAdd(attachment:test.bib) failed:
Traceback (most recent call last):
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 717, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 304, in process
    text = self.processor(text)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 291, in _macro_processor
    text)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 209, in expand_macro
    entries = extract_entries(u)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 123, in extract_entries
    strings,bibdb=bibtexparse.bibtexload(text.splitlines())
  File "build/bdist.macosx-10.6-universal/egg/tracbib/bibtexparse.py", line 356, in bibtexload
    s+= start + 1
UnboundLocalError: local variable 's' referenced before assignment
2012-01-05 11:45:08,340 Trac[formatter] DEBUG: Executing Wiki macro BibRef by provider <tracbib.tracbib.BibRefMacro object at 0x102a6d9d0>

Any help would be appreciated.

Thanks in advance.

comment:8 follow-up: Changed 3 years ago by falkb

yep, trivial. The called function must initialize s and e with 0 at the beginning.

comment:9 in reply to: ↑ 8 Changed 3 years ago by anonymous

Replying to falkb:

yep, trivial. The called function must initialize s and e with 0 at the beginning.

I suppose that the called function is bibtexload() in bibtexparse.py. I initialized s and e variables to 0, as you say, such as:

#
# Find entries
#
strings=[]
preamble=[]
comment=[]
entries={}
start= 0
s= 0
e= 0

before the while cycle. I compiled the egg file again with

python setup.py bdist_egg

and update the plugin inside my trac environment, but the problem remains ...

Any idea?

comment:10 Changed 3 years ago by anonymous

really restarted Trac? Apache restarted?

comment:11 follow-up: Changed 3 years ago by Amfortas

  • Resolution set to fixed
  • Status changed from new to closed

Thanks for the contribution. r11111 should contain the fixed code.

comment:12 Changed 3 years ago by falkb

cool revision

comment:13 in reply to: ↑ 11 ; follow-ups: Changed 3 years ago by anonymous

Replying to Amfortas:

Thanks for the contribution. r11111 should contain the fixed code.

Hi again,

well, I update this plugin with the final revision, run again python setup.py bdist_egg and update the final .egg file TracBib-Snapshot-py2.6.egg in the plugin directory of my trac environment. However, I get exactly the same error ....

Any idea?

PS: the log output is:

2012-01-06 10:17:59,678 Trac[formatter] DEBUG: Executing Wiki macro BibAdd by provider <tracbib.tracbib.BibAddMacro object at 0x101fcacd0>
2012-01-06 10:17:59,680 Trac[attachment] DEBUG: Trying to open attachment at /Users/ejmp/Documents/publish/trac/projects/PhDKnowledgeCluster/attachments/wiki/references/bibliography/test.bib
2012-01-06 10:17:59,731 Trac[formatter] ERROR: Macro BibAdd(attachment:test.bib) failed:
Traceback (most recent call last):
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 717, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 304, in process
    text = self.processor(text)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 291, in _macro_processor
    text)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 209, in expand_macro
    entries = extract_entries(u)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 123, in extract_entries
    strings,bibdb=bibtexparse.bibtexload(text.splitlines())
  File "build/bdist.macosx-10.6-universal/egg/tracbib/bibtexparse.py", line 356, in bibtexload
    s+= start + 1
UnboundLocalError: local variable 's' referenced before assignment
2012-01-06 10:17:59,732 Trac[formatter] DEBUG: Executing Wiki macro BibRef by provider <tracbib.tracbib.BibRefMacro object at 0x101fcad90>

comment:14 in reply to: ↑ 13 ; follow-up: Changed 3 years ago by falkb

Replying to anonymous:

well, I update this plugin with the final revision, run again python setup.py bdist_egg and update the final .egg file TracBib-Snapshot-py2.6.egg in the plugin directory of my trac environment. However, I get exactly the same error ....

As already said, it's not enough to copy the .egg file to the plugin dir. You must restart Trac or Apache, respectively. Also check the egg cache dirs and remove the .egg files of older plugin revisions.

comment:15 in reply to: ↑ 14 ; follow-up: Changed 3 years ago by anonymous

Replying to falkb:

Replying to anonymous:

well, I update this plugin with the final revision, run again python setup.py bdist_egg and update the final .egg file TracBib-Snapshot-py2.6.egg in the plugin directory of my trac environment. However, I get exactly the same error ....

As already said, it's not enough to copy the .egg file to the plugin dir. You must restart Trac or Apache, respectively. Also check the egg cache dirs and remove the .egg files of older plugin revisions.

I'm running trac in standalone mode and I already restart trac. I also remove older .egg files, but how I clean egg cache dirs?

comment:16 in reply to: ↑ 15 ; follow-up: Changed 3 years ago by falkb

Replying to anonymous:

but how I clean egg cache dirs?

For instance, my project dir has a subdir .egg-cache. Just remove them after stop and before start of trac.

comment:17 in reply to: ↑ 16 Changed 3 years ago by anonymous

Replying to falkb:

Replying to anonymous:

but how I clean egg cache dirs?

For instance, my project dir has a subdir .egg-cache. Just remove them after stop and before start of trac.

In my project dir I don't have any subdir for egg-cache. However, I found that in my user root directory there is created a directory named .python-eggs. I did what you said: remove it after stop and before start trac. But without success.

Any idea?

comment:18 follow-up: Changed 3 years ago by Amfortas

I'm not sure if trac 0.11 is having such a folder. In my case it was always enough to delete to copy the new egg and restarting. But make sure to run "clean" when building. I think I remember, that sometimes setup.py is not rebuilding everything.

I always run

python setup.py clean bdist_egg

comment:19 in reply to: ↑ 18 Changed 3 years ago by anonymous

Replying to Amfortas:

I'm not sure if trac 0.11 is having such a folder. In my case it was always enough to delete to copy the new egg and restarting. But make sure to run "clean" when building. I think I remember, that sometimes setup.py is not rebuilding everything.

I always run

python setup.py clean bdist_egg

In my project dir I don't have any subdir for egg-cache. However, I found that in my user root directory there is created a directory named .python-eggs. I did what you said: remove it after stop and before start trac. But without success.

Any idea?

comment:20 follow-up: Changed 3 years ago by anonymous

did you rebuild the egg this time with clean?

comment:21 in reply to: ↑ 20 Changed 3 years ago by anonymous

Replying to anonymous:

did you rebuild the egg this time with clean?

Yes, rebuild with clean ... clean .egg-cache dir ... and restart trac standalnoe server. I'm using trac v.0.12.2 and I try to build this plugin with version 0.12 and 0.13 ... but without success ....

The output error is the same, as well as the log error ....

comment:22 follow-up: Changed 3 years ago by falkb

What OS do you use? Do you install the .egg locally to your project or globally?

comment:23 in reply to: ↑ 22 Changed 3 years ago by anonymous

Replying to falkb:

What OS do you use? Do you install the .egg locally to your project or globally?

My OS is Mac OS X 10.6.8 ... the .egg was installed locally .. just for this project ... In the directory that I mentioned, in my user root directory, called .python-eggs everytime I run trac again, it's created the following cache .eggs:

drwxr-xr-x 3 root staff 102 Jan 6 11:21 Trac-0.12.2-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracAccountManager-0.3.2-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracFullBlogPlugin-0.1.1-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracMath-0.5-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracMenusPlugin-0.1.1-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracMindMapMacro-0.4-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracTags-0.6-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracWikiToPdfPlugin-2.3.1-py2.6.egg-tmp
drwxr-xr-x 3 root staff 102 Jan 6 11:21 TracWysiwyg-0.12.0.3-py2.6.egg-tmp

As you can see, there is no evidence for a temporary or cache for this plugin ...

comment:24 follow-up: Changed 3 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

i think i found the error, i need a few minutes for the patch.

But I think your bibtexfile contains errors, because otherwise i can't reproduce your problem.

comment:25 in reply to: ↑ 24 Changed 3 years ago by anonymous

Replying to anonymous:

i think i found the error, i need a few minutes for the patch.

But I think your bibtexfile contains errors, because otherwise i can't reproduce your problem.

Ok, I'm also checking my bib tex file ... but I use others and the same error maintains. For instance, I use the bib file provide in the beginning of this ticket ...

comment:26 Changed 3 years ago by Amfortas

Please apply attachment:bibtexparse.diff an report back.

And don't use the attached bibtexfile. The parserlibrary I am using is having problems parsing the url-field in this file.

Thanks

comment:27 follow-up: Changed 3 years ago by Amfortas

oha, the patch has absolutely no effect. I still have no clue.

comment:28 in reply to: ↑ 27 Changed 3 years ago by anonymous

Replying to Amfortas:

oha, the patch has absolutely no effect. I still have no clue.

An update ....

I was doing all these steps updating a backup of my environment ... so, of course, nothing changes ... Sorry for this stupid error ... I'm already apply these changes to the correct environment and I get the following error:

Error: Macro BibAdd(attachment:test2.bib) failed

'NoneType' object is not iterable

PS: I didn't update yet your last modification in the code that you made. I have to leave from my computer just for a few 30 minutes +-, so I will come back. Really thnaks for your help.

comment:29 in reply to: ↑ 13 Changed 3 years ago by falkb

Replying to anonymous:

File "build/bdist.macosx-10.6-universal/egg/tracbib/bibtexparse.py", line 356

UnboundLocalError: local variable 's' referenced before assignment

Your reported error still happens although you update to r11111. This means your Trac somehow uses a version of the plugin before r11111. I don't think the latest patch is necessary for the original problem.

comment:30 follow-up: Changed 3 years ago by Amfortas

The error now happening is, because of a problem in the parser. The parser can't handle the special-characters in the url-field in test.bib correct. Mabye I can have a look in it in the evening.

Changed 3 years ago by Amfortas

'%' is not a start of a comment in bibtex

comment:31 Changed 3 years ago by Amfortas

Now there is another patch in attachment:bibtexparse.diff.

The parser interpreted '%' as the start of a comment, but this is not supported in bibtex. So please try this new patch an report back. It worked for me on attachment:test.bib.

comment:32 in reply to: ↑ 30 Changed 3 years ago by anonymous

Replying to Amfortas:

The error now happening is, because of a problem in the parser. The parser can't handle the special-characters in the url-field in test.bib correct. Mabye I can have a look in it in the evening.

Yes, the log output is now:

2012-01-06 12:45:15,847 Trac[formatter] DEBUG: Executing Wiki macro BibAdd by provider <tracbib.tracbib.BibAddMacro object at 0x101fcbb10>
2012-01-06 12:45:15,850 Trac[attachment] DEBUG: Trying to open attachment at /Users/ejmp/Documents/publish/trac/projects/PhDKnowledgeCluster/attachments/wiki/references/bibliography/test.bib
2012-01-06 12:45:15,910 Trac[formatter] ERROR: Macro BibAdd(attachment:test.bib) failed:
Traceback (most recent call last):
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 717, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 304, in process
    text = self.processor(text)
  File "build/bdist.macosx-10.6-universal/egg/trac/wiki/formatter.py", line 291, in _macro_processor
    text)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 209, in expand_macro
    entries = extract_entries(u)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/tracbib.py", line 123, in extract_entries
    strings,bibdb=bibtexparse.bibtexload(text.splitlines())
  File "build/bdist.macosx-10.6-universal/egg/tracbib/bibtexparse.py", line 377, in bibtexload
    ff= get_fields(current)
  File "build/bdist.macosx-10.6-universal/egg/tracbib/bibtexparse.py", line 285, in get_fields
    s,e= match_pair(ss)
TypeError: 'NoneType' object is not iterable
2012-01-06 12:45:15,911 Trac[formatter] DEBUG: Executing Wiki macro BibRef by provider <tracbib.tracbib.BibRefMacro object at 0x101fcbbd0>

comment:33 follow-up: Changed 3 years ago by Amfortas

did you apply the patch attachmennt:bibtexparse.diff ? Because it should resolve exactly this issue.

Go to the folder where bibtexparse.py is located, copy bibtexparse.diff into it and run

patch < bibtexparse.diff

comment:34 in reply to: ↑ 33 ; follow-up: Changed 3 years ago by anonymous

Replying to Amfortas:

did you apply the patch attachmennt:bibtexparse.diff ? Because it should resolve exactly this issue.

Go to the folder where bibtexparse.py is located, copy bibtexparse.diff into it and run

patch < bibtexparse.diff

Ok, I get no errors now ... but I can't see anything. I using this piece of code:

[[BibAdd(attachment:test.bib)]]
[[BibRef]]

It's supposed to show the entire bibliography, right?

PS: I'm using your attached bibtex, but the output is the same with any bibtex file that I tried.

comment:35 in reply to: ↑ 34 ; follow-up: Changed 3 years ago by anonymous

Replying to anonymous:

Replying to Amfortas:

did you apply the patch attachmennt:bibtexparse.diff ? Because it should resolve exactly this issue.

Go to the folder where bibtexparse.py is located, copy bibtexparse.diff into it and run

patch < bibtexparse.diff

Ok, I get no errors now ... but I can't see anything. I using this piece of code:

[[BibAdd(attachment:test.bib)]]
[[BibRef]]

It's supposed to show the entire bibliography, right?

PS: I'm using your attached bibtex, but the output is the same with any bibtex file that I tried.

Ok, I see

[[BibRef]]

should rendered the cited articles. However, I'm having this problem:

Error: Macro BibAdd(!attachment:test.bib) failed

Unknown location '!attachment'

why?

comment:36 in reply to: ↑ 35 Changed 3 years ago by anonymous

Replying to anonymous:

Replying to anonymous:

Replying to Amfortas:

did you apply the patch attachmennt:bibtexparse.diff ? Because it should resolve exactly this issue.

Go to the folder where bibtexparse.py is located, copy bibtexparse.diff into it and run

patch < bibtexparse.diff

Ok, I get no errors now ... but I can't see anything. I using this piece of code:

[[BibAdd(attachment:test.bib)]]
[[BibRef]]

It's supposed to show the entire bibliography, right?

PS: I'm using your attached bibtex, but the output is the same with any bibtex file that I tried.

Ok, I see

[[BibRef]]

should rendered the cited articles. However, I'm having this problem:

Error: Macro BibAdd(!attachment:test.bib) failed

Unknown location '!attachment'

why?

Ok, thanks!!

Everything is OK now. I don't know why it inserts by itself and ! before attachment word.

Thanks a lot for your effort!!

comment:37 Changed 3 years ago by Amfortas

  • Resolution set to fixed
  • Status changed from reopened to closed

Glad I could help. Currently you can't show all articles at once, but you can use BibNoCite(key) if you want to see it in the References.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.