Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize the packaging process with uv #21

Merged
merged 2 commits into from
Sep 12, 2024
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
78 changes: 21 additions & 57 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 @@ -72,44 +44,36 @@ jobs:
needs: [lint, build]
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.10"]
include:
- os: windows-latest
python-version: "3.8"
- os: macos-latest
python-version: "3.8"
- os: windows-latest
python-version: "3.12"
- os: macos-latest
python-version: "3.12"
runs-on: ${{ matrix.os }}

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.
10 changes: 7 additions & 3 deletions json_store/shelve2json.py → src/json_store/shelve2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import json_store


def convert(oldfile):
def convert(oldfile: str):
if not os.path.isfile(oldfile):
raise ValueError("No such file: {}".format(oldfile))

data = shelve.open(oldfile)
name = oldfile
# remove extensions that are implicitly added by the underlying DBM module
name = name.rsplit(".dat")[0] # Windows
name = name.rsplit(".db")[0] # macOS

newfile = oldfile.rsplit(".db")[0] + ".json"
data = shelve.open(name)
newfile = name + ".json"
store = json_store.open(newfile)
store.update(data)
store.sync()
Expand Down
22 changes: 17 additions & 5 deletions tests/test_shelve2json.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#!/bin/sh
#!/usr/bin/env bash
set -e -x

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

if [[ -s "$tmp".dat ]]; then
# Windows
shelve2json "$tmp".dat
elif [[ -s "$tmp".db ]]; then
# macOS
shelve2json "$tmp".db
else
# Linux
shelve2json "$tmp"
fi

rm -f "$tmp" "$tmp".{dat,db,json}
Loading