Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Last active February 8, 2019 06:29

Revisions

  1. avalanchy revised this gist Feb 8, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions factories_lookup.py
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,11 @@


    def factories_lookup(base_dir):
    """Yields all model factories in a way expected by shell_plus command
    """Yields all model factories in a way expected by shell_plus command.
    Returned generator is evaluated only when running shell_plus. Evaluation
    itself on my machine takes ± 3.63 ms.
    Usage:
    SHELL_PLUS_POST_IMPORTS = factories_lookup(BASE_DIR)
    """
  2. avalanchy revised this gist Feb 7, 2019. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions factories_lookup.py
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,6 @@ def factories_lookup(base_dir):
    p = p.replace('/', '.')
    p = p.replace('.py', '')
    with open(m, 'r') as f:
    for l in f:
    c = re.match('class ([A-Za-z]+Factory)', l)
    if c:
    yield p, c.group(1)
    c = re.findall('class ([A-Za-z]+Factory)', f.read())
    if c:
    yield p, c
  3. avalanchy revised this gist Feb 7, 2019. No changes.
  4. avalanchy revised this gist Feb 7, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion factories_lookup.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,11 @@


    def factories_lookup(base_dir):
    """Yields all model factories in a way expected by shell_plus command"""
    """Yields all model factories in a way expected by shell_plus command
    Usage:
    SHELL_PLUS_POST_IMPORTS = factories_lookup(BASE_DIR)
    """
    modules = pathlib.Path(base_dir).glob('**/factories.py')
    for module in modules:
    m = str(module)
  5. avalanchy created this gist Feb 7, 2019.
    18 changes: 18 additions & 0 deletions factories_lookup.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import pathlib
    import re


    def factories_lookup(base_dir):
    """Yields all model factories in a way expected by shell_plus command"""
    modules = pathlib.Path(base_dir).glob('**/factories.py')
    for module in modules:
    m = str(module)
    p = m.replace(base_dir, '')
    p = p[1:]
    p = p.replace('/', '.')
    p = p.replace('.py', '')
    with open(m, 'r') as f:
    for l in f:
    c = re.match('class ([A-Za-z]+Factory)', l)
    if c:
    yield p, c.group(1)