From 8b179f76fe2e4dbcfb84e1e7a0c6743bbb81ee5b Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Wed, 14 Oct 2026 14:10:57 +0200 Subject: [PATCH] Record the CODATA edition instead of a timestamp in the generated constants file The header of NIST_codata.txt now states the CODATA edition (2006), in the same place and form as in current NIST files. The generator reads it and writes it into _codata.py in place of the "LAST GENERATED" timestamp. The timestamp changed on every build, so building the package always left _codata.py modified in the working copy; the generated file now matches the committed one exactly. _codata.py keeps one constant per line, so it is easy to search, and these lines can be up to 153 characters long. Ruff's line-length check (E501) is turned off for this file; all other rules still apply to it. --- pyproject.toml | 2 ++ quantities/constants/NIST_codata.txt | 2 +- quantities/constants/_codata.py | 1 + setup.py | 8 ++++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4fe21e69..36a685e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,3 +73,5 @@ ignore = [] "quantities/units/*.py" = ["F401"] "quantities/constants/*.py" = ["F401"] "quantities/__init__.py" = ["F401", "F403"] +# Generated from NIST_codata.txt with one constant per line. +"quantities/constants/_codata.py" = ["E501"] diff --git a/quantities/constants/NIST_codata.txt b/quantities/constants/NIST_codata.txt index 9f8094d7..9881463a 100644 --- a/quantities/constants/NIST_codata.txt +++ b/quantities/constants/NIST_codata.txt @@ -1,6 +1,6 @@ Fundamental Physical Constants --- Complete Listing - + 2006 CODATA adjustment From: http://physics.nist.gov/constants diff --git a/quantities/constants/_codata.py b/quantities/constants/_codata.py index 8cace73f..310e81f3 100644 --- a/quantities/constants/_codata.py +++ b/quantities/constants/_codata.py @@ -1,5 +1,6 @@ # THIS FILE IS AUTOMATICALLY GENERATED # ANY CHANGES MADE HERE WILL BE LOST +# Source: CODATA 2006 recommended values, from NIST_codata.txt physical_constants = {} diff --git a/setup.py b/setup.py index 1d139deb..6da26f59 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,8 @@ +import re + from setuptools import Command, setup from setuptools.command.build_py import build_py as _build from setuptools.command.sdist import sdist as _sdist -from datetime import datetime class data(Command): @@ -19,12 +20,15 @@ def finalize_options(self): def run(self): with open('quantities/constants/NIST_codata.txt') as f: data = f.read() + edition = re.search(r'(\d{4}) CODATA adjustment', data) + if edition is None: + raise ValueError('CODATA edition not found in NIST_codata.txt') data = data.split('\n')[10:-1] with open('quantities/constants/_codata.py', 'w') as f: f.write('# THIS FILE IS AUTOMATICALLY GENERATED\n') f.write('# ANY CHANGES MADE HERE WILL BE LOST\n') - f.write(f'# LAST GENERATED: {datetime.now()}\n\n') + f.write(f'# Source: CODATA {edition[1]} recommended values, from NIST_codata.txt\n\n') f.write('physical_constants = {}\n\n') for line in data: name = line[:55].rstrip().replace('mag.','magnetic')