Overview
Comment:add pacakge disovery, and additional comment styles (different languages)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f03780244f3b89cd5dbf1a0f5dcca340bb3b2e306445d2b7bc2fe97ce7dbfb40
User & Date: mario on 2022-10-31 18:56:16
Other Links: manifest | tags
Context
2022-11-01
16:57
add new comment extraction rx check-in: 3ad4b252ac user: mario tags: trunk
2022-10-31
18:56
add pacakge disovery, and additional comment styles (different languages) check-in: f03780244f user: mario tags: trunk
12:56
doc additions, add params for setup and gui, fix flit sample check-in: 93aac20151 user: mario tags: trunk
Changes

Modified pluginconf/__init__.py from [5e7e9e9afe] to [97ed648af8].

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    And `meta.config` already parsed as a list (`OptionList`) of dictionaries.
    """

    # Try via pkgutil first,
    # find any plugins.* modules, or main packages
    if module:
        search = plugin_base + kwargs.get("extra_base", [])
        for base, sfx in itertools.product(search, [".py"]):
            try:
                #log.debug(f"mod={base} fn={filename}.py")
                src = get_data(filename=module+sfx, decode=True, file_root=base)
                if src:
                    break
            except (IOError, OSError, FileNotFoundError):
                continue  # plugin_meta_extract() will print a notice later







|







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    And `meta.config` already parsed as a list (`OptionList`) of dictionaries.
    """

    # Try via pkgutil first,
    # find any plugins.* modules, or main packages
    if module:
        search = plugin_base + kwargs.get("extra_base", [])
        for base, sfx in itertools.product(search, [".py", "/__init__.py"]):
            try:
                #log.debug(f"mod={base} fn={filename}.py")
                src = get_data(filename=module+sfx, decode=True, file_root=base)
                if src:
                    break
            except (IOError, OSError, FileNotFoundError):
                continue  # plugin_meta_extract() will print a notice later
359
360
361
362
363
364
365

366
367
368
369
370
371
372
        "config": [],
        "doc": ""
    }

    # Extract coherent comment block
    src = src.replace("\r", "")
    if not literal:

        src = rx.comment.search(src)
        if not src:
            log.warning("Couldn't read source meta information: %s", filename)
            return meta
        src = src.group(0)
        src = rx.hash.sub("", src).strip()








>







359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
        "config": [],
        "doc": ""
    }

    # Extract coherent comment block
    src = src.replace("\r", "")
    if not literal:
        src = rx.header.sub("", src)
        src = rx.comment.search(src)
        if not src:
            log.warning("Couldn't read source meta information: %s", filename)
            return meta
        src = src.group(0)
        src = rx.hash.sub("", src).strip()

466
467
468
469
470
471
472






473





474


475
476
477
478
479
480
481
class rx:
    """
    Pretty crude comment splitting approach. But works
    well enough already. Technically a YAML parser would
    do better; but is likely overkill.
    """







    comment = re.compile(r"""(^ {0,4}#.*\n)+""", re.M)





    hash = re.compile(r"""(^ {0,4}#{1,2} {0,3}\r*)""", re.M)


    keyval = re.compile(r"""
        ^([\w-]+):(.*$(?:\n(?![\w-]+:).+$)*)   # plain key:value lines
    """, re.M | re.X)
    config = re.compile(r"""
        \{ ((?: [^\{\}]+ | \{[^\}]*\} )+) \}   # JSOL/YAML scheme {...} dicts
        | \< (.+?) \>                          # old <input> HTML style
    """, re.X)







>
>
>
>
>
>
|
>
>
>
>
>
|
>
>







467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
class rx:
    """
    Pretty crude comment splitting approach. But works
    well enough already. Technically a YAML parser would
    do better; but is likely overkill.
    """

    header = re.compile(r"""
        (\A (
            \#! \s+ /.+ |                      # shebang
            <\?php .*
        ) $)+
    """, re.M | re.X)
    comment = re.compile(r"""
        (^ [ ]{0,4} \# .*\n)+ |                # general
        (^ [ ]{0,4} // .*\n)+ |                # C++-style
        /\* [\s\S]+? \*/ |                     # C-multiline
        <\# [\s\S]+? \#> | \{\# [\s\S]+? \#\}  # PS/Perl
    """, re.M | re.X)
    hash = re.compile(r"""
        (^ [ ]{0,4} [#*/]{1,2} [ ]{0,3})
    """, re.M | re.X)
    keyval = re.compile(r"""
        ^([\w-]+):(.*$(?:\n(?![\w-]+:).+$)*)   # plain key:value lines
    """, re.M | re.X)
    config = re.compile(r"""
        \{ ((?: [^\{\}]+ | \{[^\}]*\} )+) \}   # JSOL/YAML scheme {...} dicts
        | \< (.+?) \>                          # old <input> HTML style
    """, re.X)

Added test/config_altsyntax.py version [28af7a5552].























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# type: test
# title: alternative syntaxes
# description: other comment types
# version: 0.7.8
# 
# Kinda have to do snippets here.

import pytest
import re
import textwrap
import pluginconf

def _parse(text):
    text = re.sub(r"\A\n", "", text)
    text = textwrap.dedent(text)
    return pluginconf.plugin_meta(src=text)


def multiline_c():
    c_style= """
    /**
     * api: c
     * title: example
     * version: 3.5.1
     * category: multiline
     *
     * Do we get a comment?
     */
    """
    assert _parse(c_style).version == "3.5.1"
    assert _parse(c_style).doc == "Do we get a comment?"

def multiline_ps1():
    ps1_style= """
    <#
     # api: cpp
     # title: second
    version: 2.1
     # category: nonpython
     #
     # Won't work without hashes
     #>
    """
    print(_parse(ps1_style))
    assert _parse(ps1_style).version == "2.1"
    # requires adapting the continuation line detection (including spaced points)
    # and detecting multiline markers, and stripping them (end up in doc else)

def indent_cpp():
    cpp_style= """
    // api: cpp
    // title: third
    // version: 3.3
    // category: doubleprefix
    //
    // Basically just // instead of #
    """
    assert _parse(cpp_style).version == "3.3"