Skip to content

Commit d582b39

Browse files
Add support for Windows, Python 3 and PyPi deployment
1 parent 816609e commit d582b39

40 files changed

+855
-487
lines changed

.editorconfig

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# Python
12+
[*.py]
13+
indent_style = space
14+
indent_size = 4
15+
max_line_length = 88
16+
17+
# YAML
18+
[*.yaml]
19+
indent_style = space
20+
indent_size = 2
21+
22+
# JSON
23+
[*.json]
24+
indent_style = space
25+
indent_size = 4

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist

.github/workflows/cd.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CD
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
name: Deploy
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: "3.x"
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install setuptools wheel twine
21+
- name: Publish on PyPI
22+
env:
23+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
24+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
25+
run: |
26+
python setup.py sdist bdist_wheel
27+
twine upload --verbose dist/*

.github/workflows/ci.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [3.7, 3.8, 3.9]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install requirements
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install --editable ".[ci]"
26+
# - name: Lint with flake8
27+
# run: |
28+
# flake8 . --count --show-source --statistics
29+
- name: Test with pytest
30+
run: |
31+
pytest --cov=gitmodel
32+
- name: Document with sphinx
33+
run: |
34+
sphinx-build ./docs/source ./docs/build
35+
- name: Upload report on CodeCov
36+
run: |
37+
bash <(curl -s https://codecov.io/bash)

.gitignore

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/build/
73+
docs/source/generated
74+
75+
# PyBuilder
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
.python-version
87+
88+
# pipenv
89+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
91+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
92+
# install all needed dependencies.
93+
#Pipfile.lock
94+
95+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
96+
__pypackages__/
97+
98+
# Celery stuff
99+
celerybeat-schedule
100+
celerybeat.pid
101+
102+
# SageMath parsed files
103+
*.sage.py
104+
105+
# Environments
106+
.env
107+
.venv
108+
env/
109+
venv/
110+
ENV/
111+
env.bak/
112+
venv.bak/
113+
114+
# Spyder project settings
115+
.spyderproject
116+
.spyproject
117+
118+
# Rope project settings
119+
.ropeproject
120+
121+
# mkdocs documentation
122+
/site
123+
124+
# mypy
125+
.mypy_cache/
126+
.dmypy.json
127+
dmypy.json
128+
129+
# Pyre type checker
130+
.pyre/
131+
132+
# Sublime Text
133+
*.sublime-workspace
134+
135+
# macOS
136+
.DS_Store
137+
138+
# IntelliJ IDEA
139+
.idea/

.pylintrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[MASTER]
2+
3+
ignore=docs, __pycache__
4+
disable=
5+
no-member,
6+
too-many-arguments,
7+
too-few-public-methods,
8+
logging-format-interpolation,
9+
missing-module-docstring
10+

README.md

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# python-gitmodel
2+
3+
[![PyPI version](https://badge.fury.io/py/gitarmony-python.svg)](https://badge.fury.io/py/gitarmony-python)
4+
[![Documentation Status](https://readthedocs.org/projects/gitarmony-python/badge/?version=latest)](https://gitarmony-python.readthedocs.io/en/latest)
5+
[![codecov](https://codecov.io/gh/bendavis78/python-gitmodel/branch/master/graph/badge.svg?token=5267NA3EQQ)](https://codecov.io/gh/bendavis78/python-gitmodel)
6+
7+
## A distributed, versioned data store for Python
8+
9+
python-gitmodel is a framework for persisting objects using Git for
10+
versioning and remote syncing.
11+
12+
## Why?
13+
14+
According to [Git's README](<https://github.com/git/git#readme>), Git
15+
is a \"stupid content tracker\". That means you aren\'t limited to
16+
storing source code in git. The goal of this project is to provide an
17+
object-level interface to use git as a schema-less data store, as well
18+
as tools that take advantage of git\'s powerful versioning capabilities.
19+
20+
python-gitmodel allows you to model your data using python, and provides
21+
an easy-to-use interface for storing that data as git objects.
22+
23+
python-gitmodel is based on [libgit2](<http://libgit2.github.com>), a
24+
pure C implementation of the Git core methods. This means that instead
25+
of calling git commands via shell, we get to use git at native speed.
26+
27+
## What\'s so great about it?
28+
29+
* Schema-less data store
30+
* Never lose data. History is kept forever and can be restored using
31+
* git tools.
32+
* Branch and merge your production data
33+
* gitmodel can work with different branches
34+
* branch or tag snapshots of your data
35+
* experiment on production data using branches, for example, to test a migration
36+
* Ideal for content-driven applications
37+
38+
## Example usage
39+
40+
Below we\'ll cover a use-case for a basic flat-page CMS.
41+
42+
Basic model creation:
43+
```python
44+
from gitmodel.workspace import Workspace from gitmodel import fields ws = Workspace('path/to/my-repo/.git') class Page(ws.GitModel): slug = fields.SlugField() title = fields.CharField() content = fields.CharField() published = fields.BooleanField(default=True)
45+
```
46+
47+
The Workspace can be thought of as your git working directory. It also
48+
acts as the \"porcelain\" layer to pygit2\'s \"plumbing\". In contrast
49+
to a working directory, the Workspace class does not make use of the
50+
repository\'s INDEX and HEAD files, and instead keeps track of these in
51+
memory.
52+
53+
Saving objects:
54+
```python
55+
page = Page(slug='example-page', title='Example Page') page.content = '<h2>Here is an Example</h2><p>Lorem Ipsum</p>' page.save() print(page.id) # abc99c394ab546dd9d6e3381f9c0fb4b
56+
```
57+
58+
By default, objects get an auto-ID field which saves as a python UUID
59+
hex (don\'t confuse these with git hashes). You can easily customize
60+
which field in your model acts as the ID field, for example:
61+
```python
62+
class Page(ws.GitModel): slug = fields.SlugField(id=True) # OR class Page(ws.GitModel): slug = fields.SlugField() class Meta: id_field = 'slug'
63+
```
64+
65+
Objects are not committed to the repository by default. They are,
66+
however, written into the object database as trees and blobs. The
67+
[Workspace.index]{.title-ref} object is a [pygit2.Tree]{.title-ref} that
68+
holds the uncommitted data. It\'s analagous to Git\'s index, except that
69+
the pointer is stored in memory.
70+
71+
Creating commits is simple:
72+
```python
73+
oid = page.save(commit=True, message='Added an example page') commit = ws.repo[oid] # a pygit2.Commit object print(commit.message)
74+
```
75+
76+
You can access previous commits using pygit2, and even view diffs
77+
between two versions of an object.
78+
```python
79+
# walking commits for commit in ws.walk(): print("{}: {}".format(commit.hex, commit.message)) # get a diff between two commits head_commit = ws.branch.commit prev_commit_oid = head_commit.parents[0] print(prev_commit.diff(head_commit))
80+
```
81+
82+
Objects can be easily retrieved by their id:
83+
```python
84+
page = Page.get('example-page') print(page.content)
85+
```
86+
87+
# Caveat Emptor
88+
89+
Git doesn\'t perform very well on its own. If you need your git-backed
90+
data to perform well in a production environment, you need to get it a
91+
\"wingman\". Since python-gitmodel can be used in a variety of ways,
92+
it\'s up to you to decide the best way to optimize it.
93+
94+
# Status
95+
96+
This project is no longer under active development.
97+
98+
# TODO
99+
100+
* Caching?
101+
* Indexing?
102+
* Query API?
103+
* Full documentation
104+
105+
python-gitmodel was inspired by Rick Olson\'s talk, \"[Git, the Stupid
106+
NoSQL Database](<http://git-nosql-rubyconf.heroku.com/>)\" and Paul
107+
Downman\'s [GitModel](<https://github.com/pauldowman/gitmodel/>) for
108+
ruby.
109+
110+
# Development
111+
112+
This projects requires the following:
113+
114+
- [Python >=3.7.9](https://www.python.org/downloads/release/python-379/)
115+
- [virtualenwrapper](https://pypi.org/project/virtualenvwrapper/) (macOS/Linux)
116+
- [virtualenwrapper-win](https://pypi.org/project/virtualenvwrapper-win/) (Windows)
117+
118+
Make sure your `WORKON_HOME` environment variable is set on Windows, and create a `gitmodel` virtual environment with `mkvirtualenv`.
119+
Build systems for installing requirements and running tests are on board of the SublimeText project.

0 commit comments

Comments
 (0)