Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_project_properties(project_dir):
auto_test(config.project, _auto_allow_exceptions=(exceptions.NoProjectFound,))
auto_test(
config.project, directory=project_dir, _auto_allow_exceptions=(exceptions.NoProjectFound,)
)
def test_as_html(temporary_dir, project_dir, chdir):
with chdir(temporary_dir):
# Directory with no project
with pytest.raises(exceptions.NoProjectFound):
api.as_html()
# Rendering should succeed as soon as a project is within the directory
temp_project_dir = os.path.join(temporary_dir, "portray")
shutil.copytree(project_dir, temp_project_dir)
with chdir(temp_project_dir):
api.as_html()
# Rendering a second time should fail
with pytest.raises(exceptions.DocumentationAlreadyExists):
api.as_html()
# Unless we enable overwritting destination
api.as_html(overwrite=True)
# Or, we output to a different location
def project(directory: str, config_file: str, **overrides) -> dict:
"""Returns back the complete configuration - including all sub configuration components
defined below that `portray` was able to determine for the project
"""
if not (
os.path.isfile(os.path.join(directory, config_file))
or os.path.isfile(os.path.join(directory, "setup.py"))
or "modules" in overrides
):
raise NoProjectFound(directory)
project_config: Dict[str, Any] = {**PORTRAY_DEFAULTS, "directory": directory}
if os.path.isfile(os.path.join(directory, "setup.py")):
project_config.update(setup_py(os.path.join(directory, "setup.py")))
project_config.update(toml(os.path.join(directory, config_file)))
project_config.update(overrides)
project_config.setdefault("modules", [os.path.basename(os.getcwd()).replace("-", "_")])
project_config.setdefault("pdocs", {}).setdefault("modules", project_config["modules"])
mkdocs_config = project_config.get("mkdocs", {})
mkdocs_config.setdefault(
"extra_markdown_extensions", project_config.get("extra_markdown_extensions", [])
)
project_config["mkdocs"] = mkdocs(directory, **mkdocs_config)