Commit dcf502bd authored by Sophie Brun's avatar Sophie Brun

New upstream version 0.7.0

parents
*.db
*.egg-info
*-py2.6.egg
*.log
*.pyc
*.swp
*/.coverage
.coverage
/cover/
*~
pyforge/docs/_build/*
mail/logs/*
sandbox-env/*
download/*
install/*
build/*
dist/*
docs/_build/*
Vagrantfile
parser_*.out
parsetab_*
.tox
.eggs/
venv/
language: python
sudo: false
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
install:
- "travis_retry pip install --upgrade pip"
- "travis_retry pip install --upgrade setuptools"
- "travis_retry pip install coveralls"
- "travis_retry pip install tox-travis"
script: "tox"
after_success:
- "coveralls"
\ No newline at end of file
See docs/news.rst
Ming
====
.. image:: https://travis-ci.org/TurboGears/Ming.png
:target: https://travis-ci.org/TurboGears/Ming
.. image:: https://coveralls.io/repos/TurboGears/Ming/badge.png
:target: https://coveralls.io/r/TurboGears/Ming
.. image:: https://img.shields.io/pypi/v/Ming.svg
:target: https://pypi.python.org/pypi/Ming
.. image:: https://img.shields.io/pypi/pyversions/Ming.svg
:target: https://pypi.python.org/pypi/Ming
.. image:: https://img.shields.io/pypi/l/Ming.svg
:target: https://pypi.python.org/pypi/Ming
.. image:: https://img.shields.io/gitter/room/turbogears/Lobby.svg
:target: https://gitter.im/turbogears/Lobby
.. image:: https://img.shields.io/twitter/follow/turbogearsorg.svg?style=social&label=Follow
:target: https://twitter.com/turbogearsorg
Ming is a MongoDB ODM ( Object Document Mapper, like an ORM but for Document based databases),
that builds on top of ``pymongo`` by extending it with:
* Declarative Models
* Schema Validation and Conversion
* Lazy Schema Evolution
* Unit of Work
* Identity Map
* One-To-Many, Many-To-One and Many-To-Many Relations
* Pure InMemory MongoDB Implementation
Ming is the official MongoDB support layer of `TurboGears <http://www.turbogears.org>`_ web
framework, thus feel free to join the TurboGears Gitter or Twitter to discuss Ming.
If you want to dig further in Ming, documentation is available
at http://ming.readthedocs.io/en/latest/
Getting Started
---------------
To use Ming you need to create a ``Session`` and a few models that
should be managed by it::
from ming import create_datastore, schema
from ming.odm import ThreadLocalODMSession, Mapper, MappedClass, FieldProperty
session = ThreadLocalODMSession(
bind=create_datastore('mongodb://localhost:27017/dbname')
)
class WikiPage(MappedClass):
class __mongometa__:
session = session
name = 'wiki_page'
_id = FieldProperty(schema.ObjectId)
title = FieldProperty(schema.String(required=True))
text = FieldProperty(schema.String(if_missing=''))
Mapper.compile_all()
Then you can create and query those models::
>>> WikiPage(title='FirstPage', text='This is a page')
<WikiPage text='This is a page'
_id=ObjectId('5ae4ef717ddf1ff6704afff5')
title='FirstPage'>
>>> session.flush() # Flush session to actually create wikipage.
>>> wp = WikiPage.query.find({'text': 'This is a page'}).first()
>>> print(wp)
<WikiPage text='This is a page'
_id=ObjectId('5ae4ef717ddf1ff6704afff5')
title='FirstPage'>
import sys
import time
from datetime import datetime
from ming import Document, Field, Session
from ming import schema as S
from ming.datastore import DataStore
NUM_ITER = 100
doc_session = Session.by_name('benchmark')
doc_session.bind = DataStore('mongodb://localhost:27017', database='benchmark')
class StringNotNone(S.String):
'''
Stronger than if_missing='', this also converts an
explicit None to ''
'''
def validate(self, value, **kw):
if value == None or value is S.Missing:
value = ''
return S.String.validate(self, value, **kw)
class Project(Document):
class __mongometa__:
session = doc_session
name='projects'
indexes=[
('shortname',),
('source',),
('sf_id',),
]
unique_indexes=[
('shortname', 'source'),
]
_review = dict(
rating=int, useful=float, useless=float, approved=bool,
user=str, comments=str, safe_html=bool, source=str,
usefulness=float, date=datetime)
_screenshot = dict(url=str, thumb=str, name=str, description=str)
_category = dict(id=int, shortname=str, name=str, description=str, fullpath=str)
_resource = dict(url=str, name=str, feed=str,
item_count=int, item_open_count=int)
_person = dict(
username=None,
homepage=None,
name=None)
_id=Field(S.ObjectId)
shortname=Field(str)
source=Field(str)
sf_id=Field(int)
projecttype=Field(int)
private=Field(S.Bool(if_missing=False))
name=Field(str)
summary=Field(StringNotNone)
created=Field(datetime)
description=Field(StringNotNone)
doap=Field(str)
project_url=Field(str)
homepage=Field(str)
updated=Field(S.Deprecated)
_last_changed=Field('last_changed', datetime)
ad_keywords=Field([[str]]) # ['ohl', 'ad20848'] would translate to "ohl=ad20848;" in JS
download_info=Field(S.Deprecated)
_icon_url=Field('icon_url', S.String(if_missing=S.Missing)) # for backward compat.
_features=Field('features', S.Array(str, if_missing=S.Missing)) # for backward compat.
reviews_disabled=Field(bool)
relations_data=Field(S.Object(dict(
is_admin=S.Deprecated,
rating=float,
code=int,
review_count=int,
features=[str],
tags=[dict(count=int, tag=str, approved=bool)],
icon_url=str,
latest_reviews=[_review],
name=str,
reviews=[_review],
text=str), if_missing=None))
related=Field([dict(source=None, shortname=None, name=str, description=str,
screenshots=[_screenshot], ok_to_recommend=bool,
rating=float, review_count=int, icon_url=str) ])
recommended=Field([dict(source=None, shortname=None, name=str, description=str)])
screenshots=Field([ _screenshot ])
resources=Field(dict(
other=[_resource],
mailing_lists=[_resource],
news=[_resource],
forums=[_resource],
trackers=[_resource],
))
feed_recent_items=Field([
dict(
_id=str,
description=str,
title=str,
url=str,
project=dict(source=str, shortname=str),
date=datetime,
type=str,
description_type=str,
author_username=str,
permission_required=S.Array(str, if_missing=None), # controllers/project.py queries mongodb for None which doens't match []
)
])
categories=Field({
'Topic':[_category],
'Operating System':[_category],
'Development Status':[_category],
'License':[_category],
'Translations':[_category],
'Intended Audience':[_category],
'User Interface':[_category],
'Programming Language':[_category],
'Database Environment':[_category],
})
feeds_last_item=Field(S.Migrate(
None, [ dict(url=str, date=datetime) ],
S.Migrate.obj_to_list('url', 'date')))
inactive=Field(datetime)
new_project_url=Field(str)
donation_page=Field(str)
preferred_support=Field(str)
code_repositories=Field([
dict(
label=str,
browse=str,
write_operations=int,
read_operations=int,
location=str,
type=str) ])
releases=Field(
S.Array(
dict(
filename=str,
url=str,
date=datetime,
bytes=float,
file_type=S.String(if_missing=''),
mime_type=str,
md5sum=str,
sf_download_label=str, sf_platform_default=[str], sf_release_notes_file=str,
sf_file_id=int,
# FRS data (pre-PFS)
sf_release_id=int, sf_package_id=int, sf_type=str, sf_platform=[str],
release_notes_url=str,
# old FRS data (shouldn't exist any more)
# download_count=S.Deprecated,
# group=S.Deprecated, #str,
# version=S.Deprecated, #str,
# changelog=S.Deprecated, #str,
# release_notes=S.Deprecated, #str,
),
validate_ranges=(
slice(0, 5), slice(-5, -1))
))
download_page=Field(str)
screenshot_page=Field(str)
maintainers=Field([_person])
developers=Field([_person])
file_feed=Field(str)
awards=Field([ dict(category=str, url=str, event=str, img_url=str) ])
sf_piwik_siteid=Field(str)
license=Field(S.Deprecated())
license_uri=Field(str)
license_title=Field(str)
developer_page=Field(str)
test_foo2=Field(S.Deprecated)
fossforus_id=Field(S.Deprecated)
fossforus_screenshots=Field(S.Deprecated)
fossforus_features=Field(S.Deprecated)
fossforus_tags=Field(S.Deprecated)
fossforus_ratings=Field(S.Deprecated)
_last_snapshot_id=Field(S.Deprecated)
print 'Begin test'
sys.stdout.flush()
begin = time.time()
for x in xrange(NUM_ITER):
Project.m.find(validate=True).next()
print '.',
sys.stdout.flush()
elapsed = time.time() - begin
docs_per_s = float(NUM_ITER) / elapsed
ms_per_doc = 1000 / docs_per_s
print 'Validated %d docs in %d secs (%.2f docs/s, %d ms/doc)' % (
NUM_ITER, elapsed, docs_per_s, ms_per_doc)
This diff is collapsed.
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
upload: html
rsync -cavz _build/html/* rick446,merciless@web.sourceforge.net:htdocs
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Ming.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Ming.qhc"
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
:mod:`ming.base` module
=======================
.. automodule:: ming.base
.. autodata:: Missing
Functions
---------
.. autofunction:: _safe_bson
Classes
-------
.. autoclass:: Cursor
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: ming.metadata._Document
:show-inheritance:
:members:
:undoc-members:
.. autoclass:: ming.declarative._DocumentMeta
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: ming.metadata.Field
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: ming.metadata._ClassManager
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: ming.metadata._InstanceManager
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: ming.metadata._ManagerDescriptor
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
.. autoclass:: Object
:show-inheritance:
:members:
:undoc-members:
:mod:`ming.datastore` module
============================
.. automodule:: ming.datastore
:members:
\ No newline at end of file
:mod:`ming.odm` module
======================
.. automodule:: ming.odm.declarative
:members:
.. automodule:: ming.odm.base
:members:
.. automodule:: ming.odm.property
:members:
.. automodule:: ming.odm.odmsession
:members:
.. automodule:: ming.odm.mapper
:members:
.. autoclass:: ming.odm.middleware.MingMiddleware
:mod:`ming` module
==================
.. automodule:: ming
.. autofunction:: configure
.. autoclass:: Index
:mod:`ming.schema` module
=========================
.. automodule:: ming.schema
:members:
:private-members:
:mod:`ming.utils` module
========================
.. automodule:: ming.utils
Functions
----------
.. autofunction:: encode_keys
.. autofunction:: all_class_properties
Classes
--------
.. autoclass:: LazyProperty
:show-inheritance:
:members:
:inherited-members:
:undoc-members:
This diff is collapsed.
# -*- coding: utf-8 -*-
#
# Ming documentation build configuration file, created by
# sphinx-quickstart on Thu Nov 19 19:51:17 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
if os.environ.get('READTHEDOCS', None) == 'True':
# MonkeyPatch create_datastore to build on readthedocs.
from ming import datastore
_create_engine = datastore.create_engine
datastore.create_engine = lambda *args, **kwargs: _create_engine('mim:///')
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# This is required to load the sphinx_runsnippet extension
sys.path.append(os.path.abspath('.'))
# This is used to be able to import snippets in doc
sys.path.append(os.path.abspath('./src'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.autosummary',
'sphinx_runsnippet']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Ming'
copyright = u'2009, Rick Copeland, Mark Ramm, Dave Brondsema, Jonathan Beard, Wolf'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
exec open('../ming/version.py')
# The short X.Y version.
version = __version__
# The full version, including alpha/beta/rc tags.
release = __version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'friendly'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'bizstyle'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True