4

I plan to develop a medium scale web application (with lot of back-end work) using multiple packages (internal and external), since it's my first experience with such scale, can I get some advice on:

  1. How to ensure that all dependencies are satisfied (no required package/module is missing, packages were imported from right location etc.)
  2. How to manage versions of packages/modules. I want to be able to introduce new versions of packages/modules with minimal code changes in other connected packages/modules.

Please let me know if there is a tool that can be of help in this. If there is any other challenge (which I may not even be aware of) that comes in managing code with this scale then please caution me and provide ways to resolve it.

What I know currently (and think that it may help in code management):

  • __all__ to define exportable modules.
  • Use of preceding single underscore to prevent modules from getting imported
  • __init__.py to manage imports at package level (so when I do import package_name then __init__.py can centrally control other imports)
  • PEP 328 to manage relative imports, importlib and other such stuff around importing.
  • I suppose some of the 3rd party packages also define __version__ or VERSION variable to check the version at runtime, but I am not sure if I can rely on it.

If there are books, blogs etc. that can help then please let me know.

EDIT: I am not sure if this type of question fits here on SO. If not then I apologize.

Dev Maha
  • 1,103
  • 1
  • 10
  • 24

1 Answers1

0

How to ensure that all dependencies are satisfied (no required package/module is missing, packages were imported from right location etc.)

Use a virtualenv and freeze the packages with pip to a requirements file:

$ pip freeze > requirements.txt
$ cat requirements.txt
argparse==1.2.1
distribute==0.6.31
wsgiref==0.1.2

Basically, use virtualenv, distribute and pip whenever you have some code that'll need a module installed.

To install packages according to the version specified in your requirements.txt:

pip install -r requirements.txt
Community
  • 1
  • 1
timss
  • 9,344
  • 3
  • 31
  • 54
  • Thanks timss. I use virtualenv, let me read further to see if freeze can help manage versions of packages and ease introduction/testing of new ones. I want to understand how we manage versions of our own packages, do we define version variable, or we create separate packages like chat01 chat02. What if I have import package_name and now I want to try an updated package (think of it as writing versioned REST APIs and managing them) – Dev Maha Apr 21 '13 at 17:38
  • @AccEnq Freeze can help you manage versions, because you can later install packages with the version in `requirements.txt` with pip (updated answer). I'm not sure how you would solve it with personal packages, but pip can install from local files aswell. – timss Apr 21 '13 at 17:55