Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,51 @@ concurrency:
cancel-in-progress: true

jobs:
flake8:
name: flake8
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install flake8
- name: flake8
uses: liskin/gh-problem-matcher-wrap@e7b7beaaafa52524748b31a381160759d68d61fb
with:
linters: flake8
run: flake8

isort:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- run: python -m pip install "isort<6"
- name: isort
# Pinned to v3.0.0.
uses: liskin/gh-problem-matcher-wrap@e7b7beaaafa52524748b31a381160759d68d61fb
with:
linters: isort
run: isort --check --diff diskcollections tests
black:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: black
uses: psf/black@stable

tests:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-22.04
needs: ["flake8", "isort", "black"]
strategy:
matrix:
python-version:
Expand Down Expand Up @@ -50,7 +92,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: Install dependencies
run: python -m pip install --upgrade coverage[toml]
Expand Down
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Contribute

$ pyenv install 3.7 3.8 3.9 3.10 3.11 3.12 3.13


#. Check your code and tests with **tox**

.. code-block:: bash
Expand Down Expand Up @@ -234,6 +233,11 @@ Contribute
py313: OK (0.75=setup[0.01]+cmd[0.74] seconds)
evaluation failed :( (4.12 seconds)

#. Lint your code

.. code-block:: bash

$ tox -e lint

#. Send a pull request!

Expand Down
28 changes: 11 additions & 17 deletions diskcollections/iterables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
from functools import partial

from ..serializers import (
PickleZLibSerializer
)
from .clients import (
PersistentDirectoryClient,
TemporaryDirectoryClient
)
from .iterables import (
Deque,
List
)

from ..serializers import PickleZLibSerializer
from .clients import PersistentDirectoryClient, TemporaryDirectoryClient
from .iterables import Deque, List

FileList = partial(
List,
client_class=TemporaryDirectoryClient,
serializer_class=PickleZLibSerializer
serializer_class=PickleZLibSerializer,
)

FileDeque = partial(
Deque,
client_class=TemporaryDirectoryClient,
serializer_class=PickleZLibSerializer
serializer_class=PickleZLibSerializer,
)

__all__ = (
'List', 'Deque',
'FileDeque', 'FileList',
'PersistentDirectoryClient', 'TemporaryDirectoryClient',
"List",
"Deque",
"FileDeque",
"FileList",
"PersistentDirectoryClient",
"TemporaryDirectoryClient",
)
32 changes: 12 additions & 20 deletions diskcollections/iterables/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class TemporaryDirectoryClient(IClientSequence):
new content.
"""

def __init__(self, iterable=(), mode='w+b'):
def __init__(self, iterable=(), mode="w+b"):
super(TemporaryDirectoryClient, self).__init__()
self.__mode = mode
self.__files = []
self.__directory = TemporaryDirectory()
self.extend(iterable)

def __repr__(self):
return 'TemporaryDirectoryClient(%s)' % self.__str__()
return "TemporaryDirectoryClient(%s)" % self.__str__()

def __str__(self):
s = ', '.join(map(repr, self))
return '[%s]' % s
s = ", ".join(map(repr, self))
return "[%s]" % s

def __del__(self):
for f in self.__files:
Expand All @@ -41,10 +41,7 @@ def __getitem__(self, index):
if isinstance(index, slice):
indices = index.indices(len(self))
start, stop, step = indices
items = (
self[i]
for i in range(start, stop, step)
)
items = (self[i] for i in range(start, stop, step))
return self.__class__(iterable=items, mode=self.__mode)

file = self.__files[index]
Expand All @@ -53,8 +50,7 @@ def __getitem__(self, index):

def __setitem__(self, index, value):
file = tempfile.TemporaryFile(
mode=self.__mode,
dir=self.__directory.name
mode=self.__mode, dir=self.__directory.name
)
file.write(bytes(value))
self.__files[index] = file
Expand All @@ -64,8 +60,7 @@ def __len__(self):

def insert(self, index, value):
file = tempfile.TemporaryFile(
mode=self.__mode,
dir=self.__directory.name
mode=self.__mode, dir=self.__directory.name
)
file.write(value)
self.__files.insert(index, file)
Expand All @@ -83,7 +78,7 @@ class PersistentDirectoryClient(IClientSequence):

def __init__(self, directory, iterable=()):
super(PersistentDirectoryClient, self).__init__()
self.__mode = 'w+'
self.__mode = "w+"
self.__files = []

if not os.path.exists(directory):
Expand All @@ -93,11 +88,11 @@ def __init__(self, directory, iterable=()):
self.extend(iterable)

def __repr__(self):
return 'PersistentDirectoryClient(%s)' % self.__str__()
return "PersistentDirectoryClient(%s)" % self.__str__()

def __str__(self):
s = ', '.join(map(repr, self))
return '[%s]' % s
s = ", ".join(map(repr, self))
return "[%s]" % s

def __del__(self):
for f in self.__files:
Expand Down Expand Up @@ -137,10 +132,7 @@ def __getitem__(self, index):
if isinstance(index, slice):
indices = index.indices(len(self))
start, stop, step = indices
items = (
self[i]
for i in range(start, stop, step)
)
items = (self[i] for i in range(start, stop, step))
return self.__class__(
self.__directory,
iterable=items,
Expand Down
18 changes: 8 additions & 10 deletions diskcollections/iterables/iterables.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import collections

from diskcollections.py2to3 import izip


class List(collections.abc.MutableSequence):

def __init__(
self,
iterable=None,
client_class=None,
serializer_class=None
self, iterable=None, client_class=None, serializer_class=None
):
super(List, self).__init__()
self.__client = client_class()
Expand All @@ -18,11 +16,11 @@ def __init__(
self.extend(iterable)

def __repr__(self):
return '%s%s' % (self.__class__, self.__str__())
return "%s%s" % (self.__class__, self.__str__())

def __str__(self):
s = ', '.join(map(repr, self))
return '[%s]' % s
s = ", ".join(map(repr, self))
return "[%s]" % s

def __copy__(self):
return self.__class__(
Expand Down Expand Up @@ -96,11 +94,11 @@ def __len__(self):
return len(self.__client)

def __repr__(self):
return '%s(%s)' % (self.__class__, self.__str__())
return "%s(%s)" % (self.__class__, self.__str__())

def __str__(self):
s = ', '.join(map(repr, self))
return '[%s]' % s
s = ", ".join(map(repr, self))
return "[%s]" % s

def __copy__(self):
return self.__class__(
Expand Down
1 change: 1 addition & 0 deletions diskcollections/py2to3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
if sys.version_info >= (3, 4):
TemporaryDirectory = tempfile.TemporaryDirectory
else:

class TemporaryDirectory:
def __init__(self):
self._directory_path = tempfile.mkdtemp()
Expand Down
4 changes: 1 addition & 3 deletions diskcollections/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class PickleZLibSerializer(ISerializer):

@staticmethod
def dumps(
obj,
protocol=pickle.HIGHEST_PROTOCOL,
level=zlib.Z_DEFAULT_COMPRESSION
obj, protocol=pickle.HIGHEST_PROTOCOL, level=zlib.Z_DEFAULT_COMPRESSION
):
pickled = pickle.dumps(obj, protocol=protocol)
compressed = zlib.compress(pickled, level)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length = 79
58 changes: 32 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
import os
from setuptools import (
find_packages,
setup,
)

from setuptools import find_packages, setup


def url(*args):
return '/'.join(args)
return "/".join(args)


here = os.path.abspath(os.path.dirname(__file__))
with open('README.rst', 'r') as f:
with open("README.rst", "r") as f:
readme = f.read()

package_name = 'python-disk-collections'
url_profile = 'https://github.com/thegrymek'
version = '0.0.5'
package_name = "python-disk-collections"
url_profile = "https://github.com/thegrymek"
version = "0.0.5"
setup(
name=package_name,
version=version,
author='thegrymek',
author_email='andrzej.grymkowski@gmail.com',
description='Package provides classes: FileList, FileDeque that behaves '
'like bulltins but keeps items at disk.',
author="thegrymek",
author_email="andrzej.grymkowski@gmail.com",
description="Package provides classes: FileList, FileDeque that behaves "
"like bulltins but keeps items at disk.",
long_description=readme,
packages=find_packages(),
url=url(url_profile, package_name),
download_url=url(url_profile, package_name, 'archive/%s.tar.gz' % version),
license='MIT',
download_url=url(url_profile, package_name, "archive/%s.tar.gz" % version),
license="MIT",
zip_safe=False,
keywords=['pickle', 'cache', 'collections', 'list', 'deque', 'json',
'zlib', 'disk'],
keywords=[
"pickle",
"cache",
"collections",
"list",
"deque",
"json",
"zlib",
"disk",
],
classifiers=[
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Topic :: Software Development :: Libraries :: Python Modules',
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
Loading