Skip to content

Commit d94f51e

Browse files
Removed clause duplicates when accessing clauses of a clausified formula. Added support for zstd compression.
1 parent 3048885 commit d94f51e

File tree

4 files changed

+160
-107
lines changed

4 files changed

+160
-107
lines changed

pysat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# current version
1212
#==============================================================================
13-
VERSION = (1, 8, 'dev', 19)
13+
VERSION = (1, 8, 'dev', 20)
1414

1515

1616
# PEP440 Format

pysat/_fileio.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
Module description
2323
==================
2424
25-
This simple module provides a basic interface to input/output operations on
26-
files. Its key design feature is the ability to work with both uncompressed
27-
and compressed files through a unified interface, thus, making it easier
28-
for a user to deal with various types of compressed files. The compression
29-
types supported include gzip, bzip2, and lzma (xz).
25+
This simple module provides a basic interface to input/output operations
26+
on files. Its key design feature is the ability to work with both
27+
uncompressed and compressed files through a unified interface, thus,
28+
making it easier for a user to deal with various types of compressed
29+
files. The compression types supported include gzip, bzip2, lzma (xz), and
30+
zstandard (zstd).
3031
3132
The module is supposed to be mainly used by :mod:`pysat.formula`.
3233
@@ -66,6 +67,13 @@
6667
except ImportError: # for Python2 without lzma
6768
lzma_present = False
6869

70+
zstd_present = True
71+
try:
72+
from compression import zstd
73+
except ImportError: # zstandard is introduced in Python 3.14
74+
zstd_present = False
75+
76+
6977

7078
#
7179
#==============================================================================
@@ -75,9 +83,10 @@ class FileObject(object):
7583
open files creating standard file pointers and closing them. The class
7684
is used when opening DIMACS files for reading and writing. Supports
7785
both uncompressed and compressed files. Compression algorithms
78-
supported are ``gzip``, ``bzip2``, and ``lzma``. Algorithm ``lzma`` can
79-
be used in Python 3 by default and also in Python 2 if the
80-
``backports.lzma`` package is installed.
86+
supported are ``gzip``, ``bzip2``, ``lzma``, and ``zstd``. Algorithm
87+
``lzma`` can be used in Python 3 by default and also in Python 2 if
88+
the ``backports.lzma`` package is installed. Algorithm ``zstandard``
89+
can be used in Python 3.14 and later.
8190
8291
Note that the class opens a file in text mode.
8392
@@ -90,8 +99,9 @@ class FileObject(object):
9099
:type compression: str
91100
92101
Compression type can be ``None``, ``'gzip'``, ``'bzip2'``, ``'lzma'``,
93-
as well as ``'use_ext'``. If ``'use_ext'`` is specified, compression
94-
algorithm is defined by the extension of the given file name.
102+
``'zstd'``, as well as ``'use_ext'``. If ``'use_ext'`` is specified,
103+
compression algorithm is defined by the extension of the given file
104+
name.
95105
"""
96106

97107
def __init__(self, name, mode='r', compression=None):
@@ -109,9 +119,9 @@ def __init__(self, name, mode='r', compression=None):
109119

110120
def open(self, name, mode='r', compression=None):
111121
"""
112-
Open a file pointer. Note that a file is *always* opened in text
113-
mode. The method inherits its input parameters from the constructor
114-
of :class:`FileObject`.
122+
Open a file pointer. Note that a file is *always* opened in
123+
text mode. The method inherits its input parameters from the
124+
constructor of :class:`FileObject`.
115125
"""
116126

117127
if compression == 'use_ext':
@@ -138,11 +148,15 @@ def open(self, name, mode='r', compression=None):
138148
self.fp = codecs.getreader('ascii')(self.fp_extra)
139149
else: # mode == 'w'
140150
self.fp = codecs.getwriter('ascii')(self.fp_extra)
141-
else: # self.ctype == 'lzma'
151+
elif self.ctype == 'lzma':
142152
# LZMA is available in Python 2 only if backports.lzma is installed
143153
# Python 3 supports it by default
144154
assert lzma_present, 'LZMA compression is unavailable.'
145155
self.fp = lzma.open(name, mode=mode + 't')
156+
else: # self.ctype == 'zstd'
157+
# Zstandard is available only in Python 3.14 and later
158+
assert zstd_present, 'Zstandard compression is unavailable.'
159+
self.fp = zstd.open(name, mode=mode + 't')
146160

147161
def close(self):
148162
"""
@@ -175,6 +189,8 @@ def get_compression_type(self, file_name):
175189
self.ctype = 'bzip2'
176190
elif ext in ('.xz', '.lzma'):
177191
self.ctype = 'lzma'
192+
elif ext == 'zst':
193+
self.ctype = 'zstd'
178194
else:
179195
self.ctype = None
180196

0 commit comments

Comments
 (0)