473,803 Members | 3,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

would be nice: import from archive

Here is a python feature that I would like: to be able to import modules
from an archive like the jar files in Java. Maybe a regular tar file?
Maybe a python specific file type, let's call it a 'par' file?

It would be useful in packaging an python library. Sure, there's always the
python packages, but a single file instead of a whole directory tree would
be more convenient. I am particularly interested because I am working on a
framework/toolkit and I am using a configuration divided into several
modules. It would be nice to be able to save configurations (combinations
of several modules) into single archive files and then switch between
configurations by pointing to one such archive file.

I am quite new to python so I should ask first whether there is already
something like that, although I did a search already. Or maybe such a
feature has already been discussed somewhere? If this is an original idea,
how can I propose it for future releases?

Dan Perl
(yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle
name, it's my last name)
Jul 18 '05
43 2525
"Terry Reedy" <tj*****@udel.e du> writes:
'import x' is syntactic sugar for 'x = __import__('x') '. I do not see it
as necessary that sugar for the common case need cover every possible case.
So, how about giving __import__ had an optional param 'signed' defaulted to
False, to allow signed =True or signed = CA?


Man, that __import__ thing is ugly. I think it's better to extend the
syntax, e.g.
import x(a,b) => __import__('x', {'a':None, 'b':None})
import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2})

so you could say
import x(signed)
or
import x(signed, certfile='mycer ts.pem')

or whatever.
Jul 18 '05 #31

"Paul Rubin" <"http://phr.cx"@NOSPAM. invalid> wrote in message
news:7x******** ****@ruckus.bro uhaha.com...
"Terry Reedy" <tj*****@udel.e du> writes:
'import x' is syntactic sugar for 'x = __import__('x') '. I do not see
it
as necessary that sugar for the common case need cover every possible
case.
So, how about giving __import__ had an optional param 'signed' defaulted
to
False, to allow signed =True or signed = CA?
Man, that __import__ thing is ugly.


Yes... but importing from signed zips is sufficiently rare and esoteric
that I would not see surface ugliness that accompanies using current syntax
as the most important consideration.

I think it's better to extend the syntax, e.g.
import x(a,b) => __import__('x', {'a':None, 'b':None})
import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2})


Identifier(args ) is currently a call of identifier with args and
overloading that syntax to mean somthing similar but different is, to me,
even uglier in a different sort of way.

Terry J. Reedy

Jul 18 '05 #32
"Terry Reedy" <tj*****@udel.e du> writes:
I think it's better to extend the syntax, e.g.
import x(a,b) => __import__('x', {'a':None, 'b':None})
import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2})


Identifier(args ) is currently a call of identifier with args and
overloading that syntax to mean somthing similar but different is, to me,
even uglier in a different sort of way.


Ok, use brackets instead: import x[a,b].
Then it's just a matter of overloading the index operator on __import__.
Jul 18 '05 #33
Paul Rubin wrote:
"Terry Reedy" <tj*****@udel.e du> writes:
> I think it's better to extend the syntax, e.g.
> import x(a,b) => __import__('x', {'a':None, 'b':None})
> import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2})


Identifier(args ) is currently a call of identifier with args and
overloading that syntax to mean somthing similar but different is, to me,
even uglier in a different sort of way.


Ok, use brackets instead: import x[a,b].
Then it's just a matter of overloading the index operator on __import__.


@signed
@certfile('myce rts.pem')
import x

anybody?
Peter
Jul 18 '05 #34
Just <ju**@xs4all.nl > writes:
The zipimport module will never write to the zip archive, so for most
efficient imports, you have to store .pyc data in there yourself.
zipimport is mostly meant as a repackaging tool, and typical zip files
only contain .pyc files.


They aren't created even outside of the zip archive, this is what I
meant ;-)

--
Godoy. <go***@ieee.org >
Jul 18 '05 #35
In article <m3************ @g2ctech.com>, Jorge Godoy <go***@ieee.org >
wrote:
Just <ju**@xs4all.nl > writes:
The zipimport module will never write to the zip archive, so for most
efficient imports, you have to store .pyc data in there yourself.
zipimport is mostly meant as a repackaging tool, and typical zip files
only contain .pyc files.


They aren't created even outside of the zip archive, this is what I
meant ;-)


But since .pyc's are always generated in the same directory as the .py
files, where else would you expect them to be generated?

Just
Jul 18 '05 #36
Just <ju**@xs4all.nl > writes:
But since .pyc's are always generated in the same directory as the .py
files, where else would you expect them to be generated?


At the directory where the zip archive is stored.

--
Godoy. <go***@ieee.org >
Jul 18 '05 #37
In article <m3************ @g2ctech.com>, Jorge Godoy <go***@ieee.org >
wrote:
Just <ju**@xs4all.nl > writes:
But since .pyc's are always generated in the same directory as the .py
files, where else would you expect them to be generated?


At the directory where the zip archive is stored.


How does that follow? The zip archive _itself_ is the "directory" where
the .py files are, why would Python suddenly choose to write .pyc files
one level up? And what about packages? It simply doesn't work that way.

Just
Jul 18 '05 #38
Paul Rubin wrote:
so you could say
import x(signed)
or
import x(signed, certfile='mycer ts.pem')

or whatever.


I believe that import is the wrong point in time for checking
signatures. You want to check the signature when the file is
added to sys.path, i.e.

imp.verify_sign ature(filename)
sys.path.append (filename)

or

imp.verify_all_ signatures(sys. path)

That way, you can guarantee that trusted code is on sys.path
all the time. Then, you can also trust any import statement.

Regards,
Martin
Jul 18 '05 #39
Just <ju**@xs4all.nl > writes:
In article <m3************ @g2ctech.com>, Jorge Godoy <go***@ieee.org >
wrote:
Just <ju**@xs4all.nl > writes:
> But since .pyc's are always generated in the same directory as the .py
> files, where else would you expect them to be generated?


At the directory where the zip archive is stored.


How does that follow? The zip archive _itself_ is the "directory" where
the .py files are, why would Python suddenly choose to write .pyc files
one level up? And what about packages? It simply doesn't work that way.


Because the implementation that allowed to unzip the "directory" and
find the files in there would also allow to place the '.pyc' in a
different place such as the real directory where the zip file resides.

Python didn't use to open zip files also, and now it does. I don't see
nothing wrong with making it also writing the '.pyc' files. Do you?

--
Godoy. <go***@ieee.org >
Jul 18 '05 #40

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

Similar topics

20
3703
by: Thomas Heller | last post by:
I'm currently working on a new version of py2exe, which will require Python 2.3 and later, because it uses the zipimport mechanism. Since py2exe is a distutils extension, and since C compilers are commonly available on most platforms except Windows, it would be fairly easy to let py2exe generate a C source file installing this import hook, and let distutils' C compiler build an executable file from this. Would this be useful, or would...
1
1779
by: fts2012 | last post by:
follow the dive into python ----------------------------------------------------------------- ----------------------------------------------------------------- I append the filepath of <<dive into python>>'s examples into sys.path,but ----------------------------------------------------------------- Traceback (most recent call last): File "<pyshell#5>", line 1, in <module>
0
136
by: Gabriel Genellina | last post by:
En Fri, 13 Jun 2008 22:38:24 -0300, Dan Yamins <dyamins@gmail.comescribió: I don't get *why* do you want to remove the 'archive' attribute before reloading the module. Just reload it *without* using `del` previously. When you reload a module, new definitions for existing names replace the old objects; new names are added; old names without a new value keep the previous value. (That is, objects are *replaced* and *added* but not...
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.