Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test the setup.py for my package?

I have a pretty big Python package I've written, about 3500 statements, with a robust unit and acceptance test suite. I feel quite confident about the quality of the code itself, but I'm uneasy about the install process going smoothly for users of the package as I don't know how to reliably test the install in an appropriately isolated environment, short of something like keeping a spare machine around and re-imaging it with a fresh OS install for each test run.

I suspect using virtualenv in the right way might provide a proper test fixture for testing installation, but after extended web searches have uncovered no helpful guidance.

How can I effectively test my setup.py and other installation bits on my development machine?

like image 586
scanny Avatar asked Dec 10 '13 08:12

scanny


People also ask

How do I test a setup py file?

If you really want isolation instead just doing python setup.py install in virtualenv. Then use virtualbox and install some free linux os in it. Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there.

Does pip run setup py?

If this wheel generation fails, pip runs setup.py clean to clean up any build artifacts that may have been generated. After that, pip will attempt a direct installation.

Does python package require setup py?

A Python file that relies only on the standard library can be redistributed and reused without the need to use setuptools. But for projects that consist of multiple files, need additional libraries, or need a specific version of Python, setuptools will be required.


2 Answers

If you like tools (which I do) check out fabric and the set of Fabric tasks I've written across all my projects:

e.g: circuits' fabfile

This should work for just about any Python project and utilizes:

  • Sphinx
  • py.test/tox
  • virtualenv

Some basic workflows:

fab build    # build the package in non-development mode
fab develop  # build the package in development mode
fab docs     # build/regenerate the documentation
fab test     # run tie unit test suite
fab release  # run through a tested release cycle

Type: fab -l for a list of commands and fab help:<name> for help on any command.

Update: Recently we added fab docker commands to work with Docker

fab docker:build    # Build a Docker image
fab docker:publish  # Publish Docker image to the Docker Hub
fab docker:run      # Run a new Docker container
like image 62
James Mills Avatar answered Oct 21 '22 06:10

James Mills


If you really want isolation instead just doing python setup.py install in virtualenv. Then use virtualbox and install some free linux os in it. Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there.

like image 41
Saša Šijak Avatar answered Oct 21 '22 07:10

Saša Šijak