English 中文(简体)
Project management/build tools for a Django project? [closed]
原标题:

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Coming from Java development where build and project management tools abound, I d like to know what s available for Django. I d really like to use something like Maven for building things, but is there another preferred way of doing it?

I m really looking for the following:

  • Command-line building: mvn install is just so easy and cool.
  • Command-line test-runs. I d like to integrate this app into something like Hudson for continuous integration, since I m hardcore like that.
  • Deployment of media to local test server (JS, CSS, images, etc.)

Is this currently possible with Maven or another tool? I m embarking on a pretty big project here and I d like to have a kicking-rad build/project management system like Maven to help the project be able to grow over time.

最佳回答

Two tools come to mind which are both generic python tools - they need not work with Django specifically:

  • Fabric. We use this; it allows us to write remote commands as if we were SSH d in, upload code etc. These isn t much you can t do and because it is essentially a bash script written in python, it is very easy to get going. But it is also a bash script written in python, which means you can import parts of your django app, run your tests or do anything python can do in the process of running your deployment.
  • Buildout. I ve not used this, but our django frontent developer tells me this is absolutely the tool to use. At a guess, it is either the same idea or a slightly more abstract, more python-orientated equivalent.

I am sure there are other packages available. The best advice I can give you is to evaluate them all briefly and pick the one that best fits your scenario/team working style. Note that these are mostly deployment tools - builds in python don t really make sense, since you don t compile python code.

In terms of CI related stuff, there are three commands from django you need to know about:

  • ./manage.py test runs your tests from all tests.py files. These are basically django-specific enhancements to unittest, a python package.
  • ./manage.py collectstatic collects static files to a directory of your choosing; highly useful for pulling all the bits together to exist on a static media server. Have a look at the static files howto for how this works.
  • You need South for this one, ./manage.py schemamigration app --auto && ./manage.py migrate app - this applies model changes to the underlying sql schema. Basically, if you just change a model and don t use south, Django will get very upset because the new field won t map to the old sql schema and it won t be able to persist your model. Schema migrations, which south supports, enable you to upgrade an existing, populated database. Worth doing by hand before automating.
  • I should also point out you can write custom management commands to execute ./manage.py whatever you like. This has a fair amount of potential - I ve used management commands as the command to execute in a cron job, for example. You could also build interactive commands for admins of your application and, of course, deployment and testing.

How these are handled really depends on what setup you have available and what tools you choose.

On compilation: The closest you get to building with python is freeze, a.k.a. py2exe or cxfreeze which produce binaries. Be aware though that all these do is store python bytecode in an exe and pass it through the interpreter, which is a shared object anyway. Also, you can t cxfreeze a django app, since django itself uses dynamic imports which occur at run time and so cannot be evaluated by cxfreeze, which is essentially a compile time tool. So discount building as a task that needs doing. You might see .pyc files appearing in your directory - python converts your python script to python bytecode if changes have been made to it since the last pyc. If no changes have been made, it loads the pyc file from last time. Python bytecode is what gets executed, so this isn t really a speedup in terms of performance, just load time.

问题回答

If you need something to manage and reproduce your (Django) python environment then I would recommend looking at pip with virtualenv as an alternative to Buildout.

This SaltyCrane article describes using pip with Django. The article describes the process on Ubuntu but we use a similar set up on both Ubuntu and OSX.

We have experience with both buildout and pip and found pip easy, more reliable and easier to scale than buildout.





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签