Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 984310d

Browse files
committed
Initial commit
0 parents  commit 984310d

28 files changed

+1264
-0
lines changed

.ci/aptPackagesToInstall.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python3-ujson
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/KOLANICH/transformerz.py.git

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
indent_size = 4
7+
insert_final_newline = true
8+
end_of_line = lf
9+
10+
[*.{yml,yaml}]
11+
indent_style = space
12+
indent_size = 2

.github/.templateMarker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KOLANICH/python_project_boilerplate.py

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
allow:
8+
- dependency-type: "all"

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: typical python workflow
13+
uses: KOLANICH-GHActions/typical-python-workflow@master
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__
2+
*.py[co]
3+
/*.egg-info
4+
*.srctrlbm
5+
*.srctrldb
6+
build
7+
dist
8+
.eggs
9+
monkeytype.sqlite3
10+
/tests/testSavedDataRootDir
11+
/.ipynb_checkpoints

.gitlab-ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#image: pypy:latest
2+
image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest
3+
4+
variables:
5+
DOCKER_DRIVER: overlay2
6+
SAST_ANALYZER_IMAGE_TAG: latest
7+
SAST_DISABLE_DIND: "true"
8+
SAST_CONFIDENCE_LEVEL: 5
9+
CODECLIMATE_VERSION: latest
10+
11+
include:
12+
- template: SAST.gitlab-ci.yml
13+
- template: Code-Quality.gitlab-ci.yml
14+
- template: License-Management.gitlab-ci.yml
15+
16+
build:
17+
tags:
18+
- shared
19+
- linux
20+
stage: build
21+
variables:
22+
GIT_DEPTH: "1"
23+
PYTHONUSERBASE: ${CI_PROJECT_DIR}/python_user_packages
24+
25+
before_script:
26+
- export PATH="$PATH:$PYTHONUSERBASE/bin" # don't move into `variables`
27+
- apt-get update
28+
- apt-get -y install python3-lz4 python3-msgpack python3-brotli python3-cbor python3-ujson
29+
- pip3 install --upgrade https://gitlab.com/KOLANICH/py-lmdb/-/jobs/artifacts/gitlab/raw/wheels/lmdb-0.CI_cpython_latest-py3-none-any.whl?job=build
30+
- python3 ./fix_python_modules_paths.py
31+
- mkdir -p ./tests/databasesFiles
32+
- mount -t ramfs ramfs ./tests/databasesFiles
33+
34+
script:
35+
- python3 setup.py bdist_wheel
36+
- mv ./dist/*.whl ./dist/Cache-0.CI-py3-none-any.whl
37+
- pip3 install --upgrade -e ./[msgpack,lz4,brotli,zopflipy,cbor,zstd,lmdb]
38+
- coverage run --source=Cache -m pytest --junitxml=./rspec.xml ./tests/test.py
39+
- coverage report -m
40+
- coverage xml
41+
42+
coverage: /^TOTAL(?:\s+\d+){4}\s+(\d+%).+/
43+
44+
cache:
45+
paths:
46+
- $PYTHONUSERBASE
47+
48+
artifacts:
49+
paths:
50+
- dist
51+
reports:
52+
junit: ./rspec.xml
53+
cobertura: ./coverage.xml

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
os:
2+
- linux
3+
- osx
4+
dist: trusty
5+
language: python
6+
python:
7+
- 3.4
8+
- 3.5
9+
- 3.6
10+
- 3.7
11+
- nightly
12+
- pypy3
13+
- pypy3-nightly
14+
before_install:
15+
- pip3 install --upgrade setuptools setuptools_scm coveralls
16+
install:
17+
- python setup.py install
18+
script:
19+
- coverage run --source=Cache python tests/test.py test
20+
after_success:
21+
- coveralls

Code_Of_Conduct.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No codes of conduct!

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include UNLICENSE
2+
include *.md
3+
include tests
4+
include .editorconfig

ReadMe.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
urm.py [![Unlicensed work](https://raw.githubusercontent.com/unlicense/unlicense.org/master/static/favicon.png)](https://unlicense.org/)
2+
======
3+
~~[wheel (GitLab)](https://gitlab.com/KOLANICH/urm.py/-/jobs/artifacts/master/raw/dist/urm-0.CI-py3-none-any.whl?job=build)~~
4+
~~[wheel (GHA via `nightly.link`)](https://nightly.link/KOLANICH-libs/urm.py/workflows/CI/master/urm-0.CI-py3-none-any.whl)~~
5+
~~![GitLab Build Status](https://gitlab.com/KOLANICH/urm.py/badges/master/pipeline.svg)~~
6+
~~![GitLab Coverage](https://gitlab.com/KOLANICH/urm.py/badges/master/coverage.svg)~~
7+
~~[![GitHub Actions](https://github.com/KOLANICH-libs/urm.py/workflows/CI/badge.svg)](https://github.com/KOLANICH-libs/urm.py/actions/)~~
8+
[![Libraries.io Status](https://img.shields.io/librariesio/github/KOLANICH-libs/urm.py.svg)](https://libraries.io/github/KOLANICH-libs/urm.py)
9+
[![Code style: antiflash](https://img.shields.io/badge/code%20style-antiflash-FFF.svg)](https://codeberg.org/KOLANICH-tools/antiflash.py)
10+
11+
Unrelational mapper.
12+
13+
Sometimes you need to store some data somewhen and lazily retrieve as class fields and we don't want to write lot of boilerplate code and maintain this piece of shit. Object-relational mappers solve this problem by mapping classes to database tables, objects - to rows, object hierarchy to public and foreign keys.
14+
15+
But sometimes we don't need to store the data in relational databases. We need to store data in entities like files, archives, remote servers using REST/GraphQL API, etc. So we generalize a bit.
16+
17+
This stuff utilizes my other library `transformerz` of composable 2-way transformations.
18+
19+
Tutorial
20+
--------
21+
22+
It is [strongly](/issue/1) recommended to read the tutorial before using the lib. [`tutorial.ipynb`](./tutorial.ipynb)[![NBViewer](https://nbviewer.org/static/ico/ipynb_icon_16x16.png)](https://nbviewer.org/urls/codeberg.org/KOLANICH-libs/urm.py/blob/master/tutorial.ipynb)
23+
24+
TL;DR. Data model
25+
-----------------
26+
27+
We tie stored entities not to objects, but properties in classes. Entities are stored in underlying key-value storage.
28+
29+
* When we first time access a property in the class, it is loaded into a cache and then returned.
30+
* subsequent accesses return the stuff from the cache.
31+
* we can `save` the stuff from the cache to the storage explicitly.
32+
* to create a storage from scratch, we put the data into a cache and then `save` it.
33+
34+
Then we heavily abstrage the stuff.
35+
36+
A `key` is a `tuple` of strings and numbers. It is an unique identifier of a piece of data. It is decoupled from the actual storage implementation. We address data by keys.
37+
38+
To define the way we are going to store data we need to answer to the following "orthogonal" questions:
39+
40+
* WHERE are we going to store it? `Saver` object is an answer. `Mapper.saver` answers the question.
41+
* WHAT is the mapping between our internal `key`s and `key`s in the storage of this piece of data? A `key` is an answer. `Mapper.key` answers this question.
42+
43+
For cold storage we need to answer an additional question:
44+
45+
* HOW are we going to serialize the data? `transformerz.Transformer` object is an answer. `ColdMapper.serializer` answers this question.
46+
47+
So `Mapper` object answers the questions related to storage of values.
48+
49+
To create a bidirectional mapping between class properties, we need to answer the following questions:
50+
51+
* What pattern of access to the data should be optimized for? `FieldStrategy` subclasses are the answers.
52+
* `ColdStrategy` optimizes for frequent rather cheap accesses to volatile data.
53+
* Requires to know how we STORE the data. `ColdMapper` object is an answer. `FieldStrategy.cold` answers this question.
54+
* `CachedStrategy` optimizes for frequent rather expensive accesses to not very volatile data.
55+
* *Additionally* requires to know how we CACHE the data? `HotMapper` object is an answer. `FieldStrategy.hot` answers this question.
56+
* How do we create our internal `key`s? `Field` subclasses contain the answers.

UNLICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org/>

pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "urm"
7+
description = "Unrelational mapper. Saves and loads data not only from key-value storages."
8+
readme = "ReadMe.md"
9+
authors = [{name = "KOLANICH"}]
10+
license = {text = "Unlicense"}
11+
classifiers = [
12+
"Development Status :: 4 - Beta",
13+
"Environment :: Other Environment",
14+
"Intended Audience :: Developers",
15+
"License :: Public Domain",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3 :: Only",
20+
"Topic :: Software Development :: Libraries :: Python Modules",
21+
]
22+
keywords = ["urm"]
23+
urls = {Homepage = "https://codeberg.org/KOLANICH-libs/urm.py"}
24+
requires-python = ">=3.4"
25+
dependencies = [
26+
"transformerz", # @ git+https://codeberg.org/KOLANICH-libs/transformerz.py.git
27+
]
28+
dynamic = ["version"]
29+
30+
[tool.setuptools]
31+
packages = ["urm"]
32+
zip-safe = true
33+
include-package-data = false
34+
35+
[tool.setuptools_scm]

0 commit comments

Comments
 (0)