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
Milestone

Comments

@sqlalchemy-bot
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Feb 22, 2010

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

@sqlalchemy-bot sqlalchemy-bot commented Feb 25, 2010

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

@sqlalchemy-bot sqlalchemy-bot commented Feb 25, 2010

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.3"
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Mar 5, 2010

Michael Bayer (@zzzeek) wrote:

89eae3c

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Mar 5, 2010

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.