Remove Hatch

This commit is contained in:
Jip-Hop 2024-07-16 17:28:16 +02:00
parent 22ea9842d4
commit 962b238f6a
9 changed files with 0 additions and 246 deletions

View File

@ -1,59 +0,0 @@
# Inspiration from <https://github.com/pypa/hatch/issues/669>
name: Build
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
workflow_dispatch:
jobs:
build:
name: Build jlmkr tool
runs-on: ubuntu-24.04
strategy:
matrix:
python-version:
- "3.11" # TrueNAS SCALE 24.04 Dragonfish
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
- name: Install Hatch
uses: pypa/hatch@install
- name: Run style check
run: hatch fmt --check
# - name: Run unit tests
# run: hatch run +py=${{ matrix.python-version }} test:test
- name: Build distribution
run: hatch build -t zipapp -t appzip
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# path:
# - dist/jlmkr
# - dist/jlmkr-*.zip
# if-no-files-found: error

View File

@ -1,3 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only

View File

@ -1,56 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
import os
from io import BytesIO
from pathlib import Path
from typing import Any, Callable, Iterable
from zipapp import create_archive
from hatchling.builders.plugin.interface import BuilderInterface
class ZipAppBuilder(BuilderInterface):
PLUGIN_NAME = "zipapp"
def get_version_api(self) -> dict[str, Callable[..., str]]:
return {"standard": self.build_standard}
def clean(self, directory: str, versions: Iterable[str]) -> None:
try:
os.remove(Path(directory, 'jlmkr'))
except:
pass
def build_standard(self, directory: str, **build_data: Any) -> str:
# generate zipapp source archive
pyzbuffer = BytesIO()
create_archive('src/jlmkr', target=pyzbuffer,
interpreter='=PLACEHOLDER=',
# main='donor.jlmkr:main',
compressed=True)
zipdata = pyzbuffer.getvalue() #.removeprefix(b"#!=PLACEHOLDER=\n")
# output with preamble
outpath = Path(directory, 'jlmkr')
with open(outpath, 'wb') as f:
f.write(preamble(self.metadata.version).encode())
f.write(zipdata)
os.chmod(outpath, 0o755)
return os.fspath(outpath)
# 10 lines will conveniently match the default of head(1)
def preamble(version): return f'''#!/usr/bin/env python3
jlmkr {version}
Persistent Linux 'jails' on TrueNAS SCALE to install software (k3s, docker, portainer, podman, etc.) with full access to all files via bind mounts.
SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
SPDX-License-Identifier: LGPL-3.0-only
-=-=-=- this is a zip file -=-=-=- what follows is binary -=-=-=-
'''

View File

@ -1,11 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
from hatchling.plugin import hookimpl
from build_app import ZipAppBuilder
@hookimpl
def hatch_register_builder():
return ZipAppBuilder

View File

@ -1,22 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]
[project]
name = "hatch-zipapp"
version = "0.0.dev0"
classifiers = [
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Private :: Do Not Upload",
]
dependencies = ["hatchling"]
[project.entry-points.hatch]
zipapp = "hooks_app"
[tool.hatch.build.targets.wheel]
packages = ["."]

View File

@ -1,3 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only

View File

@ -1,59 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
# hat tip: <https://github.com/dairiki/hatch-zipped-directory/blob/master/hatch_zipped_directory/builder.py>
import os
from hatchling.builders.config import BuilderConfig
from hatchling.builders.plugin.interface import BuilderInterface
from hatchling.builders.utils import normalize_relative_path
from pathlib import Path
from typing import Any, Callable, Iterable
from zipfile import ZipFile, ZIP_DEFLATED
class AppZipBuilderConfig(BuilderConfig): pass
class AppZipBuilder(BuilderInterface):
PLUGIN_NAME = "appzip"
@classmethod
def get_config_class(cls):
return AppZipBuilderConfig
def get_version_api(self) -> dict[str, Callable[..., str]]:
return {'standard': self.build_standard}
def clean(self, directory: str, versions: Iterable[str]) -> None:
for filename in os.listdir(directory):
if filename.startswith('jlmkr-') and filename.endswith('.zip'):
os.remove(Path(directory, filename))
def build_standard(self, directory: str, **build_data: Any) -> str:
outpath = Path(directory, f'jlmkr-{self.metadata.version}.zip')
with ZipFile(outpath, 'w') as zip:
zip.write(Path(directory, 'jlmkr'), 'jlmkr')
force_map = build_data['force_include']
for included_file in self.recurse_forced_files(force_map):
zip.write(
included_file.relative_path,
included_file.distribution_path,
ZIP_DEFLATED)
return os.fspath(outpath)
def get_default_build_data(self) -> dict[str, Any]:
build_data: dict[str, Any] = super().get_default_build_data()
extra_files = []
if self.metadata.core.readme_path:
extra_files.append(self.metadata.core.readme_path)
if self.metadata.core.license_files:
extra_files.extend(self.metadata.core.license_files)
force_include = build_data.setdefault("force_include", {})
for fn in map(normalize_relative_path, extra_files):
force_include[os.path.join(self.root, fn)] = Path(fn).name
build_data['force_include'] = force_include
return build_data

View File

@ -1,11 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
from hatchling.plugin import hookimpl
from build_zip import AppZipBuilder
@hookimpl
def hatch_register_builder():
return AppZipBuilder

View File

@ -1,22 +0,0 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]
[project]
name = "hatch-appzip"
version = "0.0.dev0"
classifiers = [
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Private :: Do Not Upload",
]
dependencies = ["hatchling"]
[project.entry-points.hatch]
appzip = "hooks_zip"
[tool.hatch.build.targets.wheel]
packages = ["."]