Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code generation in setup.py

Tags:

python

I've got some XML files from which I intend to derive some python source code; they are things like lists of language codes. Does the distribute module have a hook I can plug into for this purpose? To be perhaps clearer, I don't want to ship XML around. I want to only ship .py files. I want to derive some .py files by running a program that generates them from XML.

like image 969
bmargulies Avatar asked Oct 01 '12 14:10

bmargulies


People also ask

What is code generation in Python?

Cog is a simple code generation tool written in Python. We use it or its results every day in the production of Kubi. Kubi is a collaboration system embodied in a handful of different products.

What should be in setup py?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

What is scripts in setup py?

The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.


1 Answers

You could create a custom distutils command for your code gen process, or you can override build itself. This would require you to include the XML, though.

I'd probably move the code generation into my local build process, using zc.buildout with a templating recipe like z3c.recipe.template. The XML would then be part of the development build, with only the code generated Python files included in the user distribution.

like image 82
Matthew Trevor Avatar answered Sep 28 '22 07:09

Matthew Trevor