473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Squisher -- a lightweight, self-contained alternative to eggs?

I wrote this little program called Squisher that takes a ZIP file
containing Python modules and generates a totally self-contained .pyc
file that imports a specified module therein. (Conveniently, Python's
bytecode parser ignores anything after an end marker, and the
zipimport mechanism skips any non-ZIP data at the beginning of a
file!) For example, say you have a directory called 'foo', which
contains an __init__.py, which contains "print 'hello'; x = 123", and
a thing.py, which contains "y = 456". If you make a ZIP archive of
this and run it through Squisher, you'll get a single .pyc file which
can be imported by any Python installation anywhere just like any
other module, without requiring users to install any supporting
mechanisms (like setuptools), and giving all the flexibility and
stability of zipimport. In other words, you can do this simply by
dropping the foo.pyc file into a directory:
>>import foo
hello
>>foo.x
123
>>from foo.thing import y
y
456

Of course, this is a stupid and useless example, but you can do it
with any package you could use as an egg, yet without requiring people
to install setuptools (or any other external glue) to use it. I've
tested it with several large packages, including SQLAlchemy.

Right now I'm just testing and polishing up the code... in the
meantime, any comments?

Mar 5 '07 #1
14 1417
Adam Atlas a écrit :
(snip)
If you make a ZIP archive of
this and run it through Squisher, you'll get a single .pyc file which
can be imported by any Python installation anywhere just like any
other module, without requiring users to install any supporting
mechanisms (like setuptools),
setuptools offers *much* more than a convenient way to package source code.
Mar 5 '07 #2
This could be easily made into a distutils extension (which was my
intention all along, though that's not implemented yet). That's not
the point. This is not intended as a "way to package source code".
It's analogous to bdist, not sdist. The convenience gain is for the
users, not (primarily) the developers, of the package.

To use an Egg, you have to either put it in your sys.path manually or
install setuptools and use it to install the Egg in some global scope.
The advantage of Squisher is that you can take a whole package, squish
it into one .pyc file, and distribute that. Then, anyone who downloads
it can get a simple module file that can be used anywhere a usual .py
file can, without editing sys.path or installing it somewhere.
(Actually, this could be combined with eggs, since they're just ZIP
files. You could use the same file as an egg or as a squished module
simply by changing its extension.)

....Or am I missing something obvious about setuptools that already
does this and making a fool of myself? :)

Mar 5 '07 #3
Ah... heh, sorry, I misread your message as "a much more convenient
way" rather than "much more than a convenient way". Anyway, I
understand that, and I do indeed find setuptools useful and use it on
a regular basis.

But my other points still stand. This would be a moot point if
setuptools were part of the standard library, but it's not, and I
don't see why people should have to bother installing it if they
simply want to try a small package. Look at Beautiful Soup, for
example. It's distributed as a single .py file, and that's great. With
most modules, all I want to do is download them and plop them into my
project directory. You can always copy it into site-packages if you
want to access it globally, and you can always unzip it if you need to
see the source.

So I *will* retract my statement that this could be an "alternative"
to eggs -- ideally, it would be an addition, since it doesn't break
compatibility at all. You could download an egg and rename it to .pyc,
and import it like any other module, and at any point later, you could
rename it back to .egg and use setuptools to install it if you wish.

Mar 5 '07 #4
Adam Atlas wrote:
Ah... heh, sorry, I misread your message as "a much more convenient
way" rather than "much more than a convenient way". Anyway, I
understand that, and I do indeed find setuptools useful and use it on
a regular basis.

But my other points still stand. This would be a moot point if
setuptools were part of the standard library, but it's not, and I
don't see why people should have to bother installing it if they
simply want to try a small package. Look at Beautiful Soup, for
example. It's distributed as a single .py file, and that's great. With
most modules, all I want to do is download them and plop them into my
project directory. You can always copy it into site-packages if you
want to access it globally, and you can always unzip it if you need to
see the source.

