diff --git a/.gitignore b/.gitignore index afb63af6..7ec80d87 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ /coverage MANIFEST _LinkChecker_configdata.py +_release_date Changelog.linkchecker* /*-stamp /*-stamp-* diff --git a/MANIFEST.in b/MANIFEST.in index 9572893e..1b7e7a88 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/setup.cfg b/setup.cfg index eb9c984a..3e2c0772 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,8 +15,9 @@ python = python universal = 0 [check-manifest] -ignore-bad-ideas = *.mo -ignore = *.rej +ignore = + *.rej + _release_date [flake8] filename = diff --git a/setup.py b/setup.py index f912d19c..c369f347 100755 --- a/setup.py +++ b/setup.py @@ -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,