473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Finding Module Dependancies

mwt
When I'm rewriting code (cutting and pasting pieces from earlier
modules), is there a quick way to determine if I have imported all the
necessary modules? I am used to working in Java, where the compiler
will tell you if you haven't imported everything, and also Eclipse,
which has the handy "organize imports" feature. This is not the case in
Python, since it's not compiled, of course, and also running it might
not insure you've got all the imports, unless you go through every
possible usage scenario -- which in some cases is quite a few, and
could take a long time.

So what I'm looking for is a command, like "check dependencies" or
something, which will list all the modules needed for a source module
to run.

Apr 21 '06 #1
6 1142
mwt wrote:
When I'm rewriting code (cutting and pasting pieces from earlier
modules), is there a quick way to determine if I have imported all the
necessary modules? I am used to working in Java, where the compiler
will tell you if you haven't imported everything, and also Eclipse,
which has the handy "organize imports" feature. This is not the case in
Python, since it's not compiled, of course, and also running it might
not insure you've got all the imports, unless you go through every
possible usage scenario -- which in some cases is quite a few, and
could take a long time.

So what I'm looking for is a command, like "check dependencies" or
something, which will list all the modules needed for a source module
to run.

If you are an accomplished Eclipse user (I'm not), you should look at
the Python plug-in for Eclipse.

Remember that Python is so dynamic that you can build dependencies
during program execution and import them on-the-fly. So a dependency
checker would always be incomplete. You always need to write unit
tests.

-Larry Bates
Apr 22 '06 #2
On 22/04/2006 8:18 AM, mwt wrote:
When I'm rewriting code (cutting and pasting pieces from earlier
modules)
Instead of propagating multiple copies of source code, consider
refactoring those modules so that top-level functions and classes can be
used in other modules.
is there a quick way to determine if I have imported all the
necessary modules? I am used to working in Java, where the compiler
will tell you if you haven't imported everything,
That's a clever design. It would be even better if it just shut up and
did the imports for you :-)
and also Eclipse,
which has the handy "organize imports" feature. This is not the case in
Python, since it's not compiled, of course, and also running it might
not insure you've got all the imports, unless you go through every
possible usage scenario -- which in some cases is quite a few, and
could take a long time.
This is called "testing". Yes, it could take a long time.

So what I'm looking for is a command, like "check dependencies" or
something, which will list all the modules needed for a source module
to run.


Consider pychecker and pylint. I haven't tried pylint, but pychecker
does what you want and a whole lot more:

C:\junk>type miss_import.py
# need to import re, but forgot
def my_isdigit(s):
return bool(re.match(r"\d+", s))

C:\junk>pychecker miss_import

C:\junk>c:\python24\python.exe
c:\python24\Lib\site-packages\pychecker\checker.py miss_import
Processing miss_import...

Warnings...

miss_import.py:3: No global (re) found

C:\junk>
Apr 22 '06 #3
mwt

John Machin wrote:

This is called "testing". Yes, it could take a long time.
Thanks for the clarification. ;) Actually, I've done hellish amounts
of testing on these code pieces, which is why I don't want to have to
do it all over again just to check the imports.


Consider pychecker and pylint. I haven't tried pylint, but pychecker
does what you want and a whole lot more:

C:\junk>type miss_import.py
# need to import re, but forgot
def my_isdigit(s):
return bool(re.match(r"\d+", s))

C:\junk>pychecker miss_import

C:\junk>c:\python24\python.exe
c:\python24\Lib\site-packages\pychecker\checker.py miss_import
Processing miss_import...

Warnings...

miss_import.py:3: No global (re) found

C:\junk>


That sounds really useful. I'll check it out. Thanks!

Apr 22 '06 #4
mwt
Wow! Just ran pychecker on a couple of modules. I'm blown away by how
much information I'm getting. Thanks again!

Apr 22 '06 #5
mwt
Wow! Just ran pychecker on a couple of modules. I'm blown away by how
much information I'm getting. Thanks again!

Apr 22 '06 #6
Larry Bates wrote:

Remember that Python is so dynamic that you can build dependencies
during program execution and import them on-the-fly. So a dependency
checker would always be incomplete. You always need to write unit
tests.


The Pychecker will usually see also missing on-the-fly imports and most
of that like.
You'd need to do tricky exec stuff to trick him - and even then he can
warn for smelling style of code.
You'd have to add upon warnings a #$pycheck_no to all such smelling
lines in order to confirm, that you really know what you are doing.

To my experience you'd usually not get the written tests dense enough
(at reasonable costs) to look into all branches of execution flow.

All 5 things are needed for efficiency :
(frequency of application decreasing the list down)

* auto-postmortem debugging (dev) ( auto-postmortem report (dist))
* running written tests
* code checks
* walking major execution branches by manual tests
* beta cycling

-robert
Apr 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Y2KYZFR1 | last post by:
I have searched and only found references to using ODBC or some ancient posts about some ancient sybase library under linux, neither of which meets my critiera. I need something that will cross...
4
by: Larry | last post by:
I have a Perl script using DBD::DB2, that runs during system startup on a Solaris system. The script is working fine during startup on many machines, except on one machine it fails complaining...
0
by: Chris Bruner | last post by:
I've got a program that is successfully selling, that I would like to move from MFC to C#. My method of deployment is to copy the program and data files to an SDCard using the main PC program. That...
2
by: kj | last post by:
I'm a Python noob, and haven't yet figured out my way around the Python documentation. For example, suppose I learn about some great module foo.bar.baz, and when I run the python interpreter and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.