Skip to content

Commit

Permalink
FIXUP: Factor out git_root
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Oct 9, 2024
1 parent e690b25 commit 6a5b6e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
14 changes: 14 additions & 0 deletions dev_scripts/dev_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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)
10 changes: 2 additions & 8 deletions dev_scripts/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import urllib.request
from datetime import date

from dev_utils import git_root

DEFAULT_GUI = True
DEFAULT_USER = "user"
DEFAULT_DRY = False
Expand Down Expand Up @@ -272,14 +274,6 @@ 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()
Expand Down
15 changes: 3 additions & 12 deletions dev_scripts/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import subprocess
import sys

from dev_utils import git_root

logger = logging.getLogger(__name__)

CONTENT_QA = r"""## QA
Expand Down Expand Up @@ -561,18 +563,7 @@ 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 = (
subprocess.run(
[
"git",
"rev-parse",
"--show-toplevel",
],
stdout=subprocess.PIPE,
)
.stdout.decode()
.strip("\n")
)
self.src = git_root()

def task(*msgs, ref=None, auto=False):
"""Decorator for running a task automatically.
Expand Down
18 changes: 2 additions & 16 deletions install/common/download-tessdata.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
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"
)
TESSDATA_ARCHIVE_URL = "https://github.com/tesseract-ocr/tessdata_fast/archive/{tessdata_version}/tessdata_fast-{tessdata_version}.tar.gz"
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"
Expand Down

0 comments on commit 6a5b6e4

Please sign in to comment.