GithubHelp home page GithubHelp logo

HamlPy cannot run from library.zip about hamlpy HOT 3 OPEN

a1s avatar a1s commented on August 24, 2024
HamlPy cannot run from library.zip

from hamlpy.

Comments (3)

a1s avatar a1s commented on August 24, 2024

This patch effectively disables wrapping for all Django template loaders at HamlPy module load time when Django modules do not reside on file system:

=== modified file 'hamlpy/template/utils.py'
--- hamlpy/template/utils.py    2013-05-09 01:59:39 +0000
+++ hamlpy/template/utils.py    2013-10-02 08:18:29 +0000
@@ -1,6 +1,6 @@
 import imp
 from os import listdir
-from os.path import dirname, splitext
+from os.path import dirname, isdir, splitext

 try:
   from django.template import loaders
@@ -25,7 +25,10 @@

 def package_contents(package):
     package_path = dirname(loaders.__file__)
-    contents = set([splitext(module)[0]
-            for module in listdir(package_path)
-            if module.endswith(MODULE_EXTENSIONS)])
+    if isdir(package_path):
+        contents = set([splitext(module)[0]
+                for module in listdir(package_path)
+                if module.endswith(MODULE_EXTENSIONS)])
+    else:
+        contents = set()
     return contents

With this change, one cannot import an arbitrary Django loader from hamlpy.template.

Loaders hamlpy.template.loaders.HamlPyFilesystemLoader and hamlpy.template.loaders.HamlPyAppDirectoriesLoader are not affected by this patch and work as expected as soon as module loading error is fixed.

from hamlpy.

a1s avatar a1s commented on August 24, 2024

By the way, I think more Pythonic approach would be to provide a way for explicit wrapping of needed loaders (in a way similar to what Django cached loader does) and not automatically create wrappers for everything we can find on a file system.

from hamlpy.

a1s avatar a1s commented on August 24, 2024

This is fixed in 84abeed (courtesy of @KACAH).

from hamlpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.