Skip to content

Commit

Permalink
Migrate to uv and modernize things
Browse files Browse the repository at this point in the history
  • Loading branch information
brainsik committed Sep 9, 2024
1 parent e4a8511 commit ecf9764
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 103 deletions.
67 changes: 11 additions & 56 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
name: json-store
on: [push, pull_request]

env:
pip-cache-key: 2023.02.03

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ github.job }}-${{ env.pip-cache-key }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install uv
uses: astral-sh/setup-uv@v2

- name: pre-commit cache
uses: actions/cache@v4
Expand All @@ -27,40 +19,20 @@ jobs:
restore-keys: |
${{ runner.os }}-pre-commit-
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install ${{ github.job }} dependencies
run: pip install --disable-pip-version-check pre-commit

- name: Run pre-commit tests
run: pre-commit run -a
run: uv tool run pre-commit run -a

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ github.job }}-${{ env.pip-cache-key }}
restore-keys: |
${{ runner.os }}-pip-
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Upgrade pip and setuptools
run: python -m pip install --upgrade pip setuptools

- name: Install ${{ github.job }} dependencies
run: pip --disable-pip-version-check install wheel build
- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Build package
run: python -m build
run: uv build

- name: Store build artifacts
uses: actions/upload-artifact@v4
Expand All @@ -79,37 +51,20 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ github.job }}-${{ env.pip-cache-key }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Install ${{ github.job }} dependencies
run: |
pip install --disable-pip-version-check pytest
- name: Install json-store package
shell: bash # so this works on both Linux and Windows
run: |
pip install --disable-pip-version-check dist/json_store-*.whl
uv sync --dev
- name: Test with pytest
run: pytest
run: uv run pytest

- name: Test shelve2json
if: ${{ matrix.os != 'windows-latest' }} # shelve.open has an internal traceback on Windows
run: sh tests/test_shelve2json.sh
run: uv run sh tests/test_shelve2json.sh
51 changes: 51 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[project]
dynamic = ["version"]
name = "json-store"
requires-python = ">=3.8"
dependencies = []

authors = [{name = "jeremy avnet", email = "[email protected]"}]
description = "A shelve-like store using JSON serialization."
readme = "README.md"
license = {file = "LICENSE.txt"}
keywords = ["json", "shelve"]

classifiers = [
"Development Status :: 5 - Production/Stable",

"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries",

"License :: OSI Approved :: MIT License",

"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

[project.urls]
Homepage = "https://github.com/brainsik/json-store"
Repository = "https://github.com/brainsik/json-store.git"
Issues = "https://github.com/brainsik/json-store/issues"
Changelog = "https://github.com/brainsik/json-store/releases"

[project.scripts]
shelve2json = "json_store.shelve2json:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "src/json_store/__init__.py"

[tool.uv]
dev-dependencies = [
"pytest >=8.3"
]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

40 changes: 0 additions & 40 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion json_store/__init__.py → src/json_store/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .json_store import JSONStore

__version__ = "4.0"
__version__ = "4.1"

open = JSONStore
File renamed without changes.
5 changes: 3 additions & 2 deletions json_store/shelve2json.py → src/json_store/shelve2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def convert(oldfile):
if not os.path.isfile(oldfile):
raise ValueError("No such file: {}".format(oldfile))

data = shelve.open(oldfile)
name = oldfile.rsplit(".db")[0]
data = shelve.open(name)

newfile = oldfile.rsplit(".db")[0] + ".json"
newfile = name + ".json"
store = json_store.open(newfile)
store.update(data)
store.sync()
Expand Down
10 changes: 8 additions & 2 deletions tests/test_shelve2json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ set -e -x

tmp=$(mktemp)
rm -f "$tmp"
python -c 'import shelve; db=shelve.open("'"$tmp"'", flag="n"); db["eggs"] = "eggs"; db.close()'
shelve2json "$tmp"
python3 -c 'import shelve; db=shelve.open("'"$tmp"'", flag="n"); db["eggs"] = "eggs"; db.sync(); db.close()'

if [ -s "$tmp".db ]; then
shelve2json "$tmp".db
else
shelve2json "$tmp"
fi

rm -f "$tmp" "$tmp.json"

0 comments on commit ecf9764

Please sign in to comment.