Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Reduce need for getting addons version #5157

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion utils/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ def read_file(name):
return ""


_cached_version_branch = None


def get_version_branch(major_version, addons_git_repo_url):
"""Check if version branch for the current GRASS version exists,
if not, take branch for the previous version
For the official repo we assume that at least one version branch is present
Getting the latest version is expensive because we need to ask online for the latest
branch. Hence we cache the version branch in a global variable.

:param major_version int: GRASS GIS major version
:param addons_git_repo_url str: Addons Git ropository URL
:param addons_git_repo_url str: Addons Git repository URL

:return version_branch str: version branch
"""
global _cached_version_branch
if _cached_version_branch is not None:
return _cached_version_branch

version_branch = f"grass{major_version}"
if gs:
branch = gs.Popen(
Expand All @@ -73,9 +82,28 @@ def get_version_branch(major_version, addons_git_repo_url):
)
if version_branch not in gs.decode(branch):
version_branch = "grass{}".format(int(major_version) - 1)

_cached_version_branch = version_branch
return version_branch


def get_addons_url():
"""Function to get the addons URL
Getting the latest URL is expensive because we need to ask online for the latest
version.
"""
return urlparse.urljoin(
base_url,
urlparse.urljoin(
"grass-addons/tree/",
get_version_branch(
major,
urlparse.urljoin(base_url, "grass-addons/"),
),
),
)


def has_src_code_git(src_dir):
"""Has core module or addon source code Git

Expand Down
31 changes: 11 additions & 20 deletions utils/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from mkdocs import (
read_file,
get_version_branch,
get_addons_url,
get_last_git_commit,
top_dir as topdir,
get_addon_path,
Expand All @@ -57,16 +57,6 @@
grass_git_branch + "/",
),
)
addons_url = urlparse.urljoin(
base_url,
urlparse.urljoin(
"grass-addons/tree/",
get_version_branch(
major,
urlparse.urljoin(base_url, "grass-addons/"),
),
),
)


def _get_encoding():
Expand Down Expand Up @@ -469,15 +459,8 @@ def to_title(name):
if not year:
year = str(datetime.now().year)

# check the names of scripts to assign the right folder
curdir = os.path.abspath(os.path.curdir)
if curdir.startswith(topdir + os.path.sep):
source_url = trunk_url
pgmdir = curdir.replace(topdir, "").lstrip(os.path.sep)
else:
# addons
source_url = addons_url
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])

url_source = ""
addon_path = None
if os.getenv("SOURCE_URL", ""):
Expand All @@ -486,7 +469,7 @@ def to_title(name):
# Addon is installed from the local dir
if os.path.exists(os.getenv("SOURCE_URL")):
url_source = urlparse.urljoin(
addons_url,
get_addons_url(),
addon_path,
)
else:
Expand All @@ -495,6 +478,14 @@ def to_title(name):
addon_path,
)
else:
# check the names of scripts to assign the right folder
if curdir.startswith(topdir + os.path.sep):
source_url = trunk_url
pgmdir = curdir.replace(topdir, "").lstrip(os.path.sep)
else:
# addons
source_url = get_addons_url()
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])
url_source = urlparse.urljoin(source_url, pgmdir)
if sys.platform == "win32":
url_source = url_source.replace(os.path.sep, "/")
Expand Down
28 changes: 9 additions & 19 deletions utils/mkmarkdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from mkdocs import (
read_file,
get_version_branch,
get_addons_url,
get_last_git_commit,
top_dir,
get_addon_path,
Expand Down Expand Up @@ -59,25 +59,8 @@ def parse_source(pgm):
grass_git_branch + "/",
),
)
addons_url = urlparse.urljoin(
base_url,
urlparse.urljoin(
"grass-addons/tree/",
get_version_branch(
major,
urlparse.urljoin(base_url, "grass-addons/"),
),
),
)

cur_dir = os.path.abspath(os.path.curdir)
if cur_dir.startswith(top_dir + os.path.sep):
source_url = main_url
pgmdir = cur_dir.replace(top_dir, "").lstrip(os.path.sep)
else:
# addons
source_url = addons_url
pgmdir = os.path.sep.join(cur_dir.split(os.path.sep)[-3:])

url_source = ""
addon_path = None
Expand All @@ -87,7 +70,7 @@ def parse_source(pgm):
# Addon is installed from the local dir
if os.path.exists(os.getenv("SOURCE_URL")):
url_source = urlparse.urljoin(
addons_url,
get_addons_url(),
addon_path,
)
else:
Expand All @@ -96,6 +79,13 @@ def parse_source(pgm):
addon_path,
)
else:
if cur_dir.startswith(top_dir + os.path.sep):
source_url = main_url
pgmdir = cur_dir.replace(top_dir, "").lstrip(os.path.sep)
else:
# addons
source_url = get_addons_url()
pgmdir = os.path.sep.join(cur_dir.split(os.path.sep)[-3:])
url_source = urlparse.urljoin(source_url, pgmdir)
if sys.platform == "win32":
url_source = url_source.replace(os.path.sep, "/")
Expand Down
Loading