python-jsonstore 1.3.0__tar.gz → 1.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ pull_request:
9
+
10
+ jobs:
11
+ tests:
12
+ runs-on: ${{ matrix.os }}
13
+ env:
14
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os:
19
+ - ubuntu-latest
20
+ - windows-latest
21
+ python-version:
22
+ - "3.8"
23
+ - "3.9"
24
+ - "3.10"
25
+ - "3.11"
26
+ - "3.12"
27
+ - "3.13"
28
+ - "3.14"
29
+ - "pypy-3.9"
30
+ exclude:
31
+ - os: windows-latest
32
+ python-version: "pypy-3.9"
33
+ steps:
34
+ - name: Check out repository
35
+ uses: actions/checkout@v4
36
+
37
+ - name: Set up Python ${{ matrix.python-version }}
38
+ uses: actions/setup-python@v5
39
+ with:
40
+ python-version: ${{ matrix.python-version }}
41
+
42
+ - name: Install system dependencies
43
+ if: runner.os == 'Linux'
44
+ run: |
45
+ sudo apt-get update
46
+ sudo apt-get install -y zip p7zip-full
47
+
48
+ - name: Install Python dependencies
49
+ run: |
50
+ python -m pip install --upgrade pip
51
+ python -m pip install . pytest pytest-cov
52
+
53
+ - name: Run tests
54
+ run: pytest -vv --cov=jsonstore --cov-report=xml --junitxml=test-results.xml
55
+
56
+ - name: Upload coverage to Codecov
57
+ if: always() && env.CODECOV_TOKEN != ''
58
+ uses: codecov/codecov-action@v5
59
+ with:
60
+ token: ${{ env.CODECOV_TOKEN }}
61
+ files: ./coverage.xml
62
+ fail_ci_if_error: true
63
+
64
+ - name: Upload test results to Codecov
65
+ if: always() && env.CODECOV_TOKEN != ''
66
+ uses: codecov/codecov-action@v5
67
+ with:
68
+ token: ${{ env.CODECOV_TOKEN }}
69
+ files: ./test-results.xml
70
+ report_type: test_results
71
+ fail_ci_if_error: true
@@ -0,0 +1,27 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build-and-publish:
9
+ runs-on: ubuntu-latest
10
+ environment:
11
+ name: pypi
12
+ url: https://pypi.org/p/python-jsonstore
13
+ permissions:
14
+ id-token: write
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: '3.x'
21
+ - name: Build package
22
+ run: |
23
+ python -m pip install --upgrade pip build
24
+ python -m build
25
+ # the publishing uses PyPI's trusted publishing, so configured on pypi instead of using secrets
26
+ - name: Publish to PyPI
27
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-jsonstore
3
+ Version: 1.3.3
4
+ Summary: Map JSON files onto Python attributes for simple configuration storage
5
+ Author-email: Oliver Bristow <github+pypi@oliverbristow.co.uk>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Code0x58/python-jsonstore/
8
+ Keywords: json,key,value,store
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 2
14
+ Classifier: Programming Language :: Python :: 2.7
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.3
17
+ Classifier: Programming Language :: Python :: 3.4
18
+ Classifier: Programming Language :: Python :: 3.5
19
+ Classifier: Programming Language :: Python :: 3.6
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: 3.14
28
+ Classifier: Programming Language :: Python :: Implementation :: CPython
29
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
30
+ Classifier: Topic :: Database
31
+ Classifier: Topic :: Software Development
32
+ Requires-Python: >=2.7
33
+ Description-Content-Type: text/x-rst
34
+ License-File: LICENCE.md
35
+ Dynamic: license-file
36
+
37
+ |PyPI| |Build Status| |Coverage Report|
38
+
39
+ jsonstore
40
+ =========
41
+
42
+ This module provides a class that maps keys and values from a JSON file
43
+ onto its attributes.
44
+
45
+ The goal was to provide a convenient way of loading and saving
46
+ configuration in a familiar human readable format. This is a bit more
47
+ flexible than the
48
+ `configparser <https://docs.python.org/3/library/configparser.html>`__
49
+ module which is included with Python.
50
+
51
+ This works is tested and working on Python 2.7 and Python 3.6+. It will
52
+ not work on 2.6 or lower. The tests are also executed on PyPy.
53
+
54
+ Examples
55
+ --------
56
+
57
+ Basics
58
+ ~~~~~~
59
+
60
+ .. code:: python
61
+
62
+ # by default JsonStore commits on every change unless in a transaction
63
+ store = JsonStore('config.json')
64
+ store.a_string = "something"
65
+ store.a_list = [1, 2, 3]
66
+ store.a_dictionary = {
67
+ 'dict-list': [{}],
68
+ 'ln(2)': 0.69314718056,
69
+ 'for-you': u"💐",
70
+ }
71
+
72
+ # you can use […] to set/get/delete string keys
73
+ store['some_key'] = "a value"
74
+ # the key is split on '.'s and works on dictionaries
75
+ del store['a_dictionary.dict-list']
76
+ store['a_dictionary.new_value'] = "old value"
77
+ # you can also use the syntactic sugar for tuple keys (explicit lists work too)
78
+ assert store['a_dictionary', 'new_value'] == "old value"
79
+ # you can traverse lists too
80
+ assert store['a_list', -1] == 3
81
+ # you can use slices in lists
82
+ assert len(store['a_list', 1:]) == 2
83
+ del store['a_list', :2]
84
+ assert store.a_list == [3]
85
+
86
+ # deep copies are made when assigning values
87
+ my_list = ['fun']
88
+ store.a_list = my_list
89
+ assert store.a_list is not my_list
90
+ assert 'a_list' in store
91
+
92
+ # deep copies are also returned to avoid unsanitary changes being made
93
+ store.a_dictionary['new_value'] = "new value" # won't update the store!
94
+ assert store.a_dictionary['new_value'] == "old value"
95
+ assert store.a_dictionary is not store.a_dictionary
96
+
97
+ # Appending to, extending a list
98
+ >>> store.list = [1, 2, 3]
99
+
100
+ # Because of the fact that .append won't modify the list in the actual file,
101
+ # but only a copy...
102
+ >>> store.list.append(4)
103
+ >>> store.list
104
+ [1, 2, 3]
105
+
106
+ # ... we need to rather use the += operator to append to a list.
107
+ >>> store.list += [4]
108
+ >>> store.list
109
+ [1, 2, 3, 4]
110
+
111
+ # Similarly, we can extend the list
112
+ >>> store.list += [5, 6]
113
+ >>> store.list
114
+ [1, 2, 3, 4, 5, 6]
115
+
116
+ Transactions
117
+ ~~~~~~~~~~~~
118
+
119
+ ``JsonStore`` objects can be used as `context
120
+ managers <https://www.python.org/dev/peps/pep-0343/>`__ to provide
121
+ transactions which are rolled back in the event of an exception. The
122
+ transaction model is primitive; you can only nest transactions.
123
+
124
+ While a store is put into a transaction, it will not save changes to
125
+ file until all of the transactions have been closed.
126
+
127
+ .. code:: python
128
+
129
+ from jsonstore import JsonStore
130
+
131
+ # even with auto_commit=True, the file won't be saved until the last contexts has been closed
132
+ with JsonStore('config.json', indent=None, auto_commit=False) as store:
133
+ self.value = 1
134
+
135
+ # the context manager will roll back changes made if an exception is raised
136
+ store = JsonStore('config.json', indent=None)
137
+ try:
138
+ with store:
139
+ store.value = "new"
140
+ raise Exception
141
+ except Exception:
142
+ pass
143
+ # here we see the value that was saved previously
144
+ assert store.value == 1
145
+
146
+
147
+ .. |Build Status| image:: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml/badge.svg
148
+ :target: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml
149
+ .. |PyPI| image:: https://img.shields.io/pypi/v/python-jsonstore.svg
150
+ :target: https://pypi.org/project/python-jsonstore/
151
+ .. |Coverage Report| image:: https://codecov.io/gh/Code0x58/python-jsonstore/branch/master/graph/badge.svg
152
+ :target: https://codecov.io/gh/Code0x58/python-jsonstore
@@ -1,4 +1,4 @@
1
- |PyPi Package| |Build Status| |Codacy Rating| |Coverage Report|
1
+ |PyPI| |Build Status| |Coverage Report|
2
2
 
