Skip to content

Commit

Permalink
Automate build date generation with hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
rdoursenaud committed Jun 28, 2023
1 parent bf7c1a7 commit 24928ab
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ remotely.
- [x] [UPX](https://upx.github.io/) support
- How to build:
- Review [denonremote.spec](denonremote.spec)
- Use `hatch run build:pyinstaller`
- Use `hatch build; hatch run build:pyinstaller`
- [x] [Nuitka](https://nuitka.net) (Alpha support for Microsoft Windows)
- Use `hatch run build:nuitka`
- Use `hatch build; hatch run build:nuitka`
- [ ] [PyOxidiser](https://github.com/indygreg/PyOxidizer)
- [ ] [cx-Freeze](https://pypi.org/project/cx-Freeze/) for multiplatform support?
- [ ] VST plugin? (Not required if MIDI input is implemented but would be neat to have in the monitoring section of a
Expand Down
18 changes: 2 additions & 16 deletions denonremote.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
# SPDX-FileCopyrightText: 2021-2022 Raphaël Doursenaud <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from datetime import datetime

from PyInstaller.building.api import PYZ, EXE
from PyInstaller.building.api import EXE, PYZ
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.datastruct import Tree
from kivy.tools.packaging.pyinstaller_hooks import get_deps_minimal, hookspath, runtime_hooks
from kivy_deps import sdl2, glew
from kivy_deps import glew, sdl2

from denonremote.__about__ import __version__

Expand All @@ -29,12 +27,6 @@ dependencies = get_deps_minimal(exclude_ignored=False, window=True, text=True, i
dependencies['hiddenimports'].append('twisted.internet._threadedselect')
dependencies['excludes'].remove('twisted')

# Set build date
BUILD_FILE = 'src/denonremote/__build__.py'
__build_date__ = datetime.now().isoformat()
with open(BUILD_FILE, 'w') as f:
f.write(f'__build_date__ = "{__build_date__}"\r')

a = Analysis(
cipher=block_cipher,
datas=added_files,
Expand Down Expand Up @@ -71,9 +63,3 @@ exe = EXE(
upx_exclude=[],
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
)

# Cleanup the build date file
try:
os.remove(BUILD_FILE)
except FileNotFoundError:
pass
36 changes: 36 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This Python file uses the following encoding: utf-8
#
# SPDX-FileCopyrightText: 2023 Raphaël Doursenaud <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from datetime import datetime
from typing import Any

from hatchling.builders.hooks.plugin.interface import BuildHookInterface

BUILD_FILE = 'src/denonremote/__build__.py'


class CustomBuildHook(BuildHookInterface):

def _get_build_file(self):
return os.path.join(self.root, BUILD_FILE)

def clean(self, versions: list[str]) -> None:
# Cleanup the build file
try:
os.remove(self._get_build_file())
except FileNotFoundError:
pass

def initialize(self, version: str, build_data: dict[str, Any]) -> None:
print(version)
# Create the build
__build_date__ = datetime.now().isoformat()
build_file = self._get_build_file()
with open(build_file, 'w') as f:
f.write(f'__build_date__ = "{__build_date__}"\r')
# __build__.py is in .gitignore. We must force its inclusion
self.build_config.force_include[build_file] = BUILD_FILE
print(self.build_config.force_include)
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ path = 'src/denonremote/__about__.py'

[tool.hatch.envs.default]
python = '3.11'
dependencies = [
'hatchling', # Required for the custom hook
]

[[tool.hatch.envs.test.matrix]]
python = [
Expand Down Expand Up @@ -128,6 +131,8 @@ exclude_lines = [
'if TYPE_CHECKING:',
]

[tool.hatch.build.hooks.custom]

[tool.hatch.build.targets.sdist]
exclude = [
'/.github',
Expand Down

0 comments on commit 24928ab

Please sign in to comment.