Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47424
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carlosnepomuceno@outlook.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'attribute': 0.07; "'.'": 0.09; 'closest': 0.09; 'subject:modules': 0.09; 'dist': 0.16; 'modules,': 0.16; 'retrieving': 0.16; 'set()': 0.16; 'setuptools': 0.16; 'setuptools.': 0.16; 'skip:/ 70': 0.16; 'sat,': 0.16; 'module': 0.19; 'trying': 0.19; 'packages.': 0.19; '>>>': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'this?': 0.23; '>>>': 0.24; 'either.': 0.24; 'received:65.55.116': 0.24; "i've": 0.25; '>': 0.26; 'header :In-Reply-To:1': 0.27; 'installed': 0.27; 'idea': 0.28; 'function': 0.29; 'correct': 0.29; 'locations': 0.30; 'mode': 0.30; "i'm": 0.30; 'url:mailman': 0.30; "skip:' 10": 0.31; 'values.': 0.31; 'subject:all': 0.32; 'thanks!': 0.32; 'quite': 0.32; 'url:python': 0.33; '(i.e.': 0.33; 'date:': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'something': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'possible': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'example,': 0.37; 'list': 0.37; 'email addr:python.org': 0.37; 'skip:o 20': 0.38; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'subject:': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'tips': 0.61; 'email addr:gmail.com': 0.63; 'email name:python-list': 0.65; '2013': 0.98 |
| X-TMN | [kDEdbPTdZXw/WyHWnQXajz5tdt3OAFFx] |
| X-Originating-Email | [carlosnepomuceno@outlook.com] |
| Content-Type | multipart/alternative; boundary="_39358e4d-a5e0-4c60-aff3-59660fa61b03_" |
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: Listing modules from all installed packages |
| Date | Sun, 9 Jun 2013 08:23:15 +0300 |
| Importance | Normal |
| In-Reply-To | <210f2f63-13b0-46c2-b080-fd831cb3ca49@googlegroups.com> |
| References | <210f2f63-13b0-46c2-b080-fd831cb3ca49@googlegroups.com> |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 09 Jun 2013 05:23:15.0583 (UTC) FILETIME=[718558F0:01CE64D1] |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2907.1370755403.3114.python-list@python.org> (permalink) |
| Lines | 112 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370755403 news.xs4all.nl 15910 [2001:888:2000:d::a6]:50538 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47424 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
print '\n'.join([re.findall("from '(.*)'",str(v))[0] for k,v in sys.modules.items() if str(v).find('from')>-1])
> Date: Sat, 8 Jun 2013 21:30:48 -0700
> Subject: Listing modules from all installed packages
> From: jphalip@gmail.com
> To: python-list@python.org
>
> Hi,
>
> I'm trying to write a function that programmatically obtains and returns the exact location of all first-level modules for all installed packages.
>
> For example, if the packages named 'django' and 'django-debug-toolbar' are installed, I'd like this function to return something like:
> >>> installed_modules()
> /Users/my_user/.virtualenvs/my_venv/lib/python2.6/site-packages/django
> /Users/my_user/.virtualenvs/my_venv/src/debug_toolbar
>
> That is, this function needs to consider all installed packages, including those that have been installed in "edit" mode (i.e. in the src/ folder). Note also that the main module for the 'django-debug-toolbar' is in fact named 'debug_toolbar'.
>
> So far the closest I've been to retrieving the list of first-level modules is as follows:
>
> import os
> import pkg_resources
> import setuptools
>
> pkgs = set()
>
> for dist in pkg_resources.working_set:
> if os.path.isdir(dist.location):
> for pkg in setuptools.find_packages(dist.location):
> if '.' not in pkg:
> pkgs.add(pkg)
>
> The idea is then to loop through that list of modules, import them and get their exact locations by fetching their __file__ attribute values.
>
> However, this feels very hackish and I don't think it's actually quite correct either. I'm sure there must be a better way. If possible I'd also like to avoid having to use setuptools.
>
> Do you have any tips on how to achieve this?
>
> Many thanks!
>
> Julien
> --
> http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Listing modules from all installed packages Julien Phalip <jphalip@gmail.com> - 2013-06-08 21:30 -0700
RE: Listing modules from all installed packages Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-09 08:23 +0300
Re: Listing modules from all installed packages 88888 Dihedral <dihedral88888@gmail.com> - 2013-06-09 11:57 -0700
RE: Listing modules from all installed packages Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-09 09:22 +0300
Re: Listing modules from all installed packages cclauss@bluewin.ch - 2013-06-09 05:51 -0700
Re: Listing modules from all installed packages Julien Phalip <jphalip@gmail.com> - 2013-06-14 12:18 -0700
csiph-web