Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there no Makefiles for automation in Python projects?

As a long time Python programmer, I wonder, if a central aspect of Python culture eluded me a long time: What do we do instead of Makefiles?

Most ruby-projects I've seen (not just rails) use Rake, shortly after node.js became popular, there was cake. In many other (compiled and non-compiled) languages there are classic Make files.

But in Python, no one seems to need such infrastructure. I randomly picked Python projects on GitHub, and they had no automation, besides the installation, provided by setup.py.

What's the reason behind this?

Is there nothing to automate? Do most programmers prefer to run style checks, tests, etc. manually?

Some examples:

  • dependencies sets up a virtualenv and installs the dependencies
  • check calls the pep8 and pylint commandlinetools.
  • the test task depends on dependencies enables the virtualenv, starts selenium-server for the integration tests, and calls nosetest
  • the coffeescript task compiles all coffeescripts to minified javascript
  • the runserver task depends on dependencies and coffeescript
  • the deploy task depends on check and test and deploys the project.
  • the docs task calls sphinx with the appropiate arguments

Some of them are just one or two-liners, but IMHO, they add up. Due to the Makefile, I don't have to remember them.

To clarify: I'm not looking for a Python equivalent for Rake. I'm glad with paver. I'm looking for the reasons.

like image 746
keppla Avatar asked Sep 28 '11 09:09

keppla


People also ask

Can you use makefiles with Python?

Even though Python is regarded as an interpreted language and the files need not be compiled separately, many developers are unaware that you can still use make to automate different parts of developing a Python project, like running tests, cleaning builds, and installing dependencies.

Do you need a Makefile for Python?

Nothing in your Python code needs to know that make is being used. Your Makefile simply describes the commands you would otherwise run at the command line to build your executable, whatever those might be.

Are makefiles good?

A makefile is useful because (if properly defined) allows recompiling only what is needed when you make a change. In a large project rebuilding the program can take some serious time because there will be many files to be compiled and linked and there will be documentation, tests, examples etc.


1 Answers

Actually, automation is useful to Python developers too!

Invoke is probably the closest tool to what you have in mind, for automation of common repetitive Python tasks: https://github.com/pyinvoke/invoke

With invoke, you can create a tasks.py like this one (borrowed from the invoke docs)

from invoke import run, task  @task def clean(docs=False, bytecode=False, extra=''):     patterns = ['build']     if docs:         patterns.append('docs/_build')     if bytecode:         patterns.append('**/*.pyc')     if extra:         patterns.append(extra)     for pattern in patterns:         run("rm -rf %s" % pattern)  @task def build(docs=False):     run("python setup.py build")     if docs:         run("sphinx-build docs docs/_build") 

You can then run the tasks at the command line, for example:

$ invoke clean $ invoke build --docs 

Another option is to simply use a Makefile. For example, a Python project's Makefile could look like this:

docs:     $(MAKE) -C docs clean     $(MAKE) -C docs html     open docs/_build/html/index.html  release: clean     python setup.py sdist upload  sdist: clean     python setup.py sdist     ls -l dist 
like image 80
coffee-grinder Avatar answered Oct 16 '22 21:10

coffee-grinder