Skip to content

Commit dda0fea

Browse files
committed
first commit
0 parents  commit dda0fea

File tree

14 files changed

+572
-0
lines changed

14 files changed

+572
-0
lines changed

.bumpversion.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[bumpversion]
2+
current_version = 1.0.0
3+
4+
[bumpversion:file:setup.py]
5+
6+
[bumpversion:file:pyconfig/__init__.py]
7+

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
*.egg-info
2+
.*.swp
3+
.*.swo
4+
*.pyc
5+
.DS_Store
6+
dist
7+
.tox
8+
.coverage
9+
htmlcov
10+
six-*.egg/
11+
*.orig
12+
.idea/
13+
*.iml
14+
*.log
15+
16+
bak
17+
output
18+
output_*
19+
research
20+
venv
21+
venv3
22+
cache
23+
.cache
24+
vendor
25+
xvendor
26+
node_modules
27+
28+
report.xml
29+
pylint-report.html
30+
pytest-report.html
31+
set_w
32+
snafu.py
33+
set_infra
34+
35+
36+
*.py[cod]
37+
38+
# C extensions
39+
*.so
40+
41+
# Packages
42+
*.egg
43+
*.egg-info
44+
dist
45+
build
46+
eggs
47+
parts
48+
bin
49+
var
50+
sdist
51+
develop-eggs
52+
.installed.cfg
53+
lib
54+
lib64
55+
56+
# Installer logs
57+
pip-log.txt
58+
59+
# Unit test / coverage reports
60+
.coverage
61+
.tox
62+
nosetests.xml
63+
64+
# Translations
65+
*.mo
66+
67+
# Mr Developer
68+
.mr.developer.cfg
69+
.project
70+
.pydevproject
71+
.pypirc

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2018 Oyetoke Toby and contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include LICENSE README.md

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
#SPHINXPROJ =
8+
SOURCEDIR = docs
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# ConfigStore
2+
3+
A Python module for handling config files. It helps handles persist config files and also giving the ability to set, get, update and delete config settings
4+
5+
> Easily load and persist config without having to think about where and how
6+
7+
It's built base on nodejs [configstore](https://github.com/yeoman/configstore)
8+
9+
Config is stored in a JSON file located in `$XDG_CONFIG_HOME` or `~/.localconfig`.<br>
10+
Example: `~/.localconfig/configstore/name.json`
11+
12+
## Installation
13+
14+
```bash
15+
pip install pyconfig
16+
```
17+
18+
## Usage
19+
20+
```python
21+
from pyconfig import ConfigStore
22+
23+
// create a Configstore instance with a unique name e.g. gnit
24+
// Package name and optionally some default values
25+
conf = ConfigStore("Gnit", {"foo": 'bar'});
26+
27+
print(conf.get('foo'));
28+
//>>> 'bar'
29+
30+
conf.set('awesome', True);
31+
print(conf.get('awesome'));
32+
//>>> True
33+
34+
// Use dot-notation to set nested properties
35+
conf.set('bar.baz', True);
36+
print(conf.get('bar'));
37+
//>>> {"baz": True}
38+
39+
conf.delete('awesome');
40+
print(conf.get('awesome'));
41+
//>>>
42+
```
43+
44+
45+
## API
46+
47+
### Configstore(packageName, [defaults], [options])
48+
49+
Returns a new instance.
50+
51+
#### packageName
52+
53+
Type: `string`
54+
55+
Name of your package.
56+
57+
#### defaults
58+
59+
Type: `Object`
60+
61+
Default config.
62+
63+
#### options
64+
65+
##### globalConfigPath
66+
67+
Type: `bool`<br>
68+
Default: `False`
69+
70+
Store the config at `$CONFIG/package-name/config.json` instead of the default `$CONFIG/configstore/package-name.json`. This is not recommended as you might end up conflicting with other tools, rendering the "without having to think" idea moot.
71+
72+
### Features
73+
74+
You can use dot-notation to set, get, update and delete nested dict properties
75+
76+
### .set(key, value)
77+
78+
Set an item.
79+
80+
### .set(object)
81+
82+
Set multiple items at once.
83+
84+
### .get(key)
85+
86+
Get an item.
87+
88+
### .has(key)
89+
90+
Check if an item exists.
91+
92+
### .delete(key)
93+
94+
Delete an item.
95+
96+
### .clear()
97+
98+
Delete all items.
99+
100+
### .all
101+
102+
Get all the config as an object or replace the current config with an object:
103+
104+
```python
105+
conf.all({
106+
hello: 'world'
107+
})
108+
```
109+
110+
### .size
111+
112+
Get the item count.
113+
114+
### .path
115+
116+
Get the path to the config file. Can be used to show the user where the config file is located or even better open it for them.
117+
118+
119+
## License
120+
Copyright - 2018
121+
Oyetoke Toby <twitter:@OyetokeT>
122+
MIT LICENSE

