Issue #3 resolved

Add pydir macro for handy functionality

Jesse Noller
created an issue

Something nice to have, a bash function for getting what the current site-packages directory is: {{{


alias pydir="python -c \"from distutils.sysconfig import get_python_lib; print get_python_lib()\" }}}

Comments (10)

  1. Jesse Noller reporter

    No, and that's the idea. I use it a lot to jump into the site-packages directory to poke at source code, verify nothing is wonky, etc. It's a nice-to-have

  2. Doug Hellmann repo owner

    OK, I just wasn't clear if distutils did something fancier. How about if workon sets $SITE_PACKAGES in the environment after activating the new env.

    I should probably also add a global postactivate hook so you could set these sorts of things on your own.

  3. Chris Hasenpflug

    FWIW, when i'm in a virtualenv, that code snippet returns my global site-packages:

    (elsewhere)chris@macbookpro [~]
    $ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

    Could be an issue with my setup, but it doesn't seem like something that can be trusted 100%. I've ended up writing this (but I'm not happy with it...) in my pylink script:

    import distutils, os; print os.path.join(distutils.sysconfig.PREFIX, 'lib', 'python%s' % distutils.sysconfig.get_python_version(), 'site-packages')

    I'd be +1 on a global postactivate hook. For one, I don't like the default PS1 setting, and that would doable there too.

  4. Jesse Noller reporter

    Curse you distutils! I'll check tomorrow, it's possible distutils is rummaging deeper into the install path then virtualenv can fake it. I'll see if I can come up with something more reliable.

  5. Jesse Noller reporter

    Yeah, that would be why. Looking at the distutils code, it looks like what it's doing is pretty simple (at first glance), but it's not obvious (given a quick review) on how to trick it. I can keep digging, but something in the vein chris suggests would work to.

  6. Chris Hasenpflug

    After thinking about this some more, doesn't it make sense just to put the alias in your own .profile scripts? It doesn't feel right putting an alias in the wrapper utilities. Now a global postactivate hook, absolutely. And then users could define their own if they desired. I just don't like define (and possibly overwriting..) a user's aliases.

  7. Log in to comment