scragg0x / realms-wiki

Git based wiki inspired by Gollum
http://realms.io
GNU General Public License v2.0
833 stars 91 forks source link

add templates from modules to MANIFEST.in #179

Closed stephane-martin closed 7 years ago

stephane-martin commented 7 years ago

Hello,

install via pip seems broken.

virtualenv testrealms
source testrealms/bin/activate
pip install realms-wiki
realms-wiki dev

... gives in browser the exception: TemplateNotFound: wiki/page.html"

Looks like MANIFEST.in is missing paths to templates insides modules...

gazpachoking commented 7 years ago

Hmm, can we make this more generic so it doesn't have to be listed for every module? Maybe realms/modules/*/templates/* or something. I think also we might need to add the static directories for the modules in there as well.

scragg0x commented 7 years ago

@gazpachoking I'm not sure if your example will work. Something like realms/modules *.html might

stephane-martin commented 7 years ago

Actually I think it does work, but the only way to know is to test or read pip/_vendor/distlib/manifest.py code (pain occurs), as python packaging doc is quite incomplete.

elif action == 'recursive-include':
    for pattern in patterns:
        if not self._include_pattern(pattern, prefix=thedir):
            logger.warning('no files found matching %r '
                           'under directory %r', pattern, thedir)

then

pattern_re = self._translate_pattern(pattern, anchor, prefix, is_regex)

then

prefix_re = self._glob_to_re(prefix)[:-len(empty_pattern)]

then this masterwork

def _glob_to_re(self, pattern):
    """Translate a shell-like glob pattern to a regular expression.

    Return a string containing the regex.  Differs from
    'fnmatch.translate()' in that '*' does not match "special characters"
    (which are platform-specific).
    """
    pattern_re = fnmatch.translate(pattern)

    # '?' and '*' in the glob pattern become '.' and '.*' in the RE, which
    # IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
    # and by extension they shouldn't match such "special characters" under
    # any OS.  So change all non-escaped dots in the RE to match any
    # character except the special characters (currently: just os.sep).
    sep = os.sep
    if os.sep == '\\':
        # we're using a regex to manipulate a regex, so we need
        # to escape the backslash twice
        sep = r'\\\\'
    escaped = r'\1[^%s]' % sep
    pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
    return pattern_re

(Urrrrggghhh)

So it should work :)