So I *will* retract my statement that this could be an "alternative"
to eggs -- ideally, it would be an addition, since it doesn't break
compatibility at all. You could download an egg and rename it to .pyc,
and import it like any other module, and at any point later, you could
rename it back to .egg and use setuptools to install it if you wish.
Good point to make these things much easier!

But possibly I'm the only Windows user here,
as I still find these talks all very difficult to understand,
and I really don't understand why all this complexity is necessary,
setuptools ? eggs ? zips ? pythonpaths ?

As a normal Windows user,
I'm used to run an install file,
and hit just 1 button.
As a normal Windows programmer,
I'm used to create a simple Inno-setup file,
and my users can behave as a simplistic and happy Windows user.

But I guess the needed complexity is all thanks to NIX ;-)

I think I never would have started with Python,
if I didn't bounced into the Enthought-edition.

--
cheers,
Stef Mientki
http://pic.flappie.nl
Mar 5 '07 #5
Adam,

Sounds like a nice idea to me. Pretty ingenious use of the zip/
bytecode headers and all too. Post a message when you release it
please.

Regards,
Jordan

Mar 5 '07 #6
Adam Atlas a écrit :
Ah... heh, sorry, I misread your message as "a much more convenient
way" rather than "much more than a convenient way".
!-)

(snip)
But my other points still stand.
Indeed.
Mar 5 '07 #7
Stef Mientki a écrit :
Adam Atlas wrote:
>Ah... heh, sorry, I misread your message as "a much more convenient
way" rather than "much more than a convenient way". Anyway, I
understand that, and I do indeed find setuptools useful and use it on
a regular basis.

But my other points still stand. This would be a moot point if
setuptools were part of the standard library, but it's not, and I
don't see why people should have to bother installing it if they
simply want to try a small package. Look at Beautiful Soup, for
example. It's distributed as a single .py file, and that's great. With
most modules, all I want to do is download them and plop them into my
project directory. You can always copy it into site-packages if you
want to access it globally, and you can always unzip it if you need to
see the source.

So I *will* retract my statement that this could be an "alternative"
to eggs -- ideally, it would be an addition, since it doesn't break
compatibility at all. You could download an egg and rename it to .pyc,
and import it like any other module, and at any point later, you could
rename it back to .egg and use setuptools to install it if you wish.
Good point to make these things much easier!

But possibly I'm the only Windows user here,
I don't think so.
as I still find these talks all very difficult to understand,
and I really don't understand why all this complexity is necessary,
setuptools ? eggs ? zips ? pythonpaths ?

As a normal Windows user,
I'm used to run an install file,
and hit just 1 button.
As a normal *n*x user, I'm used to run a single command line. Don't even
have to hit a button !-)
But I guess the needed complexity is all thanks to NIX ;-)
FUD.
Mar 5 '07 #8
Stef Mientki wrote:
>
As a normal Windows user,
I'm used to run an install file,
and hit just 1 button.
As a normal Windows programmer,
I'm used to create a simple Inno-setup file,
and my users can behave as a simplistic and happy Windows user.

But I guess the needed complexity is all thanks to NIX ;-)
"Au contraire, as they say in England." - Steve X. Citement

Most UNIX-based (or at least GNU/Linux or BSD-based) Python users are
likely to have Python provided by their vendor together with a
"constellation" of packages. As long as the software they need is
packaged by their distribution, it's a matter of selecting the package
concerned; other packages upon which the desired software depends will
be installed automatically. You don't usually need to click through
some wizard ("next", "I agree", "next", "next", "next", "next",
"next", "finish"), either.

Paul

Mar 5 '07 #9
Stef,

What Adam is talking about has nothing to do with windows or *nix.
He's talking about packing one or more .py files into a single
archive, which can be imported just like the regular .py files. This
means you can distribute a whole bunch of module files/dirs as a
single .pyc file. It just makes it easier to have a single file to
distribute rather than a whole bunch, or a zip that one has to unzip
into a certain directory, &c. So you can have myscript.py +
myscriptfiles.pyc vs. myscript.py + somedepdir/ + someotherdepdir/ +
somedepfile.py...&c.

