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 discovery is slightly broken on Windows #142

Closed
posativ opened this issue Mar 13, 2013 · 4 comments
Closed

module discovery is slightly broken on Windows #142

posativ opened this issue Mar 13, 2013 · 4 comments

Comments

@posativ
Copy link
Owner

posativ commented Mar 13, 2013

https://github.com/posativ/acrylamid/blob/master/acrylamid/helpers.py#L411 may not return the Acrylamid module but rather (if any) something else. This only applies to modules in a subdirectory (like the search view).

@maphew
Copy link
Contributor

maphew commented Mar 14, 2013

I don't understand much of what's going on in there, my python fu is weak, but I believe the error is related to replacing the dir separator /, which on Windows may be either '/' or '', usually the latter. You could try .replace(os.sep, '.') instead(?)

#!/usr/bin/env python

import sys
import os
from os.path import join, dirname, isdir, isfile, commonprefix, normpath

PATH = 'b:/code/acrylamid'

for root, dirs, files in os.walk(PATH):
    for fname in files:
        if fname == '__init__.py':
            filename = os.path.join(root, fname)

            prefix = commonprefix((PATH, filename))
            if prefix:
                dname, x = os.path.split(filename[len(prefix):])
                dotname = dname.replace(os.sep, '.').lstrip('.')

            print('filename:\t', filename)
            print('dotname:\t', dotname)

results in Pyscripter interactive interpreter:

*** Remote Interpreter Reinitialized  ***
>>> 
[Dbg]>>> 
filename:    b:/code/acrylamid\acrylamid\__init__.py
dotname:     acrylamid
filename:    b:/code/acrylamid\acrylamid\defaults\__init__.py
dotname:     acrylamid.defaults
filename:    b:/code/acrylamid\acrylamid\defaults\html5\__init__.py
dotname:     acrylamid.defaults.html5
filename:    b:/code/acrylamid\acrylamid\defaults\shadowplay\jinja2\__init__.py
dotname:     acrylamid.defaults.shadowplay.jinja2
filename:    b:/code/acrylamid\acrylamid\filters\__init__.py
dotname:     acrylamid.filters
filename:    b:/code/acrylamid\acrylamid\lib\__init__.py
dotname:     acrylamid.lib
filename:    b:/code/acrylamid\acrylamid\specs\__init__.py
dotname:     acrylamid.specs
filename:    b:/code/acrylamid\acrylamid\tasks\__init__.py
dotname:     acrylamid.tasks
filename:    b:/code/acrylamid\acrylamid\templates\__init__.py
dotname:     acrylamid.templates
filename:    b:/code/acrylamid\acrylamid\views\__init__.py
dotname:     acrylamid.views
filename:    b:/code/acrylamid\acrylamid\views\search\__init__.py
dotname:     acrylamid.views.search

Note printed path differs from stored path:

>>> os.sep
'\\'
>>> root
'b:/code/acrylamid\\misc'
>>> print(root)
b:/code/acrylamid\misc
>>> filename
'b:/code/acrylamid\\acrylamid\\views\\search\\__init__.py'
>>> print(filename)
b:/code/acrylamid\acrylamid\views\search\__init__.py
>>> 

@posativ
Copy link
Owner Author

posativ commented Mar 14, 2013

Basically I try to import a module by path using the imp module (compatible way for Python 2 and 3). Unfortunately you can't point imp to the filename. You have to extract the right module name (and make it possible to write your own filters/views in your blog).

If the filename is b:/code/acrylamid\acrylamid\views\search__init_.py_, the module name is not search but acrylamid.views.search whereas b:/code/acrylamid\acrylamid\views\index.py is resolved to acrylamid.views.index but only if the module is inside of Acrylamid. This circumvents certain edge cases where a module is named like an already existing one (such as filters.html and html in the std library of Python 3).

My Windows-foo is still very limited, but I'll try to fix this as fast as possible.

@posativ
Copy link
Owner Author

posativ commented Mar 14, 2013

Pushed to master and legacy/0.6 (as version 0.6.7). If you want to test the search with the provided command line:

$ acrylamid compile --search
$ python misc/search.py blog/output/search/p.js python
exact match: [0, 2, 3, 133, 8, 14, 15, 16, 19, 20, 22 ... ]
partial match: [19, 85, 158, 58, 39, 22, 23]

@maphew
Copy link
Contributor

maphew commented Mar 15, 2013

Many thanks Martin!

I confirm that with 0.6.7 the search files are created:

B:\www\acr>acr compile --search
...snip...
  ←[1;33m   update←[0m  [0.05s] output\acr\index.html
  ←[1;32m   create←[0m  [0.11s] output\acr\search\src\0.txt
  ←[1;32m   create←[0m  output\acr\search\src\1.txt
  ←[1;32m   create←[0m  output\acr\search\src\2.txt
...snip...

However misc/search.py doesn't exist in the pypi package:

...\Python27>dir /s/b search.py

...\Python27\Lib\site-packages\acrylamid\specs\search.py
...\Python27\Lib\site-packages\pip\commands\search.py

I found it in on the master branch, and can confirm that that does work on my system:

B:\code\acrylamid>python misc\search.py B:\www\acr\output\search\p.js python
exact match: [10, 5]
partial match: [5, 5]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants