Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm absolutely new to packaging, so forgive me if I am asking something obvious for an experienced packager...

How can I be sure that mentioned all the dependencies correctly in my package?

Say that my application make use of lib library-xyz which is not installed by default. If I build the package and install it on my developing machine, library-xyz will be installed already, so - even if I failed to mention it as a dependency - the program will still run correctly. But another user on a fresh install of ubuntu won't have library-xyz installed and the program will likely crash for him.

The way I am testing now is having a fresh ubuntu install running in a VM and installing the package there, but since it seems like a common problem, I wonder if there is a better way to test, something adopting the same philosophy of chroot but that - instead of "cutting out" parts of the filesystem would "cut out" all those installed packages that are not "default" in a clean ubuntu installation.

I'm packaging python programs.

share|improve this question
    
Is pbuilder an option? –  Nathan Osman Aug 20 '11 at 0:48
    
@George - I looked a bit into it before asking this question, but - possibly because I am so new to packaging - I got lost. I was under the impression that pbuilder worked mostly for compiled languages anyhow. Am I wrong? A google search for pbuilder python doesn't seem to bring up useful (at least for me) documentation. Any pointer? –  mac Aug 20 '11 at 13:33
    
After reading your question more, yeah - you're right. –  Nathan Osman Aug 20 '11 at 16:40
    
@GeorgeEdison - pbuilder can be used regardless of the programming language you use. In fact, there's a pbuilder section in the Python Packaging Guide. The point here is that pbuilder will let you check build dependencies as it can be used to create binary packages from the source package in a restricted environment. However, it won't be useful to check dependencies unless you add something to you packaging scripts like running unit tests that make use of all dependencies needed. –  jcollado Nov 11 '11 at 15:08

2 Answers 2

up vote 3 down vote accepted

The lintian program runs after building a package using debuild and should warn you for missing libraries when building a binary package. The ldd command can be used to check which libraries are needed for a package.

I use the below script for fetching library package dependencies quickly:

#!/bin/sh
# Save it as executable ~/bin/pkglibs
# Usage: pkglibs directory
#        pkglibs file
list_lib_pkgnames() {
    local lib="$1" libs
    # get the libraries for given "$lib", stripping out linker libraries
    libs=$(ldd "$lib" | awk '/=/{print $1}' | grep -vE '^(linux-vdso|linux-gate)\.so\.1$')
    # if there are libraries, find the matching packages for it
    [ -n "$libs" ] && dpkg -S $libs | sed 's/: .*//'
}
search="$1"
if [ -d "$search" ]; then
    # for directories, recursively search for library dependencies
    find "$search" -type f -exec "$0" {} \; | sort -u
else
    list_lib_pkgnames "$search"
fi

The command may take a while for large directories since it test each file separatedly. It can be optimized to generate a list of libraries first, and then passing the unique entries to the dpkg -S command, but that is an exercise for the reader.

Example: pkglibs /usr/lib/mesa/:

ia32-libs
lib32gcc1
lib32stdc++6
libc6
libc6-i386
libdrm2
libgcc1
libstdc++6
libx11-6
libxau6
libxcb1
libxdamage1
libxdmcp6
libxext6
libxfixes3
libxxf86vm1
share|improve this answer
    
Thank you for this. Maybe I omitted a key-information in my question? I am packaging python programs. Lintian executes normally against my packages but seems not to detect missing dependencies, while ldd throws not a dynamic executable and exits... :-/ –  mac Aug 19 '11 at 13:25
2  
The dh_python2 step might be what you're looking for. Another way to check your package for dependencies is running grep -rn 'import ' path/to/your/python/files-or-dirs to check the required python modules. Most python modules are prefixed with python-, like python-appindicator. –  Lekensteyn Aug 19 '11 at 14:12
    
Thank you for this. It really seems dh_python2 is what I am after, yet... even though the software seems to run smoothly (no errors thrown) it does not populate the debian/control file with the dependencies that I know for sure I have. The documentation for dh_python2 helper seems to be quite scarce, do you have any good pointer for me? Thank you! –  mac Aug 21 '11 at 11:39
    
Add ${python:Depends} to Depends: in your control file. –  Lekensteyn Aug 21 '11 at 11:50
    
It is already there. Maybe I am expecting to see something that I shouldn't? My code - amongst others - depends from BeautifulSoap. I would expect to see somewhere in the control file a line saying Depends: python-beautifulsoap. Again: this is my very first time packaging applications, so I apologise if I am missing something obvious... –  mac Aug 21 '11 at 13:56

As explained in my comment above regarding pbuilder, it's useful mainly to verify build dependencies (similar to upload the package to a launchpad PPA), but won't be useful to check dependencies unless you add some additional steps in your packaging scripts like running unit tests.

Another similar solution (run tests in a restricted environment), if you're just considering dependencies against python libraries, would be to create a virtualenv so that you're in control of the python libraries available during testing. One tool that would be usefull to manage the virtual environments using multiple python versions while running the tests would be tox.

This won't add the dependencies for you in the debian/control file, but could be helpful anyway.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.