Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module_directory not handled properly when given an absolute template path on Windows #128

Closed
sqlalchemy-bot opened this issue Feb 22, 2010 · 4 comments
Labels
bug Something isn't working low priority runtime
Milestone

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Anonymous

When an absolute path is given on windows (i.e. c:\ or d:) for the filename parameter to Template.init, then the module_directory parameter is ignored because of how os.path.join works.

A patch is attached to emulate the way absolute paths work on posix systems.


Attachments: win32fix.diff

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

I'd prefer this:

Index: mako/template.py
===================================================================
--- mako/template.py    (revision 473)
+++ mako/template.py    (working copy)
@@ -57,7 +57,9 @@
             self.uri = uri
         elif filename:
             self.module_id = re.sub(r'\W', "_", filename)
-            self.uri = filename
+            drive, path = os.path.splitdrive(filename)
+            path = os.path.normpath(path).replace(os.path.sep, "/")
+            self.uri = path
         else:
             self.module_id = "memory:" + hex(id(self))
             self.uri = self.module_id
@@ -95,8 +97,8 @@
                     u = u[1:]
                 path = os.path.abspath(
                         os.path.join(
-                            module_directory.replace('/', os.path.sep), 
-                            u + ".py"
+                            os.path.normpath(module_directory), 
+                            os.path.normpath(u) + ".py"
                             )
                         )
             else:

can you test ? This should have a platform independent unit test in order to be committed (i.e. set os.path to os.ntpath, check desired output, set os.path to os.posixpath, etc.).

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.3"

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

89eae3c

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working low priority runtime labels Nov 26, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.3 milestone Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority runtime
Projects
None yet
Development

No branches or pull requests

1 participant