Merge pull request #584 from cjmayo/releasedate

Set release date from HEAD
This commit is contained in:
Chris Mayo 2021-12-13 19:22:19 +00:00 committed by GitHub
commit 01dfc13886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 16 deletions

1
.gitignore vendored
View file

@ -16,6 +16,7 @@
/coverage
MANIFEST
_LinkChecker_configdata.py
_release_date
Changelog.linkchecker*
/*-stamp
/*-stamp-*

View file

@ -10,6 +10,7 @@ include install-rpm.sh
include .project
include .pydevproject
include .yamllint
include _release_date
recursive-include cgi-bin \
*.css \
@ -81,4 +82,4 @@ recursive-include windows \
*.pfx \
*.pvk
prune .github/
prune .github

View file

@ -15,8 +15,9 @@ python = python
universal = 0
[check-manifest]
ignore-bad-ideas = *.mo
ignore = *.rej
ignore =
*.rej
_release_date
[flake8]
filename =

View file

@ -30,8 +30,8 @@ import sys
if sys.version_info < (3, 6, 0, "final", 0):
raise SystemExit("This program requires Python 3.6 or later.")
import os
import re
import stat
import subprocess
from pathlib import Path
# import Distutils stuff
@ -40,6 +40,7 @@ from distutils.command.install_lib import install_lib
from distutils.command.build import build
from distutils.command.clean import clean
from distutils.command.install_data import install_data
from setuptools.command.sdist import sdist
from distutils.dir_util import remove_tree
from distutils.file_util import write_file
from distutils import util, log
@ -57,6 +58,8 @@ else:
AppName = "LinkChecker"
Description = "check links in web documents or full websites"
RELEASE_DATE_FILE = "_release_date"
def get_long_description():
"""Try to read long description from README.rst."""
@ -83,19 +86,19 @@ def cnormpath(path):
return path
release_ro = re.compile(r"\(released (.+)\)")
def get_release_date():
"""Parse and return relase date as string from doc/changelog.txt."""
fname = os.path.join("doc", "changelog.txt")
def get_release_date(for_sdist=False):
"""Return release date as a string from the most recent commit."""
release_date = "unknown"
with open(fname) as fd:
# the release date is on the first line
line = fd.readline()
mo = release_ro.search(line)
if mo:
release_date = mo.groups(1)
# need git >= 2.25.0 for %cs
cp = subprocess.run(["git", "log", "-n 1", "HEAD", "--format=%cI"],
stdout=subprocess.PIPE, universal_newlines=True)
if cp.stdout:
release_date = cp.stdout.split("T")[0]
elif not for_sdist:
try:
release_date = Path(RELEASE_DATE_FILE).read_text()
except FileNotFoundError:
pass
return release_date
@ -104,6 +107,12 @@ def get_portable():
return os.environ.get("LINKCHECKER_PORTABLE", "0")
class MySdist(sdist):
def run(self):
Path(RELEASE_DATE_FILE).write_text(get_release_date(for_sdist=True))
super().run()
class MyBuild(build):
"""Custom build with translation compilation"""
@ -350,6 +359,7 @@ setup(
long_description_content_type="text/x-rst",
distclass=MyDistribution,
cmdclass={
"sdist": MySdist,
"build": MyBuild,
"install_lib": MyInstallLib,
"install_data": MyInstallData,