commit: d8d559f446149a194c351ba831cbdc66aba88eaf Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Sat Dec 27 19:29:13 2025 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sun Dec 28 14:04:42 2025 +0000 URL: https://gitweb.gentoo.org/proj/gemato.git/commit/?id=d8d559f4
Fix datetime.datetime.utcnow DeprecationWarning ``` /usr/share/gemato/gen_fast_metamanifest.py:119: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). ``` We can't use `datetime.UTC` because of old Python, so use `datetime.timezone.utc` instead to support <py3.11. Signed-off-by: Sam James <sam <AT> gentoo.org> Part-of: https://github.com/gentoo/gemato/pull/40 Closes: https://github.com/gentoo/gemato/pull/40 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> gemato/cli.py | 4 ++-- gemato/openpgp.py | 2 +- tests/test_recursiveloader.py | 2 +- utils/gen_fast_metamanifest.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gemato/cli.py b/gemato/cli.py index 4333775..9c3bf24 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -453,7 +453,7 @@ class UpdateCommand(BaseUpdateMixin, GematoCommand): LOGGER.info(f'Updating Manifests in {p}...') - start_ts = datetime.datetime.utcnow() + start_ts = datetime.datetime.now(datetime.timezone.utc) m.update_entries_for_directory(relpath, **update_kwargs) # write TIMESTAMP if requested, or if already there @@ -509,7 +509,7 @@ class CreateCommand(BaseUpdateMixin, GematoCommand): LOGGER.info(f'Creating Manifests in {p}...') - start_ts = datetime.datetime.utcnow() + start_ts = datetime.datetime.now(datetime.timezone.utc) m.update_entries_for_directory() # write TIMESTAMP if requested diff --git a/gemato/openpgp.py b/gemato/openpgp.py index 155bdef..1d2823a 100644 --- a/gemato/openpgp.py +++ b/gemato/openpgp.py @@ -791,7 +791,7 @@ class PGPyEnvironment: if not vr: raise OpenPGPVerificationFailure( f'Bad signature made by key {k.fingerprint}') - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) sig_expire = msg.signatures[0].expires_at if sig_expire is not None and sig_expire < now: raise OpenPGPVerificationFailure( diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index 3079b96..50a9318 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -783,7 +783,7 @@ DATA test 11 SHA1 561295c9cbf9d6b2f6428414504a8deed3020641 @classmethod def create(cls, tmp_path): super().create(tmp_path) - future_dt = (datetime.datetime.utcnow() + + future_dt = (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)) with open(tmp_path / 'Manifest', 'w') as f: f.write(cls.MANIFESTS['Manifest'].replace( diff --git a/utils/gen_fast_metamanifest.py b/utils/gen_fast_metamanifest.py index 2f7628d..36d22eb 100755 --- a/utils/gen_fast_metamanifest.py +++ b/utils/gen_fast_metamanifest.py @@ -116,7 +116,7 @@ IGNORE packages p.map(gen_fast_manifest.gen_manifest, manifest_dir_generator(1), chunksize=64) # special directories: we split Manifest there, and add timestamp - ts = datetime.datetime.utcnow().strftime( + ts = datetime.datetime.now(datetime.timezone.utc).strftime( 'TIMESTAMP %Y-%m-%dT%H:%M:%SZ\n').encode('ascii') make_toplevel('metadata/glsa', ts, pgp_key) make_toplevel('metadata/news', ts, pgp_key) @@ -129,7 +129,7 @@ IGNORE packages p.map(gen_fast_manifest.gen_manifest, list(manifest_dir_generator(4))) # final split - ts = datetime.datetime.utcnow().strftime( + ts = datetime.datetime.now(datetime.timezone.utc).strftime( 'TIMESTAMP %Y-%m-%dT%H:%M:%SZ\n').encode('ascii') make_toplevel('', ts, pgp_key)
