Skip to content

Commit

Permalink
implement git clone method
Browse files Browse the repository at this point in the history
  • Loading branch information
alchem0x2A committed Jan 14, 2024
1 parent 89ff13a commit ee1a02f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion sparc/docparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"TOL_POISSON": {"type": "double"},
}

sparc_repo_url = "https://github.com/SPARC-X/SPARC"

class SPARCDocParser(object):
"""Use regex to parse LaTeX doc to python API"""
Expand Down Expand Up @@ -305,6 +306,24 @@ def json_from_directory(cls, directory=".", include_subdirs=True, **kwargs):
json_string = json.dumps(root_dict, indent=True)
return json_string

@classmethod
def json_from_repo(cls, url=sparc_repo_url, version="master",
include_subdirs=True, **kwargs):
"""Download the source code from git and use json_from_directory to parse
"""
import tempfile
from subprocess import run
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
download_dir = tmpdir / "SPARC"
download_cmds = ["git", "clone", "--depth", "1", str(url), "SPARC"]
run(download_cmds, cwd=tmpdir)
json_string = cls.json_from_directory(directory=download_dir / "doc" / ".LaTeX",
include_subdirs=include_subdirs,
**kwargs)
return json_string



def convert_tex_parameter(text):
"""Conver a TeX string to non-escaped name (for parameter only)"""
Expand Down Expand Up @@ -584,7 +603,7 @@ def sanitize_type(param_dict):
help="Parse manual parameters from subdirs",
)
argp.add_argument(
"root", help="Root directory of the latex files"
"root", nargs="?", help="Root directory of the latex files"
) # root directory of the LaTeX files
args = argp.parse_args()
output = Path(args.output).with_suffix(".json")
Expand Down

0 comments on commit ee1a02f

Please sign in to comment.