docs/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# ConfigStore
2+
3+
A Python module for handling config files. It helps handles persist config files and also giving the ability to set, get, update and delete config settings
4+
5+
> Easily load and persist config without having to think about where and how
6+
7+
It's built base on nodejs [configstore](https://github.com/yeoman/configstore)
8+
9+
Config is stored in a JSON file located in `$XDG_CONFIG_HOME` or `~/.localconfig`.<br>
10+
Example: `~/.localconfig/configstore/name.json`
11+
12+
## Installation
13+
14+
```bash
15+
pip install pyconfig
16+
```
17+
18+
## Usage
19+
20+
```python
21+
from pyconfig import ConfigStore
22+
23+
// create a Configstore instance with a unique name e.g. gnit
24+
// Package name and optionally some default values
25+
conf = ConfigStore("Gnit", {"foo": 'bar'});
26+
27+
print(conf.get('foo'));
28+
//>>> 'bar'
29+
30+
conf.set('awesome', True);
31+
print(conf.get('awesome'));
32+
//>>> True
33+
34+
// Use dot-notation to set nested properties
35+
conf.set('bar.baz', True);
36+
print(conf.get('bar'));
37+
//>>> {"baz": True}
38+
39+
conf.delete('awesome');
40+
print(conf.get('awesome'));
41+
//>>>
42+
```
43+
44+
45+
## API
46+
47+
### Configstore(packageName, [defaults], [options])
48+
49+
Returns a new instance.
50+
51+
#### packageName
52+
53+
Type: `string`
54+
55+
Name of your package.
56+
57+
#### defaults
58+
59+
Type: `Object`
60+
61+
Default config.
62+
63+
#### options
64+
65+
##### globalConfigPath
66+
67+
Type: `bool`<br>
68+
Default: `False`
69+
70+
Store the config at `$CONFIG/package-name/config.json` instead of the default `$CONFIG/configstore/package-name.json`. This is not recommended as you might end up conflicting with other tools, rendering the "without having to think" idea moot.
71+
72+
### Features
73+
74+
You can use dot-notation to set, get, update and delete nested dict properties
75+
76+
### .set(key, value)
77+
78+
Set an item.
79+
80+
### .set(object)
81+
82+
Set multiple items at once.
83+
84+
### .get(key)
85+
86+
Get an item.
87+
88+
### .has(key)
89+
90+
Check if an item exists.
91+
92+
### .delete(key)
93+
94+
Delete an item.
95+
96+
### .clear()
97+
98+
Delete all items.
99+
100+
### .all
101+
102+
Get all the config as an object or replace the current config with an object:
103+
104+
```python
105+
conf.all({
106+
hello: 'world'
107+
})
108+
```
109+
110+
### .size
111+
112+
Get the item count.
113+
114+
### .path
115+
116+
Get the path to the config file. Can be used to show the user where the config file is located or even better open it for them.
117+
118+
119+
## License
120+
Copyright - 2018
121+
Oyetoke Toby <twitter:@OyetokeT>
122+
MIT LICENSE

example.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pyconfig import ConfigStore
2+
3+
conf = ConfigStore("vestub", {"url":"http://vestub.com"}, True)
4+
print(conf.get("url"))
5+
conf.set("Title", "Social Media for Idea Owners and Investors")
6+
conf.set("Tags", "Tech, Investors, Social Media")
7+
conf.set("Tags.Topic", "Python")
8+
conf.set({"Subject.Topic":"English"})
9+
print(conf.all())
10+
print(conf.path)
11+
12+
conf.delete("url")
13+
print(conf.all())

0 commit comments

Comments
 (0)