Skip to content

map_guides

Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.

FoSpy._dev.testing.map_guides

EXPECTED_FN module-attribute

EXPECTED_FN = 'optional_fields'

REQUIRED_FN module-attribute

REQUIRED_FN = 'required_fields'

SUB_DIR module-attribute

SUB_DIR = 'FoSpy_Map_Guides'

dir_prompt

dir_prompt(title='Select a directory')
Source code in FoSpy/_dev/testing/_utils.py
def dir_prompt(title="Select a directory"):
    root = Tk()
    root.withdraw()

    filepath = filedialog.askdirectory(
        title=title
    )
    if not filepath:
        raise Exception("No directory selected.")
    return filepath

generate_map_guide

generate_map_guide(
    cls=Synthesis, include_optional=False, parent_str=""
)
Source code in FoSpy/json/help/__init__.py
def generate_map_guide(cls=Synthesis, include_optional=False, parent_str=""):
    from ...blocks import ListBlock, SingleBlock

    opt_set = cls.build_validators() if include_optional else cls.build_req_validators()
    opt_set.pop("ext", None)

    guide = {}

    for key, validator in opt_set.items():
        current_key = parent_str + key
        if isinstance(validator, type):
            if issubclass(validator, SingleBlock):
                guide_dct = generate_map_guide(validator, include_optional=include_optional, parent_str=current_key+".")
                guide[key] = guide_dct
                continue
            elif issubclass(validator, ListBlock):
                reqCls = validator._reqCls
                example = [generate_map_guide(reqCls, include_optional=include_optional, parent_str=current_key+f"[{i}].") for i in range(2)]
                guide[key] = example
                continue
            elif issubclass(validator, list):
                example = [current_key+f"[{i}]" for i in range(2)]
                guide[key] = example
                continue

        guide[key] = current_key

    return guide

get_current_branch

get_current_branch()
Source code in FoSpy/_dev/testing/_utils.py
def get_current_branch():
    return subprocess.check_output(
        ["git", "rev-parse", "--abbrev-ref", "HEAD"],
        cwd=REPO_PATH,
        text=True
    ).strip()

run

run(dirpath=None, open_result=True)
Source code in FoSpy/_dev/testing/map_guides.py
def run(dirpath=None, open_result=True):
    if dirpath is None:
        try:
            dirpath = dir_prompt(title="Select a folder to save the map guides to.")
        except Exception:
            print("Failed to select directory. Aborting...")
            return



    outdir = Path(dirpath) / SUB_DIR

    if str(dirpath).endswith(SUB_DIR):
        outdir = outdir.parent

    os.makedirs(outdir, exist_ok=True)

    guides = {
        EXPECTED_FN: generate_map_guide(include_optional=True),
        REQUIRED_FN: generate_map_guide(include_optional=False)
    }

    for name, guide in guides.items():
        with open(outdir / f"{name}.json", "w") as f:
            json.dump(guide, f, indent=4)

    readme = dedent(f"""
    # FoSpy Map Guides

    This folder contains guide files for creating JSON maps FoSpy. Consult
    https://errthumt.github.io/FoSpy/incoming/guides/maps for more information. The
    documentation site has similar guide files, but the guide files generated here
    are up-to-date with the version of FoSpy you were using at the time of
    generation ({get_current_branch()} branch). This may be different than the version used to generate the guide
    files on the website.
    """)

    with open(outdir / "README.txt", "w") as f:
        f.write(readme)

    if open_result:
        os.startfile(outdir)