22
33import logging
44import requests
5- import subprocess
6- from pathlib import Path
75
86import click
97
8+ from opm_python_docs import helpers
9+
1010URL_SIMULATORS = "https://raw.githubusercontent.com/OPM/opm-simulators/master/python/docstrings_simulators.json"
1111URL_COMMON = "https://raw.githubusercontent.com/OPM/opm-common/master/python/docstrings_common.json"
1212URL_DUNE_MODULE = "https://raw.githubusercontent.com/OPM/opm-simulators/master/dune.module"
1313
14- def get_git_root () -> Path :
15- """Return the absolute path of the opm-python-documentation repository's root."""
16- try :
17- output = subprocess .check_output (
18- ["git" , "rev-parse" , "--show-toplevel" ],
19- stderr = subprocess .STDOUT
20- )
21- except subprocess .CalledProcessError :
22- # Handle the error if we're not inside a Git repo, etc.
23- raise RuntimeError ("Not a valid Git repository or other error occurred." )
24- # Check that the parent directory is the opm-python-documentation repository
25- root = output .decode ("utf-8" ).strip ()
26- if not root .endswith ("opm-python-documentation" ):
27- raise RuntimeError ("Not in the opm-python-documentation repository." )
28- return Path (root )
2914
3015def convert_pr_to_commit_hash (repo : str , pr_number : int ) -> str :
3116 """Convert a PR number to a commit hash."""
@@ -49,7 +34,7 @@ def download_docstring_file(url: str, pr_number: int|None) -> None:
4934 logging .info (f"Downloading docstrings file from { url } " )
5035 response = requests .get (url )
5136 response .raise_for_status () # Raises 404 if the file is not found
52- git_root_dir = get_git_root ()
37+ git_root_dir = helpers . get_git_root ()
5338 save_path = git_root_dir / "python" / filename
5439 with open (str (save_path ), "wb" ) as file :
5540 file .write (response .content )
@@ -60,7 +45,7 @@ def download_dune_module() -> None:
6045 logging .info ("Downloading dune.module file" )
6146 response = requests .get (URL_DUNE_MODULE )
6247 response .raise_for_status ()
63- git_root_dir = get_git_root ()
48+ git_root_dir = helpers . get_git_root ()
6449 save_path = git_root_dir / "dune.module"
6550 with open (save_path , "wb" ) as file :
6651 file .write (response .content )
0 commit comments