Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


module discovery is slightly broken on Windows #142

posativ opened this Issue · 4 comments

2 participants

Owner may not return the Acrylamid module but rather (if any) something else. This only applies to modules in a subdirectory (like the search view).


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 == '':
            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  ***
filename:    b:/code/acrylamid\acrylamid\
dotname:     acrylamid
filename:    b:/code/acrylamid\acrylamid\defaults\
dotname:     acrylamid.defaults
filename:    b:/code/acrylamid\acrylamid\defaults\html5\
dotname:     acrylamid.defaults.html5
filename:    b:/code/acrylamid\acrylamid\defaults\shadowplay\jinja2\
dotname:     acrylamid.defaults.shadowplay.jinja2
filename:    b:/code/acrylamid\acrylamid\filters\
dotname:     acrylamid.filters
filename:    b:/code/acrylamid\acrylamid\lib\
dotname:     acrylamid.lib
filename:    b:/code/acrylamid\acrylamid\specs\
dotname:     acrylamid.specs
filename:    b:/code/acrylamid\acrylamid\tasks\
dotname:     acrylamid.tasks
filename:    b:/code/acrylamid\acrylamid\templates\
dotname:     acrylamid.templates
filename:    b:/code/acrylamid\acrylamid\views\
dotname:     acrylamid.views
filename:    b:/code/acrylamid\acrylamid\views\search\

Note printed path differs from stored path:

>>> os.sep
>>> root
>>> print(root)
>>> filename
>>> print(filename)

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\, the module name is not search but whereas b:/code/acrylamid\acrylamid\views\ 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 posativ closed this in 8728ceb

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/ 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]

Many thanks Martin!

I confirm that with 0.6.7 the search files are created:

B:\www\acr>acr compile --search
  ←[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

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

...\Python27>dir /s/b


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

B:\code\acrylamid>python misc\ 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
Something went wrong with that request. Please try again.