简体   繁体   中英

Find all unmet dependencies for a Python/Django project

I've been handed a dozen or so legacy Django applications to maintain. The first part of this process is moving them off their ancient Ubuntu 9.04 server (which is long out of support) onto something fresh and safe.

But the projects don't include any sort of dependency listing. From habit I'm used to generating a requirements.txt file as I develop a site and that makes redeployment a simple and automated process.

As it stands I would have to manually step through these projects, making sure to scrape every corner to find possible missing dependencies. Either that or I install everything .

Is there an automated code-analysis option here? Something that can use to scan the local project directories for each project to generate a list of packages it needs... ideally in PyPI formatted package names.

z3c.dependencychecker can be used for this purpose.

It's in the z3c namespace, but from what I know that's only because it has been developed with a Zope ecosystem in mind, but it can just as well be used for plain Python projects. Unless you want to run its tests, it does not have any dependencies on Zope packages.

It does however only consider dependencies declared in setup.py , not in requirements.txt . But it should be pretty easy to sync up missing dependencies for the full list of dependencies once they've been determined.

Usage:

  • Activate your virtualenv, and install z3c.dependencychecker , eg by doing pip install z3c.dependencychecker
  • Make sure you have run python setup.py develop for your project recently, so you have an up-to-date *.egg-info .
  • cd into your projects source directory
  • run dependencychecker

Note that z3c.dependencychecker isn't perfect (pretty much by definition, because of the way it works), so it can report some false positives. But in my experience it's a very good start, and it should be pretty easy to verify why it reported a particular dependency, and weed out false positives.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM