ElSnoMan / pyclinic

A library to test services in Python
MIT License
5 stars 1 forks source link

Dynamically identify the user's Workspace Root #13

Open ElSnoMan opened 3 years ago

ElSnoMan commented 3 years ago

Using absolute paths to our internal files is probably not a good way to find their Workspace Root.

def add_model_to_file(model: str, file_path: str = "model.py") -> str:
    """Add the Pydantic Model string to a Python file.

    Args:
        model: The Pydantic Model string.
        file_path: The path must include the .py file extension.
    """
    root = os.path.join(os.path.dirname(__file__), "../")
    fp = os.path.join(root, file_path)
    with open(fp, "a") as f:
        f.write(model)
    return f