From 920cb9f8174c5421dffdea6cdd0f0783c1a950ca Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Fri, 12 Jul 2024 00:29:35 +0200 Subject: [PATCH] chore(deps): allow xopen major version 2 (#1532) See xopen changelog: https://github.com/pycompression/xopen/blob/main/README.rst#v200-2024-03-26 Maintain compatibility with v1 and v2, deprecate v1 with period of 4 months and requiring major version bump --------- Co-authored-by: Victor Lin <13424970+victorlin@users.noreply.github.com> --- CHANGES.md | 5 +++++ DEPRECATED.md | 4 ++++ augur/io/file.py | 14 +++++++++++++- setup.py | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b78fdeecd..e0ecf7ea6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,11 @@ ## __NEXT__ +### Features + +* Support xopen major version 2. Deprecate v1. Schedule for removal around November 2024. [#1532][] (@corneliusroemer) + +[#1532]: https://github.com/nextstrain/augur/pull/1532 ## 25.0.0 (10 July 2024) diff --git a/DEPRECATED.md b/DEPRECATED.md index 772b428c0..090326fe8 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -4,6 +4,10 @@ These features are deprecated, which means they are no longer maintained and will go away in a future major version of Augur. They are currently still available for backwards compatibility, but should not be used in new code. +## `xopen` major version 1 + +*Deprecated in version __NEXT__ (July 2024). Planned for removal at the earliest with major version 26 not before November 2024* + ## `augur parse` preference of `name` over `strain` as the sequence ID field *Deprecated in February 2024. Planned to be reordered June 2024 or after.* diff --git a/augur/io/file.py b/augur/io/file.py index 5b8a7bc13..1aa5f59af 100644 --- a/augur/io/file.py +++ b/augur/io/file.py @@ -2,9 +2,21 @@ from contextlib import contextmanager from io import IOBase from textwrap import dedent -from xopen import PipedCompressionReader, PipedCompressionWriter, xopen +from xopen import xopen from augur.errors import AugurError +# Workaround to maintain compatibility with both xopen v1 and v2 +# Around November 2024, we shall drop support for xopen v1 +# by removing the try-except block and using +# _PipedCompressionProgram directly +try: + from xopen import _PipedCompressionProgram as PipedCompressionReader + from xopen import _PipedCompressionProgram as PipedCompressionWriter +except ImportError: + from xopen import ( # type: ignore[attr-defined, no-redef] + PipedCompressionReader, + PipedCompressionWriter, + ) ENCODING = "utf-8" diff --git a/setup.py b/setup.py index efc46cd06..14ca3ee5e 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,7 @@ "phylo-treetime >=0.11.2, <0.12", "pyfastx >=1.0.0, <3.0", "scipy ==1.*", - "xopen[zstd] >=1.7.0, ==1.*" + "xopen[zstd] >=1.7.0, <3" # TODO: Deprecated, remove v1 support around November 2024 ], extras_require = { 'dev': [