Skip to content

Commit

Permalink
Merge pull request #16 from heikomuller/dev-0.1.5
Browse files Browse the repository at this point in the history
Dev 0.1.5
  • Loading branch information
heikomuller authored Nov 6, 2020
2 parents 4df4b00 + 86bbeae commit 1f3ffbc
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 41 deletions.
8 changes: 0 additions & 8 deletions .coveragerc

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@
### 0.1.4 - 2020-10-07

* Add index position information to column class (\#11)


### 0.1.5 - 2020-11-06

* Add __getitem__ and get() method to `SnapshotListing`
41 changes: 41 additions & 0 deletions histore/archive/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ def __init__(self, snapshots: Optional[List[Snapshot]] = None):
raise ValueError(msg.format(prev.valid_time, s.valid_time))
prev = s

def __getitem__(self, version: int) -> Snapshot:
"""Get the snapshot for a given version number. Raises a KeyError if
no snapshot with the given version exists.
Parameters
----------
version: int
Unique version identifier for the returned snapshot.
Returns
-------
histore.archive.snapshot.Snapshot
Raises
------
KeyError
"""
return self.get(version)

def __iter__(self):
"""Make the snapshot list iterable.
Expand Down Expand Up @@ -201,6 +220,28 @@ def at_time(self, ts: datetime) -> Snapshot:
# The last snapshot was valid at or before the given timestamp.
return s1

def get(self, version: int) -> Snapshot:
"""Get the snapshot for a given version number. Raises a KeyError if
no snapshot with the given version exists.
Parameters
----------
version: int
Unique version identifier for the returned snapshot.
Returns
-------
histore.archive.snapshot.Snapshot
Raises
------
KeyError
"""
for s in self.snapshots:
if s.version == version:
return s
raise KeyError('unknown snapshot {}'.format(version))

def has_version(self, version: int) -> bool:
"""Check if the given version identifier references an existing
snapshot in the listing.
Expand Down
2 changes: 1 addition & 1 deletion histore/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# file LICENSE for full license details.

"""Code version information for histore."""
__version__ = '0.1.4'
__version__ = '0.1.5'
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

7 changes: 7 additions & 0 deletions tests/archive/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def test_snapshot_listing():
s2 = Snapshot(version=1, valid_time=util.to_datetime('2020-05-02'))
s3 = Snapshot(version=2, valid_time=util.to_datetime('2020-05-03'))
listing = SnapshotListing(snapshots=[s1, s2, s3])
# Get snapshots by identifier.
for version in range(2):
assert listing[version].version == version
assert listing.get(version).version == version
# Error when accessing snapshot with unknown identifier.
with pytest.raises(KeyError):
listing[4]
versions = list()
for s in listing:
versions.append(s.version)
Expand Down
30 changes: 0 additions & 30 deletions tox.ini

This file was deleted.

0 comments on commit 1f3ffbc

Please sign in to comment.