3
3
  jsonstore
4
4
  =========
@@ -12,11 +12,8 @@ flexible than the
12
12
  `configparser <https://docs.python.org/3/library/configparser.html>`__
13
13
  module which is included with Python.
14
14
 
15
- This works is tested and working on Python 2.7+ and Python 3.3+. It will
16
- not work on 2.6 or lower, but is expected to work on 3.0-3.2. The tests
17
- do not work in 3.2.6 due to
18
- `mistreating <https://travis-ci.org/Code0x58/python-jsonstore/jobs/198150401>`__
19
- the 💩 when parsing the test code. This is also tested on pypy and pypy3.
15
+ This works is tested and working on Python 2.7 and Python 3.6+. It will
16
+ not work on 2.6 or lower. The tests are also executed on PyPy.
20
17
 
21
18
  Examples
22
19
  --------
@@ -110,11 +107,10 @@ file until all of the transactions have been closed.
110
107
  # here we see the value that was saved previously
111
108
  assert store.value == 1
112
109
 
113
- .. |Build Status| image:: https://travis-ci.org/Code0x58/python-jsonstore.svg?branch=master
114
- :target: https://travis-ci.org/Code0x58/python-jsonstore
115
- .. |Codacy Rating| image:: https://api.codacy.com/project/badge/Grade/37ea488773444de59469a3775be83faf
116
- :target: https://www.codacy.com/app/evilumbrella-github/python-jsonstore?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Code0x58/python-jsonstore&amp;utm_campaign=Badge_Grade
117
- .. |PyPi Package| image:: https://badge.fury.io/py/python-jsonstore.svg
110
+
111
+ .. |Build Status| image:: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml/badge.svg
112
+ :target: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml
113
+ .. |PyPI| image:: https://img.shields.io/pypi/v/python-jsonstore.svg
118
114
  :target: https://pypi.org/project/python-jsonstore/
