Skip to content

Commit

Permalink
Make Windows runner speedier
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal authored Jan 8, 2024
2 parents 3cf7a2a + e998839 commit eb685b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def release(session: nox.Session) -> None:
session.run("python", "-m", "build")


@nox.session(name="venv")
@nox.session(name="venv", reuse_venv=True)
def venv(session: nox.Session) -> None:
"""Create a virtual environment and install wheels from a specified folder into it."""
folder = "dist" if session.interactive else "wheelhouse"
Expand Down
27 changes: 18 additions & 9 deletions python_hugo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,39 @@

from __future__ import annotations

import os
import platform
import sys
# Reduce expenses for various imports
from functools import lru_cache
from os import execvp, path
from platform import machine
from subprocess import check_call
from sys import argv
from sys import platform as sysplatform

HUGO_VERSION = "0.121.2"

FILE_EXT = ".exe" if sys.platform == "win32" else ""
FILE_EXT = ".exe" if sysplatform == "win32" else ""

HUGO_PLATFORM = {
"darwin": "darwin",
"linux": "linux",
"win32": "windows",
}[sys.platform]
}[sysplatform]

HUGO_ARCH = {
"x86_64": "amd64",
"arm64": "arm64",
"AMD64": "amd64",
"aarch64": "arm64",
}[platform.machine()]
}[machine()]


@lru_cache(maxsize=1)
def hugo_executable():
"""
Returns the path to the Hugo executable.
"""
return os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH120
return path.join( # noqa: PTH118
path.dirname(__file__), # noqa: PTH120
"binaries",
f"hugo-{HUGO_VERSION}-{HUGO_PLATFORM}-{HUGO_ARCH}" + FILE_EXT,
)
Expand All @@ -47,4 +52,8 @@ def __call():
Hugo binary entry point. Passes all command-line arguments to Hugo.
"""
print(MESSAGE)
os.execvp(hugo_executable(), ["hugo", *sys.argv[1:]])
if sysplatform == "win32":
# execvp broken on Windows, use subprocess instead to not launch a new shell
check_call([hugo_executable(), *argv[1:]])
else:
execvp(hugo_executable(), ["hugo", *argv[1:]])

0 comments on commit eb685b0

Please sign in to comment.