[Debian-olpc-devel] Finding dependencies of Python code

Jonas Smedegaard dr at jones.dk
Tue Nov 10 12:29:16 UTC 2009


On Fri, Nov 06, 2009 at 06:51:13PM +0100, Jonas Smedegaard wrote:
>On Fri, Nov 06, 2009 at 06:19:19PM +0100, Sascha Silbe wrote:
>>On Fri, Nov 06, 2009 at 05:39:41PM +0100, Jonas Smedegaard wrote:

>>>If anyone knows about a tool to extract all "import" statements 
>>>in  Python code, I would much appreciate it!
>>find -name "*.py" |xargs grep -h import |sort -u
>
>Yeah - better than nothing.  Some time ago I wrote a loooong perl 
>one-liner doing above + some kinds of calling shell commands, but 
>then by seession dies and with it the one-liner which off course 
>wasn't written down anywhere yet and didn't even gt saved to the bash 
>history :-(

Here's an improvement of above which simplifies simple import statements 
and includes filename for indented ones which are potentially trickier 
(it might be try-encapsulated statements that should then lead to 
recommends or suggests rather than hard depends):

find * -name "*.py" -exec grep -H '\bimport\b' {} \; | perl -pe 's/^[^:]+:(?:from\s+(\S+)|import\s+(\S+)).*/$1/; s/^(?=[^:]+:)/A /' | sort -u


I still need to reinvent the parts scanning for external binaries 
executed from inside Python code.

Help appreciated!


>>The "magic" stuff should usually be safe to ignore as it's for 
>>loading plugins, not external dependencies (AFAICT at least).
>
>What "magic"?  I lost you there.

Please do elaborate.


Kind regards,

  - Jonas

-- 
* Jonas Smedegaard - idealist & Internet-arkitekt
* Tlf.: +45 40843136  Website: http://dr.jones.dk/

  [x] quote me freely  [ ] ask before reusing  [ ] keep private
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/debian-olpc-devel/attachments/20091110/8743cb1b/attachment.pgp>


More information about the Debian-olpc-devel mailing list