Leonardo Andrade
Leonardo Andrade

Reputation: 2628

How can I add a custom package in a pyramid project?

I created a pyramid project (with pcreate -s starter projtest) and with the default structure, pserve runs the project as expected. But, when I add a package directory (for example, called "skimpygimpy") in the same level of views.py and templates directory, pserve isn't able to launch the project (invalid command name 'development.ini' error).

projtest/
 |-- CHANGES.txt
 |-- development.ini
 |-- MANIFEST.in
 |-- myproject
 |   |-- __init__.py
 |   |-- skimpygimpy
 |   |   |-- __init__.py
 |   |   |-- file.py
 |   |   |--  ...
 |   |-- static
 |   |   |-- favicon.ico
 |   |   |-- logo.png
 |   |   |-- pylons.css
 |   |-- templates
 |   |   |-- mytemplate.pt
 |   |-- tests.py
 |   |-- views.py
 |-- production.ini
 |-- README.txt
 |-- setup.cfg
 |-- setup.py

So, how could I add a custom package inside a pyramid project and avoid this error (invalid command name 'development.ini') when I call pserve?

More informations about the problem:

I did these commands:

mkdir pyramid
cd pyramid/
virtualenv --no-site-packages env
cd env/
bin/easy_install pyramid
bin/pcreate -s starter projtest
cd projtest
cd projtest
hg clone https://code.google.com/p/skimpygimpy/
cd skimpygimpy
touch __init__.py
cd ..
cd ..
../bin/python setup.py develop
../bin/pserve development.ini

And, then, the message: invalid command name 'development.ini'

If I delete the "skimpygimpy" directory, and rerun

../bin/python setup.py develop
../bin/pserve development.ini

It's OK.

The development.ini file: http://codepad.org/VKPXm0jf

What am I doing wrong? Any ideas?

Upvotes: 2

Views: 599

Answers (1)

Michael Merickel
Michael Merickel

Reputation: 23341

That's a weird one, I'm mostly drawing a blank right now but I have a guess. I think that since you are cloning skimpygimpy's entire source tree as a subpackage in your project, the skimpygimpy setup.py is being executed inadvertently by something like a config.scan() which imports all of the code from the subpackages. When the setup.py gets imported, bad things will happen because it'll use sys.args to grab parameters, which would explain why its acting like you called python setup.py development.ini.

Dependencies should be found by having them all installed into the same virtualenv, their actual location on the filesystem is not nearly as relevant when this is done because the interpreter's path always includes things in the virtualenv.

As a result, third-party projects should not be placed inside your package but rather installed into the virtualenv, so I think you should avoid placing skimpygimpy as a subpackage at all. This means cloning it int the top-level projtest folder if you like, but not inside the projtest package.

I'm pretty sure your problem would not occur with any manually created packages that didn't include a setup.py. For example mkdir foo; touch foo/__init__.py should not exhibit your problem.

Upvotes: 1

Related Questions