mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 11:40:25 +05:00
Package ArchiveBox commit metadata safely
This commit is contained in:
parent
97d82c2615
commit
983708f230
@ -41,7 +41,7 @@ def detect_installed_version(PACKAGE_DIR: Path = PACKAGE_DIR):
|
||||
|
||||
@cache
|
||||
def get_COMMIT_HASH() -> str | None:
|
||||
for env_var in ("ARCHIVEBOX_COMMIT_HASH", "COMMIT_HASH"):
|
||||
for env_var in ("ARCHIVEBOX_COMMIT_HASH",):
|
||||
env_commit_hash = os.environ.get(env_var, "").strip()
|
||||
if re.fullmatch(r"[0-9a-fA-F]{40}", env_commit_hash):
|
||||
return env_commit_hash
|
||||
@ -55,6 +55,13 @@ def get_COMMIT_HASH() -> str | None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
packaged_commit_hash = (PACKAGE_DIR / "COMMIT_SHA").read_text().strip()
|
||||
if re.fullmatch(r"[0-9a-fA-F]{40}", packaged_commit_hash):
|
||||
return packaged_commit_hash
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _read_git_file(git_dir: Path, ref: str) -> str | None:
|
||||
try:
|
||||
return git_dir.joinpath(ref).read_text().strip()
|
||||
@ -76,6 +83,13 @@ def get_COMMIT_HASH() -> str | None:
|
||||
return None
|
||||
|
||||
try:
|
||||
try:
|
||||
pyproject_text = (PACKAGE_DIR.parent / "pyproject.toml").read_text()
|
||||
except FileNotFoundError:
|
||||
pyproject_text = ""
|
||||
if not re.search(r'^name = "archivebox"$', pyproject_text, re.MULTILINE):
|
||||
return None
|
||||
|
||||
git_dir = PACKAGE_DIR.parent / ".git"
|
||||
if git_dir.is_file():
|
||||
gitdir_line = git_dir.read_text().strip()
|
||||
@ -95,11 +109,6 @@ def get_COMMIT_HASH() -> str | None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
return list((PACKAGE_DIR.parent / ".git/refs/heads/").glob("*"))[0].read_text().strip()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@ -45,7 +45,8 @@ def _create_git_repo(tmp_path: Path) -> tuple[Path, Path, str]:
|
||||
copied_version = repo / "archivebox" / "config" / "version.py"
|
||||
copied_version.parent.mkdir(parents=True)
|
||||
shutil.copyfile(version.__file__, copied_version)
|
||||
_git(git, repo, "add", "archivebox/config/version.py")
|
||||
(repo / "pyproject.toml").write_text('[project]\nname = "archivebox"\nversion = "0.0.0"\n')
|
||||
_git(git, repo, "add", "archivebox/config/version.py", "pyproject.toml")
|
||||
_git(git, repo, "commit", "-m", "add ArchiveBox version module")
|
||||
return git, repo, _git(git, repo, "rev-parse", "HEAD")
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "archivebox",
|
||||
"version": "0.9.35rc169",
|
||||
"version": "0.9.35rc170",
|
||||
"repository": "github:ArchiveBox/ArchiveBox",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
33
pdm_build.py
Normal file
33
pdm_build.py
Normal file
@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from pdm.backend.hooks import Context
|
||||
|
||||
|
||||
def _current_commit(root: Path) -> str | None:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(root), "rev-parse", "HEAD"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
return None
|
||||
|
||||
commit_hash = result.stdout.strip()
|
||||
return commit_hash if re.fullmatch(r"[0-9a-f]{40}", commit_hash) else None
|
||||
|
||||
|
||||
def pdm_build_update_files(context: Context, files: dict[str, Path]) -> None:
|
||||
commit_hash = _current_commit(context.root)
|
||||
if not commit_hash:
|
||||
return
|
||||
|
||||
dst = context.ensure_build_dir() / "archivebox" / "COMMIT_SHA"
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
dst.write_text(f"{commit_hash}\n", encoding="utf-8")
|
||||
files["archivebox/COMMIT_SHA"] = dst
|
||||
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "archivebox"
|
||||
version = "0.9.35rc169"
|
||||
version = "0.9.35rc170"
|
||||
requires-python = ">=3.13"
|
||||
description = "Self-hosted internet archiving solution."
|
||||
authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}]
|
||||
@ -83,7 +83,7 @@ dependencies = [
|
||||
"abxbus==2.5.40", # EventBus API
|
||||
"abxpkg", # direct imports only; version constrained by abx-dl -> abx-plugins
|
||||
"abx-plugins", # direct imports only; version constrained by abx-dl
|
||||
"abx-dl==1.12.32", # shared ArchiveBox downloader package
|
||||
"abx-dl==1.12.33", # shared ArchiveBox downloader package
|
||||
### UUID7 backport for Python <3.14
|
||||
"uuid7>=0.1.0; python_version < '3.14'", # provides the uuid_extensions module on Python 3.13
|
||||
]
|
||||
@ -170,10 +170,6 @@ build-backend = "pdm.backend"
|
||||
|
||||
[tool.pdm.build]
|
||||
includes = ["archivebox/"]
|
||||
source-includes = [
|
||||
".git/HEAD",
|
||||
".git/refs/heads/dev",
|
||||
]
|
||||
excludes = [
|
||||
".cache",
|
||||
".mypy_cache",
|
||||
@ -348,7 +344,7 @@ Donate = "https://github.com/ArchiveBox/ArchiveBox/wiki/Donations"
|
||||
|
||||
|
||||
[tool.bumpver]
|
||||
current_version = "v0.9.35rc169"
|
||||
current_version = "v0.9.35rc170"
|
||||
version_pattern = "vMAJOR.MINOR.PATCH[PYTAGNUM]"
|
||||
commit_message = "bump version {old_version} -> {new_version}"
|
||||
tag_message = "{new_version}"
|
||||
|
||||
10
uv.lock
10
uv.lock
@ -24,7 +24,7 @@ abxpkg = "2100-01-01T00:00:00Z"
|
||||
|
||||
[[package]]
|
||||
name = "abx-dl"
|
||||
version = "1.12.32"
|
||||
version = "1.12.33"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "abx-plugins" },
|
||||
@ -39,9 +39,9 @@ dependencies = [
|
||||
{ name = "rich" },
|
||||
{ name = "rich-click" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/a1/fb/f16cd432b0fe332dfbb48ad44c0db83fda58071e126e140aa0fdaa30b51b/abx_dl-1.12.32.tar.gz", hash = "sha256:783ca4bb599e8e965affc12bd223cac55d5569eca55b3cb83a5b3cc831759064", size = 86778, upload-time = "2026-07-29T03:32:12.216Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e1/3c/b30ba1b5f82dc0bc45ff6321f75c4f1b060d7370fd1774a5a76d17ed08a0/abx_dl-1.12.33.tar.gz", hash = "sha256:dfb437ca753b4cdf6c2e9552d7faf5f68d00d760c1f4029c33e7ad6a39d79ade", size = 86721, upload-time = "2026-07-29T05:06:53.474Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ee/ed/6945e671919464e2d461f4743b44a050545211f8e7ce5dc9d88403ac08dd/abx_dl-1.12.32-py3-none-any.whl", hash = "sha256:f9022f003a8a53fd09fe402175df2ccc590816f8550f33e867bbe9418a088337", size = 90708, upload-time = "2026-07-29T03:32:11.092Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/69/3b/be30b74465c2cb0a3663112b6eaf4bf3ea6091beb10ffc9a168879b33069/abx_dl-1.12.33-py3-none-any.whl", hash = "sha256:8f6875f3716437296b3f82616491f1660b91a12de3fd6b50b84433897ff81a3f", size = 90584, upload-time = "2026-07-29T05:06:52.231Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -123,7 +123,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "archivebox"
|
||||
version = "0.9.35rc169"
|
||||
version = "0.9.35rc170"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "abx-dl" },
|
||||
@ -223,7 +223,7 @@ dev = [
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "abx-dl", specifier = "==1.12.32" },
|
||||
{ name = "abx-dl", specifier = "==1.12.33" },
|
||||
{ name = "abx-plugins" },
|
||||
{ name = "abxbus", specifier = "==2.5.40" },
|
||||
{ name = "abxpkg" },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user