If you still don't get it, you don't need it.

Regards,
Jordan

Mar 5 '07 #10
Okay, here's the prototype...
<http://adamatlas.org/2007/03/Squisher-0.1.py>
It's meant to be run as a command line program (pass it a directory or
a zip file as an argument). By default it will save the new file to
the argument's base name plus '.pyc'. You can override this with -o.

Obviously it's very much a work in progress... try it out and let me
know the results.

Mar 6 '07 #11
On Mar 5, 12:31 am, "Adam Atlas" <a...@atlas.stwrote:
Right now I'm just testing and polishing up the code... in the
meantime, any comments?
How does this work with compiled extension modules?

Mar 6 '07 #12
Doesn't seem to work. I guess zipimport doesn't support that by
default... but if I remember correctly, Setuptools adds that. Maybe
I'll take a look at how it does it (I think by extracting the .so to /
tmp?) and see how easy it would be to integrate it here.

Mar 6 '07 #13
I updated it.
http://adamatlas.org/2007/03/Squisher-0.2.py

New Things:
- It supports C extensions within squished packages.
- It supports including squished packages within other squished
packages. (That is, you can have a package that includes a .pyc
generated by this, and turn that whole package into one .pyc.)
- If you import it after you import setuptools in a setup.py, it will
override a bit of setuptools so that bdist_egg will result in an egg
that can also be used as a squished package (if you rename it to
something ending in .pyc).
- It puts a helpful docstring at the top of generated .pyc files,
mainly for the purpose of being easy to see if you open the file in a
text editor. (It tells you what can be done with the file -- name it
something .pyc, or unzip it, or, if applicable, use it as an egg.)

Mar 7 '07 #14
Adam Atlas a écrit :
Doesn't seem to work. I guess zipimport doesn't support that by
default... but if I remember correctly, Setuptools adds that. Maybe
I'll take a look at how it does it (I think by extracting the .so to /
tmp?)
or to another known location, IIRC.
and see how easy it would be to integrate it here.
Mar 8 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeremy Hylton | last post by:
Lightweight Languages 2004 (LL4) http://ll4.csail.mit.edu/ Dec. 4, 2004 MIT, Cambridge MA Call for Presentations LL4 will be an intense, exciting, one-day forum bringing together the best...
2
by: build | last post by:
G'day all, I want to load comma sep text files and display it in a grid. I'd like something simple and lightweight. Don't need to edit it in grid, I could do that in textboxes if required. tia...
13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
1
by: Guinness Mann | last post by:
Greetings, I'm working in VS2003.NET using C#. I need to download a few rows from an SQL Server database table and then be able to page back and forth through them. I don't need to make any...
0
by: tjr7933 | last post by:
Has anyone implemented the OMG lightweight log spec into a c++ application? #! rnews 1946 Xref: xyzzy comp.lang.lisp:150483 Newsgroups: comp.lang.lisp Path: xyzzy!nntp From: Jeffrey Cunningham...
3
by: Ramza Brown | last post by:
I am sorry if I think like this, but sometimes(keyword sometimes) I like distributing my interpreters. Anyway, I found the absolute minimum libraries needed for Python to work with Win32. And,...
2
by: MS News | last post by:
Hello When I spawn a lightweight process on a new Thread and return immediately to the Client what happens if the lightweight process takes an hour to finish? Under what context is the process...
2
by: Martin Halle | last post by:
Dear all, I'm using XML in a project. This is a very simple and small file that follows an even simpler XSD schema. I've found a lightweight library (TinyXML) to read and access the contents of...
11
by: garyusenet | last post by:
I have 'cli via c# on order', and in the mean time am reading 'Pro C# 2005 and the .NET platform' (Andrew Troelson). I'm just reading about the 'five types defined in the CTS'. Specifically Struct....
2
by: metaperl | last post by:
I find it arduous to type dictionary and also feel that any data I create for a program deserves to have its operations tied to it. As a result, I often create lots of lightweight classes. Here's a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.