Skip to content

Commit

Permalink
Fix the everest doc generator
Browse files Browse the repository at this point in the history
The generator would only function within a
editable install. The behavior is changed such
that it has to be run from within the ERT
repository, in one of the parent directories of
the file that is generated.
  • Loading branch information
verveerpj committed Sep 30, 2024
1 parent e607feb commit 967abff
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/everest/docs/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import sys
from pathlib import Path

from everest.docs.generate_docs_from_config_spec import generate_docs_pydantic_to_rst

committed_file = (
Path(__file__).parents[3] / "docs" / "everest" / "config_generated.rst"
).resolve()
GENERATED_FILE = Path("docs") / "everest" / "config_generated.rst"

parts = GENERATED_FILE.parts
while parts and not Path(*parts).exists():
parts = parts[1:]
if not parts:
print(
f"""The file to update ('{GENERATED_FILE}') was not found.
The generator must be run from one of the parent directories of
'{GENERATED_FILE.parts[-1]}' within the ERT source directory.
Please change the current directory accordingly and re-run."""
)
sys.exit()

print(f"Writing new docs contents to {committed_file}")
docs_content = generate_docs_pydantic_to_rst()
with open(committed_file, "w", encoding="utf-8") as fp:
with Path(*parts).open("w", encoding="utf-8") as fp:
fp.write(docs_content)

print(f"Writing updated docs to {committed_file} complete, you may now commit it.")
print(f"Generated docs written to {GENERATED_FILE}")
print("Please commit the generated file.")

0 comments on commit 967abff

Please sign in to comment.