6

Goals:

  • Make use of modern Python packaging toolsets to deploy/install proprietary packages into some virtualenv.
  • The installed packages should include compiled *.pyc(or *.pyo) only without source files.
  • There are a couple of packages, and a vendor name (here we choose dgmx for our studio) is used as the package names. Therefore, the installed packages would be something like dgmx/alucard, dgmx/banshee, dgmx/carmilla, ...
  • The file hierarchy of installed packages should be like ones by python setup.py install --single-version-externally-managed or pip install. Refer to How come I can't get the exactly result to *pip install* by manually *python setup.py install*?

Question in short:

I like to deploy proprietary namespaced packages into a virtualenv by only compiled *.pyc(or *.pyo) files, in which the file/directory hierarchy just reflects the namespace with polluting sys.path by lots of ooxx.egg paths.

Something I have tried:

  1. python setup.py bdist_egg --exclude-source-files then easy_install ooxx.egg.
    • pollute "sys.path" for each namespace package.
  2. python setup.py install --single-version-externally-managed.
    • not *.pyc only.
    • the "install_requires" got ignored!
    • need to manually put a ooxx.egg-info/installed-files.txt to make uninstall work correctly.
  3. pip install . in the location of "setup.py".
    • not *.pyc only.
  4. pysetup install . in the location of "setup.py".
    • not *.pyc only.

Update:

My current idea is to follow method 2.

  • python setup.py egg_info --egg-base . # get requires.txt
  • python setup.py install --single-version-externally-managed --record installed-files.txt # get installed-files.txt
  • manually install other dependencies through "requires.txt"
  • manually delete installed source files (*.py) through "installed-files.txt"
  • remove source files (*.py) from "installed-files.txt" and put it into deployed "ooxx.egg-info/installed-files.txt"

References:

  1. Migrating to pip+virtualenv from setuptools
  2. installing only .pyc (python compiled) with setuptools
  3. Can I deploy Python .pyc files only to Google App Engine?
  4. How come I can't get the exactly result to *pip install* by manually *python setup.py install*?
4
  • 1
    FYI, pyc are not really compiled binaries, and can easily be reverse engineered, e.g. using the dis module. I would suggest looking at pyd files (which are basically dlls), but I'm not sure how you can create them from python code. Commented Apr 17, 2012 at 8:35
  • I know, but it's a policy issue instead of robust technical issue. Commented Apr 17, 2012 at 9:19
  • @Drake: you probably want .pyo files instead of .pyc. Commented Apr 17, 2012 at 10:22
  • @vartec you're right. .pyo is much better then~ Commented Apr 17, 2012 at 10:49

1 Answer 1

-1

Some trick may help:

Compile your source into .pyc, zip them up in a single .zip file.

Write a new module with a simple module all it does is to add the .zip to the sys.path.

So when you import this module, the .zip is in the path. All you have to do is in a custom step in setup.py, copy the zip file to the proper place.

Sign up to request clarification or add additional context in comments.

1 Comment

In case of Python called an egg, and he already mentioned that in the question (first option he has tried).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.