wilsonyu2006 / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

Mutagen fails on homebrew (mac) and does not use the local checkout of the mutagen module #143

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Home brew downloads and puts mutagen inside /usr/local/Cellar and puts symlinks 
in /usr/local/bin

Invoking mid3v2 goes through the symlink /usr/local/bin/mid3v2 which causes 
python not to find the mutagen folder with your modules inside 
/usr/local/bin/mutagen. They are actually in 
/usr/local/Cellar/python-mutagen/<version>/mutagen.

So I propose the following. Consider the prolog found in all the public python 
scripts

try:
    import mutagen, mutagen.id3
except ImportError:
    # Run as ./mid3v2 out of tools/
    sys.path.append(os.path.abspath("../"))
    import mutagen, mutagen.id3

And replace with something like

script_path = os.path.dirname(os.path.realpath(__file__))
if os.path.basename(script_path) == 'tools':
    sys.path.insert(1, os.path.dirname(script_path))

import mutagen, mutagen.id3

This will also make the public scripts load the mutagen modules from the hg 
checkout (due to order of sys.path) if you already have a system wide 
installation.

Original issue reported on code.google.com by joao.ei...@gmail.com on 14 Apr 2013 at 4:36

GoogleCodeExporter commented 8 years ago

Original comment by joao.ei...@gmail.com on 14 Apr 2013 at 4:44

Attachments:

GoogleCodeExporter commented 8 years ago
Are you sure you load mid3v2 with the homebrew python?

Original comment by reiter.christoph@gmail.com on 14 Apr 2013 at 11:33

GoogleCodeExporter commented 8 years ago
No. I'm using the homebrew mutagen with the system python. I have not needed to 
install python with homebrew so far.

Original comment by joao.ei...@gmail.com on 15 Apr 2013 at 1:16

GoogleCodeExporter commented 8 years ago
But, the main problem is invoking tools/mid3v2 with a symlink, so can easily 
happen elsewhere.

Original comment by joao.ei...@gmail.com on 15 Apr 2013 at 1:17

GoogleCodeExporter commented 8 years ago
I'm not sure I understand. Why does accessing mid3v2 through a symlink change 
the module search path?

Original comment by reiter.christoph@gmail.com on 15 Apr 2013 at 10:58

GoogleCodeExporter commented 8 years ago
That was explained

"Invoking mid3v2 goes through the symlink /usr/local/bin/mid3v2 which causes 
python not to find the mutagen folder with your modules inside 
/usr/local/bin/mutagen. They are actually in 
/usr/local/Cellar/python-mutagen/<version>/mutagen."

Original comment by joao.ei...@gmail.com on 15 Apr 2013 at 11:10

GoogleCodeExporter commented 8 years ago
This only says that it does, not why (at least on linux it doesn't).

Original comment by reiter.christoph@gmail.com on 15 Apr 2013 at 11:24

GoogleCodeExporter commented 8 years ago
Doh, you're right. I did the patch some time ago and confused the problem.

The problem is not the symlink but the call to os.path.abspath(). If 
/usr/local/bin/mid3v2 links to tools/mid3v2, abspath will return the current 
working folder and not the folder where the script is located.

Original comment by joao.ei...@gmail.com on 15 Apr 2013 at 11:54

GoogleCodeExporter commented 8 years ago
So mutagen isn't even in your python path. I guess there lies your problem.

Original comment by reiter.christoph@gmail.com on 15 Apr 2013 at 3:08

GoogleCodeExporter commented 8 years ago
The call to abspath() is still wrong. And the issue still happens if you're 
working with a dev checkout and have a system python installation.

Original comment by joao.ei...@gmail.com on 15 Apr 2013 at 3:32

GoogleCodeExporter commented 8 years ago
The fallback code does what the comment above says.

I've removed it now: revision 3304f3110a00

Original comment by reiter.christoph@gmail.com on 15 Apr 2013 at 3:57