119
115
  .. |Coverage Report| image:: https://codecov.io/gh/Code0x58/python-jsonstore/branch/master/graph/badge.svg
120
- :target: https://codecov.io/gh/Code0x58/python-jsonstore
116
+ :target: https://codecov.io/gh/Code0x58/python-jsonstore
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=75", "setuptools_scm>=7", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "python-jsonstore"
7
+ description = "Map JSON files onto Python attributes for simple configuration storage"
8
+ readme = "README.rst"
9
+ requires-python = ">=2.7"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "Oliver Bristow", email = "github+pypi@oliverbristow.co.uk"},
13
+ ]
14
+ keywords = ["json", "key", "value", "store"]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 2",
21
+ "Programming Language :: Python :: 2.7",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.3",
24
+ "Programming Language :: Python :: 3.4",
25
+ "Programming Language :: Python :: 3.5",
26
+ "Programming Language :: Python :: 3.6",
27
+ "Programming Language :: Python :: 3.7",
28
+ "Programming Language :: Python :: 3.8",
29
+ "Programming Language :: Python :: 3.9",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Programming Language :: Python :: 3.14",
35
+ "Programming Language :: Python :: Implementation :: CPython",
36
+ "Programming Language :: Python :: Implementation :: PyPy",
37
+ "Topic :: Database",
38
+ "Topic :: Software Development",
39
+ ]
40
+ dependencies = []
41
+ dynamic = ["version"]
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/Code0x58/python-jsonstore/"
45
+
46
+ [tool.setuptools]
47
+ py-modules = ["jsonstore"]
48
+ license-files = ["LICENCE.md"]
49
+
50
+ [tool.setuptools_scm]
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-jsonstore
3
+ Version: 1.3.3
4
+ Summary: Map JSON files onto Python attributes for simple configuration storage
5
+ Author-email: Oliver Bristow <github+pypi@oliverbristow.co.uk>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Code0x58/python-jsonstore/
8
+ Keywords: json,key,value,store
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 2
14
+ Classifier: Programming Language :: Python :: 2.7
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.3
17
+ Classifier: Programming Language :: Python :: 3.4
18
+ Classifier: Programming Language :: Python :: 3.5
19
+ Classifier: Programming Language :: Python :: 3.6
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: 3.14
28
+ Classifier: Programming Language :: Python :: Implementation :: CPython
29
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
30
+ Classifier: Topic :: Database
31
+ Classifier: Topic :: Software Development
32
+ Requires-Python: >=2.7
33
+ Description-Content-Type: text/x-rst
34
+ License-File: LICENCE.md
35
+ Dynamic: license-file
36
+
37
+ |PyPI| |Build Status| |Coverage Report|
38
+
39
+ jsonstore
40
+ =========
41
+
42
+ This module provides a class that maps keys and values from a JSON file
43
+ onto its attributes.
44
+
45
+ The goal was to provide a convenient way of loading and saving
46
+ configuration in a familiar human readable format. This is a bit more
47
+ flexible than the
48
+ `configparser <https://docs.python.org/3/library/configparser.html>`__
49
+ module which is included with Python.
50
+
51
+ This works is tested and working on Python 2.7 and Python 3.6+. It will
52
+ not work on 2.6 or lower. The tests are also executed on PyPy.
53
+
54
+ Examples
55
+ --------
56
+
57
+ Basics
58
+ ~~~~~~
59
+
60
+ .. code:: python
61
+
62
+ # by default JsonStore commits on every change unless in a transaction
63
+ store = JsonStore('config.json')
64
+ store.a_string = "something"
65
+ store.a_list = [1, 2, 3]
66
+ store.a_dictionary = {
67
+ 'dict-list': [{}],
68
+ 'ln(2)': 0.69314718056,
69
+ 'for-you': u"💐",
70
+ }
71
+
72
+ # you can use […] to set/get/delete string keys
73
+ store['some_key'] = "a value"
74
+ # the key is split on '.'s and works on dictionaries
75
+ del store['a_dictionary.dict-list']
76
+ store['a_dictionary.new_value'] = "old value"
77
+ # you can also use the syntactic sugar for tuple keys (explicit lists work too)
78
+ assert store['a_dictionary', 'new_value'] == "old value"
79
+ # you can traverse lists too
80
+ assert store['a_list', -1] == 3
81
+ # you can use slices in lists
82
+ assert len(store['a_list', 1:]) == 2
83
+ del store['a_list', :2]
84
+ assert store.a_list == [3]
85
+
86
+ # deep copies are made when assigning values
87
+ my_list = ['fun']
88
+ store.a_list = my_list
89
+ assert store.a_list is not my_list
90
+ assert 'a_list' in store
91
+
92
+ # deep copies are also returned to avoid unsanitary changes being made
93
+ store.a_dictionary['new_value'] = "new value" # won't update the store!
94
+ assert store.a_dictionary['new_value'] == "old value"
95
+ assert store.a_dictionary is not store.a_dictionary
96
+
97
+ # Appending to, extending a list
98
+ >>> store.list = [1, 2, 3]
99
+
100
+ # Because of the fact that .append won't modify the list in the actual file,
101
+ # but only a copy...
102
+ >>> store.list.append(4)
103
+ >>> store.list
104
+ [1, 2, 3]
105
+
106
+ # ... we need to rather use the += operator to append to a list.
107
+ >>> store.list += [4]
108
+ >>> store.list
109
+ [1, 2, 3, 4]
110
+
111
+ # Similarly, we can extend the list
112
+ >>> store.list += [5, 6]
113
+ >>> store.list
114
+ [1, 2, 3, 4, 5, 6]
115
+
116
+ Transactions
117
+ ~~~~~~~~~~~~
118
+
119
+ ``JsonStore`` objects can be used as `context
120
+ managers <https://www.python.org/dev/peps/pep-0343/>`__ to provide
121
+ transactions which are rolled back in the event of an exception. The
122
+ transaction model is primitive; you can only nest transactions.
123
+
124
+ While a store is put into a transaction, it will not save changes to
125
+ file until all of the transactions have been closed.
126
+
127
+ .. code:: python
128
+
129
+ from jsonstore import JsonStore
130
+
131
+ # even with auto_commit=True, the file won't be saved until the last contexts has been closed
132
+ with JsonStore('config.json', indent=None, auto_commit=False) as store:
133
+ self.value = 1
134
+
135
+ # the context manager will roll back changes made if an exception is raised
136
+ store = JsonStore('config.json', indent=None)
137
+ try:
138
+ with store:
139
+ store.value = "new"
140
+ raise Exception
141
+ except Exception:
142
+ pass
143
+ # here we see the value that was saved previously
144
+ assert store.value == 1
145
+
146
+
147
+ .. |Build Status| image:: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml/badge.svg
148
+ :target: https://github.com/Code0x58/python-jsonstore/actions/workflows/ci.yml
149
+ .. |PyPI| image:: https://img.shields.io/pypi/v/python-jsonstore.svg
150
+ :target: https://pypi.org/project/python-jsonstore/
151
+ .. |Coverage Report| image:: https://codecov.io/gh/Code0x58/python-jsonstore/branch/master/graph/badge.svg
152
+ :target: https://codecov.io/gh/Code0x58/python-jsonstore
@@ -1,10 +1,10 @@
1
- .travis.yml
2
1
  LICENCE.md
