Skip to content

Commit

Permalink
🗃️ Dynamically read/write from VERSION file
Browse files Browse the repository at this point in the history
This file will be written upon the execution of the `build_py` command class and will not be included in the source distribution directly.
  • Loading branch information
agriyakhetarpal committed Mar 23, 2024
1 parent 81c61b7 commit 915c0f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,6 @@ hugo/binaries/*

# Hugo builder cache
hugo_cache/

# Hugo version file
hugo/VERSION
3 changes: 2 additions & 1 deletion hugo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from sys import argv
from sys import platform as sysplatform

HUGO_VERSION = "0.124.1"
with open(path.join(path.dirname(__file__), "VERSION")) as f: # noqa: PTH123, PTH120, PTH118
HUGO_VERSION = f.read().strip()

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

Expand Down
24 changes: 22 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from setuptools.command.build_py import build_py
from wheel.bdist_wheel import bdist_wheel

# Has to be kept in sync with the version in hugo/cli.py
HUGO_VERSION = "0.124.1"
HUGO_RELEASE = (
f"https://github.com/gohugoio/hugo/archive/refs/tags/v{HUGO_VERSION}.tar.gz"
Expand Down Expand Up @@ -51,7 +50,6 @@
+ FILE_EXT
)


class HugoWriter(build_py):
"""
A custom pre-installation command that writes the version of Hugo being built
Expand All @@ -73,6 +71,27 @@ def run(self) -> None:
super().run()


class HugoWriter(build_py):
"""
A custom pre-installation command that writes the version of Hugo being built
to hugo/VERSION so that the version is available to read at runtime.
"""

def initialize_options(self) -> None:
return super().initialize_options()

def finalize_options(self) -> None:
return super().finalize_options()

def run(self) -> None:
"""Write the version of Hugo being built to hugo/VERSION."""
with open("hugo/VERSION", "w") as version_file: # noqa: PTH123
version_file.write(HUGO_VERSION)
version_file.write("\n")

super().run()


class HugoBuilder(build_ext):
"""
Custom extension command that builds Hugo from source, placing the binary into
Expand Down Expand Up @@ -356,6 +375,7 @@ def run(self):
)
],
cmdclass={
"build_py": HugoWriter,
"build_ext": HugoBuilder,
"clean": Cleaner,
"bdist_wheel": HugoWheel,
Expand Down

0 comments on commit 915c0f9

Please sign in to comment.