[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-12-30 Thread Decorater

Decorater added the comment:

OK, Well I just tested and it sadly don't support import hooks that adds 
support for importing custom file types or file types python does know about 
with a uncommon extension inside of zip files which is somewhat sad. However if 
someone was to do something similar to py2exe's import hook allowing memory 
loading pyd and so files they could allow it to work for their import hook's 
needs.

--
keywords: +patch
Added file: http://bugs.python.org/file46090/zipimport.rst.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-12-17 Thread Brett Cannon

Brett Cannon added the comment:

The cutoff for 3.6.0 has passed, but documentation patches can still go in for 
3.6.1 (and 3.5.3).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-12-16 Thread Decorater

Decorater added the comment:

Well, Will there be any documentations for this before 3.6 final release or no 
because this would be nice to know for other people who would like to do 
something similar.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

Changes by Decorater :


--
nosy: +brett.cannon, eric.snow, ncoghlan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

Changes by Decorater :


--
nosy: +twouters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

Changes by Decorater :


--
nosy:  -brett.cannon, eric.snow, ncoghlan, paul.moore, tim.golden, twouters, 
zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Steve Dower

Changes by Steve Dower :


--
nosy: +brett.cannon, eric.snow, ncoghlan, twouters -steve.dower

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

Changes by Decorater :


--
components:  -Windows

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

Changes by Decorater :


--
assignee:  -> docs@python
components: +Documentation -Interpreter Core
nosy: +docs@python

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28816] Document if zipimport can respect import hooks to load custom files from zip.

2016-11-28 Thread Decorater

New submission from Decorater:

I am wondering so lets say for example if I was to make a json import hook 
(code below):

from importlib.machinery import FileFinder
import json
import sys


class ExtensionImporter(object):
"""Base Importer Class."""
def __init__(self, extension_list):
self.extensions = extension_list

def find_loader(self, name, path):
"""Filds some loaders for importing the module."""
self.path = path
return self

def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
return None


class JsonImporter(ExtensionImporter):
"""JSON importer Class."""
def __init__(self):
super(JsonImporter, self).__init__(['.json'])

def load_module(self, fullname):
"""Loads modules found with the extension"""
premodule = super(JsonImporter, self).load_module(fullname)
if premodule is None:
 with open(self.path, 'r') as f:
module = json.load(f)
sys.modules[fullname] = module
return module
raise ImportError('Couldn't open path')

extension_importers = [JsonImporter()]
hook_list = []
for importer in extension_importers:
hook_list.append((importer.find_loader, importer.extensions))

sys.path_hooks.insert(0, FileFinder.path_hook(*hook_list))
sys.path_importer_cache.clear()


What if I had those json files in a zip file and used ZipImport on that zip 
file would it use that import hook that I shared above if all other import 
methods fail to import those json files (obvously they would fail though)?

There should be documentation to explain if it supports user created import 
hooks that they create using importlib.

This is because I would be very happy if zipimport supports my own import hook 
if any other method of importing files from that zip file fails but mine ends 
up working. It also allows people to load up many other formats (provided they 
know the format) as if it was a python script. (of if they compressed it in a 
custom file like for example a RAR file that WinRAR can create. And yes I would 
support a RARImport for rar files.

--
components: Interpreter Core, Windows
messages: 281850
nosy: Decorater, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Document if zipimport can respect import hooks to load custom files from 
zip.
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com