3
2
  README.rst
4
3
  jsonstore.py
5
- setup.cfg
6
- setup.py
4
+ pyproject.toml
7
5
  test_jsonstore.py
6
+ .github/workflows/ci.yml
7
+ .github/workflows/publish.yml
8
8
  python_jsonstore.egg-info/PKG-INFO
9
9
  python_jsonstore.egg-info/SOURCES.txt
10
10
  python_jsonstore.egg-info/dependency_links.txt
@@ -1,6 +1,3 @@
1
- [bdist_wheel]
2
- universal = 1
3
-
4
1
  [egg_info]
5
2
  tag_build =
6
3
  tag_date = 0
@@ -216,7 +216,8 @@ class Tests(unittest.TestCase):
216
216
  del self.store["list", 1]
217
217
 
218
218
  self.store.dict = {}
219
- with self.assertRaises(TypeError):
219
+ # somewhere after python 3.9 this went from a TypeError to a KeyError
220
+ with self.assertRaises((TypeError, KeyError)):
220
221
  del self.store["dict", slice("a")]
221
222
 
222
223
  def test_context_and_deserialisation(self):
@@ -1,29 +0,0 @@
1
- language: python
2
-
3
- jobs:
4
- include:
5
- - python: 3.9
6
- - python: 3.8
7
- - python: 3.7
8
- - python: 3.6
9
- - python: 3.5
10
- - python: 3.4
11
- - python: 2.7
12
- - python: pypy3
13
- - python: pypy
14
- - name: "Python: 2.7"
15
- os: osx
16
- osx_image: xcode11.2 # Python 3.7.4 running on macOS 10.14.4
17
- language: shell # 'language: python' is an error on Travis CI macOS
18
- - name: "Python: 3.8"
19
- os: windows # Windows 10.0.17134 N/A Build 17134
20
- language: shell # 'language: python' is an error on Travis CI Windows
21
- before_install:
22
- - choco install python --version 3.8.2
23
- - python -m pip install --upgrade pip
24
- env: PATH=/c/Python38:/c/Python38/Scripts:$PATH
25
-
26
- install: python -m pip install --upgrade . pytest==4.6.1 pytest-cov==2.8.1 codecov==2.1.10
27
- script: python -m pytest -vv --cov=jsonstore --cov-append
28
- after_success:
29
- - codecov
@@ -1,148 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: python-jsonstore
3
- Version: 1.3.0
4
- Summary: UNKNOWN
5
- Home-page: https://github.com/Code0x58/python-jsonstore/
6
- Author: Oliver Bristow
7
- Author-email: github+pypi@oliverbristow.co.uk
8
- License: MIT
9
- Description: |PyPi Package| |Build Status| |Codacy Rating| |Coverage Report|
10
-
11
- jsonstore
12
- =========
13
-
14
- This module provides a class that maps keys and values from a JSON file
15
- onto its attributes.
16
-
17
- The goal was to provide a convenient way of loading and saving
18
- configuration in a familiar human readable format. This is a bit more
19
- flexible than the
20
- `configparser <https://docs.python.org/3/library/configparser.html>`__
21
- module which is included with Python.
22
-
23
- This works is tested and working on Python 2.7+ and Python 3.3+. It will
24
- not work on 2.6 or lower, but is expected to work on 3.0-3.2. The tests
25
- do not work in 3.2.6 due to
26
- `mistreating <https://travis-ci.org/Code0x58/python-jsonstore/jobs/198150401>`__
27
- the 💩 when parsing the test code. This is also tested on pypy and pypy3.
28
-
29
- Examples
30
- --------
31
-
32
- Basics
33
- ~~~~~~
34
-
35
- .. code:: python
36
-
37
- # by default JsonStore commits on every change unless in a transaction
38
- store = JsonStore('config.json')
39
- store.a_string = "something"
40
- store.a_list = [1, 2, 3]
41
- store.a_dictionary = {
42
- 'dict-list': [{}],
43
- 'ln(2)': 0.69314718056,
44
- 'for-you': u"💐",
45
- }
46
-
47
- # you can use […] to set/get/delete string keys
48
- store['some_key'] = "a value"
49
- # the key is split on '.'s and works on dictionaries
50
- del store['a_dictionary.dict-list']
51
- store['a_dictionary.new_value'] = "old value"
52
- # you can also use the syntactic sugar for tuple keys (explicit lists work too)
53
- assert store['a_dictionary', 'new_value'] == "old value"
54
- # you can traverse lists too
55
- assert store['a_list', -1] == 3
56
- # you can use slices in lists
57
- assert len(store['a_list', 1:]) == 2
58
- del store['a_list', :2]
59
- assert store.a_list == [3]
60
-
61
- # deep copies are made when assigning values
62
- my_list = ['fun']
63
- store.a_list = my_list
64
- assert store.a_list is not my_list
65
- assert 'a_list' in store
66
-
67
- # deep copies are also returned to avoid unsanitary changes being made
68
- store.a_dictionary['new_value'] = "new value" # won't update the store!
69
- assert store.a_dictionary['new_value'] == "old value"
70
- assert store.a_dictionary is not store.a_dictionary
71
-
72
- # Appending to, extending a list
73
- >>> store.list = [1, 2, 3]
74
-
75
- # Because of the fact that .append won't modify the list in the actual file,
76
- # but only a copy...
77
- >>> store.list.append(4)
78
- >>> store.list
79
- [1, 2, 3]
80
-
81
- # ... we need to rather use the += operator to append to a list.
82
- >>> store.list += [4]
83
- >>> store.list
84
- [1, 2, 3, 4]
85
-
86
- # Similarly, we can extend the list
87
- >>> store.list += [5, 6]
88
- >>> store.list
89
- [1, 2, 3, 4, 5, 6]
90
-
91
- Transactions
92
- ~~~~~~~~~~~~
93
-
94
- ``JsonStore`` objects can be used as `context
95
- managers <https://www.python.org/dev/peps/pep-0343/>`__ to provide
96
- transactions which are rolled back in the event of an exception. The
97
- transaction model is primitive; you can only nest transactions.
98
-
99
- While a store is put into a transaction, it will not save changes to
100
- file until all of the transactions have been closed.
101
-
102
- .. code:: python
103
-
104
- from jsonstore import JsonStore
105
-
106
- # even with auto_commit=True, the file won't be saved until the last contexts has been closed
107
- with JsonStore('config.json', indent=None, auto_commit=False) as store:
108
- self.value = 1
109
-
110
- # the context manager will roll back changes made if an exception is raised
111
- store = JsonStore('config.json', indent=None)
112
- try:
113
- with store:
114
- store.value = "new"
115
- raise Exception
116
- except Exception:
117
- pass
118
- # here we see the value that was saved previously
119
- assert store.value == 1
120
-
121
- .. |Build Status| image:: https://travis-ci.org/Code0x58/python-jsonstore.svg?branch=master
122
- :target: https://travis-ci.org/Code0x58/python-jsonstore
123
- .. |Codacy Rating| image:: https://api.codacy.com/project/badge/Grade/37ea488773444de59469a3775be83faf
124
- :target: https://www.codacy.com/app/evilumbrella-github/python-jsonstore?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Code0x58/python-jsonstore&amp;utm_campaign=Badge_Grade
125
- .. |PyPi Package| image:: https://badge.fury.io/py/python-jsonstore.svg
126
- :target: https://pypi.org/project/python-jsonstore/
127
- .. |Coverage Report| image:: https://codecov.io/gh/Code0x58/python-jsonstore/branch/master/graph/badge.svg
128
- :target: https://codecov.io/gh/Code0x58/python-jsonstore
129
- Keywords: json key value store
130
- Platform: UNKNOWN
131
- Classifier: Development Status :: 5 - Production/Stable
132
- Classifier: Intended Audience :: Developers
133
- Classifier: License :: OSI Approved :: MIT License
134
- Classifier: Operating System :: OS Independent
135
- Classifier: Programming Language :: Python :: 2
136
- Classifier: Programming Language :: Python :: 2.7
137
- Classifier: Programming Language :: Python :: 3
138
- Classifier: Programming Language :: Python :: 3.3
139
- Classifier: Programming Language :: Python :: 3.4
140
- Classifier: Programming Language :: Python :: 3.5
141
- Classifier: Programming Language :: Python :: 3.6
142
- Classifier: Programming Language :: Python :: 3.7
143
- Classifier: Programming Language :: Python :: 3.8
144
- Classifier: Programming Language :: Python :: Implementation :: CPython
145
- Classifier: Programming Language :: Python :: Implementation :: PyPy
146
- Classifier: Topic :: Database
147
- Classifier: Topic :: Software Development
148
- Description-Content-Type: text/x-rst
@@ -1,148 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: python-jsonstore
3
- Version: 1.3.0
4
- Summary: UNKNOWN
5
- Home-page: https://github.com/Code0x58/python-jsonstore/
6
- Author: Oliver Bristow
7
- Author-email: github+pypi@oliverbristow.co.uk
8
- License: MIT
9
- Description: |PyPi Package| |Build Status| |Codacy Rating| |Coverage Report|
10
-
11
- jsonstore
12
- =========
13
-
14
- This module provides a class that maps keys and values from a JSON file
15
- onto its attributes.
16
-
17
- The goal was to provide a convenient way of loading and saving
18
- configuration in a familiar human readable format. This is a bit more
19
- flexible than the
20
- `configparser <https://docs.python.org/3/library/configparser.html>`__
21
- module which is included with Python.
22
-
23
- This works is tested and working on Python 2.7+ and Python 3.3+. It will
24
- not work on 2.6 or lower, but is expected to work on 3.0-3.2. The tests
25
- do not work in 3.2.6 due to
26
- `mistreating <https://travis-ci.org/Code0x58/python-jsonstore/jobs/198150401>`__
27
- the 💩 when parsing the test code. This is also tested on pypy and pypy3.
28
-
29
- Examples
30
- --------
31
-
32
- Basics
33
- ~~~~~~
34
-
35
- .. code:: python
36
-
37
- # by default JsonStore commits on every change unless in a transaction
38
- store = JsonStore('config.json')
39
- store.a_string = "something"
40
- store.a_list = [1, 2, 3]
41
- store.a_dictionary = {
42
- 'dict-list': [{}],
43
- 'ln(2)': 0.69314718056,
44
- 'for-you': u"💐",
45
- }
46
-
47
- # you can use […] to set/get/delete string keys
48
- store['some_key'] = "a value"
49
- # the key is split on '.'s and works on dictionaries
50
- del store['a_dictionary.dict-list']
51
- store['a_dictionary.new_value'] = "old value"
52
- # you can also use the syntactic sugar for tuple keys (explicit lists work too)
53
- assert store['a_dictionary', 'new_value'] == "old value"
54
- # you can traverse lists too
55
- assert store['a_list', -1] == 3
56
- # you can use slices in lists
57
- assert len(store['a_list', 1:]) == 2
58
- del store['a_list', :2]
59
- assert store.a_list == [3]
60
-
61
- # deep copies are made when assigning values
62
- my_list = ['fun']
63
- store.a_list = my_list
64
- assert store.a_list is not my_list
65
- assert 'a_list' in store
66
-
67
- # deep copies are also returned to avoid unsanitary changes being made
68
- store.a_dictionary['new_value'] = "new value" # won't update the store!
69
- assert store.a_dictionary['new_value'] == "old value"
70
- assert store.a_dictionary is not store.a_dictionary
71
-
72
- # Appending to, extending a list
73
- >>> store.list = [1, 2, 3]
74
-
75
- # Because of the fact that .append won't modify the list in the actual file,
76
- # but only a copy...
77
- >>> store.list.append(4)
78
- >>> store.list
79
- [1, 2, 3]
80
-
81
- # ... we need to rather use the += operator to append to a list.
82
- >>> store.list += [4]
83
- >>> store.list
84
- [1, 2, 3, 4]
85
-
86
- # Similarly, we can extend the list
87
- >>> store.list += [5, 6]
88
- >>> store.list
89
- [1, 2, 3, 4, 5, 6]
90
-
91
- Transactions
92
- ~~~~~~~~~~~~
93
-
94
- ``JsonStore`` objects can be used as `context
95
- managers <https://www.python.org/dev/peps/pep-0343/>`__ to provide
96
- transactions which are rolled back in the event of an exception. The
97
- transaction model is primitive; you can only nest transactions.
98
-
99
- While a store is put into a transaction, it will not save changes to
100
- file until all of the transactions have been closed.
101
-
102
- .. code:: python
103
-
104
- from jsonstore import JsonStore
105
-
106
- # even with auto_commit=True, the file won't be saved until the last contexts has been closed
107
- with JsonStore('config.json', indent=None, auto_commit=False) as store:
108
- self.value = 1
109
-
110
- # the context manager will roll back changes made if an exception is raised
111
- store = JsonStore('config.json', indent=None)
112
- try:
113
- with store:
114
- store.value = "new"
115
- raise Exception
116
- except Exception:
117
- pass
118
- # here we see the value that was saved previously
119
- assert store.value == 1
120
-
121
- .. |Build Status| image:: https://travis-ci.org/Code0x58/python-jsonstore.svg?branch=master
122
- :target: https://travis-ci.org/Code0x58/python-jsonstore
123
- .. |Codacy Rating| image:: https://api.codacy.com/project/badge/Grade/37ea488773444de59469a3775be83faf
124
- :target: https://www.codacy.com/app/evilumbrella-github/python-jsonstore?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Code0x58/python-jsonstore&amp;utm_campaign=Badge_Grade
125
- .. |PyPi Package| image:: https://badge.fury.io/py/python-jsonstore.svg
126
- :target: https://pypi.org/project/python-jsonstore/
127
- .. |Coverage Report| image:: https://codecov.io/gh/Code0x58/python-jsonstore/branch/master/graph/badge.svg
128
- :target: https://codecov.io/gh/Code0x58/python-jsonstore
129
- Keywords: json key value store
130
- Platform: UNKNOWN
131
- Classifier: Development Status :: 5 - Production/Stable
132
- Classifier: Intended Audience :: Developers
133
- Classifier: License :: OSI Approved :: MIT License
134
- Classifier: Operating System :: OS Independent
135
- Classifier: Programming Language :: Python :: 2
136
- Classifier: Programming Language :: Python :: 2.7
137
- Classifier: Programming Language :: Python :: 3
138
- Classifier: Programming Language :: Python :: 3.3
139
- Classifier: Programming Language :: Python :: 3.4
140
- Classifier: Programming Language :: Python :: 3.5
141
- Classifier: Programming Language :: Python :: 3.6
142
- Classifier: Programming Language :: Python :: 3.7
143
- Classifier: Programming Language :: Python :: 3.8
144
- Classifier: Programming Language :: Python :: Implementation :: CPython
145
- Classifier: Programming Language :: Python :: Implementation :: PyPy
146
- Classifier: Topic :: Database
147
- Classifier: Topic :: Software Development
148
- Description-Content-Type: text/x-rst
@@ -1,46 +0,0 @@
1
- import codecs
2
- from os import path
3
- from textwrap import dedent
4
-
5
- from setuptools import setup
6
-
7
- here = path.abspath(path.dirname(__file__))
8
-
9
- with codecs.open(path.join(here, "README.rst"), encoding='utf-8') as f:
10
- long_description = f.read()
11
-
12
- setup(
13
- name='python-jsonstore',
14
- use_scm_version=True,
15
- description="",
16
- long_description=long_description,
17
- long_description_content_type='text/x-rst',
18
- author="Oliver Bristow",
19
- author_email='github+pypi@oliverbristow.co.uk',
20
- license='MIT',
21
- classifiers=dedent("""
22
- Development Status :: 5 - Production/Stable
23
- Intended Audience :: Developers
24
- License :: OSI Approved :: MIT License
25
- Operating System :: OS Independent
26
- Programming Language :: Python :: 2
27
- Programming Language :: Python :: 2.7
28
- Programming Language :: Python :: 3
29
- Programming Language :: Python :: 3.3
30
- Programming Language :: Python :: 3.4
31
- Programming Language :: Python :: 3.5
32
- Programming Language :: Python :: 3.6
33
- Programming Language :: Python :: 3.7
34
- Programming Language :: Python :: 3.8
35
- Programming Language :: Python :: Implementation :: CPython
36
- Programming Language :: Python :: Implementation :: PyPy
37
- Topic :: Database
38
- Topic :: Software Development
39
- """).strip().split('\n'),
40
- keywords='json key value store',
41
- url='https://github.com/Code0x58/python-jsonstore/',
42
- py_modules=dedent("""
43
- jsonstore
44
- """).strip().split('\n'),
45
- setup_requires=["setuptools_scm", "wheel"],
46
- )