From 8db9261ccf2ac2d029c23bd7a3f633688ea7e6a9 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Wed, 9 Oct 2024 20:22:52 +0300 Subject: [PATCH] Revert "FIXUP: Factor out git_root" This reverts commit 6a5b6e4249e7818ca67ffde47578469d05e26382. --- dev_scripts/dev_utils.py | 14 -------------- dev_scripts/env.py | 10 ++++++++-- dev_scripts/qa.py | 15 ++++++++++++--- install/common/download-tessdata.py | 18 ++++++++++++++++-- 4 files changed, 36 insertions(+), 21 deletions(-) delete mode 100644 dev_scripts/dev_utils.py diff --git a/dev_scripts/dev_utils.py b/dev_scripts/dev_utils.py deleted file mode 100644 index 1a58e3a5d..000000000 --- a/dev_scripts/dev_utils.py +++ /dev/null @@ -1,14 +0,0 @@ -import pathlib -import subprocess - - -def git_root(): - """Get the root directory of the Git repo.""" - # FIXME: Use a Git Python binding for this. - # FIXME: Make this work if called outside the repo. - path = ( - subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) - .decode() - .strip("\n") - ) - return pathlib.Path(path) diff --git a/dev_scripts/env.py b/dev_scripts/env.py index db7b6ee6c..3c8230d1f 100755 --- a/dev_scripts/env.py +++ b/dev_scripts/env.py @@ -11,8 +11,6 @@ import urllib.request from datetime import date -from dev_utils import git_root - DEFAULT_GUI = True DEFAULT_USER = "user" DEFAULT_DRY = False @@ -274,6 +272,14 @@ def run(*args): ).stdout +def git_root(): + """Get the root directory of the Git repo.""" + # FIXME: Use a Git Python binding for this. + # FIXME: Make this work if called outside the repo. + path = run("git", "rev-parse", "--show-toplevel").decode().strip("\n") + return pathlib.Path(path) + + def user_data(): """Get the user data dir in (which differs on different OSes)""" home = pathlib.Path.home() diff --git a/dev_scripts/qa.py b/dev_scripts/qa.py index 43ef8af7d..07cfbbfdf 100755 --- a/dev_scripts/qa.py +++ b/dev_scripts/qa.py @@ -9,8 +9,6 @@ import subprocess import sys -from dev_utils import git_root - logger = logging.getLogger(__name__) CONTENT_QA = r"""## QA @@ -563,7 +561,18 @@ def __init__(self, try_auto=False, skip_manual=False, debug=False): self.debug = debug self.try_auto = try_auto self.skip_manual = skip_manual - self.src = git_root() + self.src = ( + subprocess.run( + [ + "git", + "rev-parse", + "--show-toplevel", + ], + stdout=subprocess.PIPE, + ) + .stdout.decode() + .strip("\n") + ) def task(*msgs, ref=None, auto=False): """Decorator for running a task automatically. diff --git a/install/common/download-tessdata.py b/install/common/download-tessdata.py index 73aca79a3..f2da96ee1 100644 --- a/install/common/download-tessdata.py +++ b/install/common/download-tessdata.py @@ -1,12 +1,13 @@ import hashlib import io import json +import pathlib +import re +import subprocess import sys import tarfile import urllib.request -from dev_utils import git_root - TESSDATA_RELEASES_URL = ( "https://api.github.com/repos/tesseract-ocr/tessdata_fast/releases/latest" ) @@ -14,6 +15,19 @@ TESSDATA_CHECKSUM = "d0e3bb6f3b4e75748680524a1d116f2bfb145618f8ceed55b279d15098a530f9" +def git_root(): + """Get the root directory of the Git repo.""" + # FIXME: Use a Git Python binding for this. + # FIXME: Make this work if called outside the repo. + cmd = ["git", "rev-parse", "--show-toplevel"] + path = ( + subprocess.run(cmd, check=True, stdout=subprocess.PIPE) + .stdout.decode() + .strip("\n") + ) + return pathlib.Path(path) + + def main(): share_dir = git_root() / "share" tessdata_dir = share_dir / "tessdata"