[Checkins] SVN: zope.sqlalchemy/tags/0.2/ tag 0.2
Laurence Rowe
l at lrowe.co.uk
Sat Jun 28 10:34:57 EDT 2008
Log message for revision 87845:
tag 0.2
Changed:
A zope.sqlalchemy/tags/0.2/
D zope.sqlalchemy/tags/0.2/CHANGES.txt
A zope.sqlalchemy/tags/0.2/CHANGES.txt
D zope.sqlalchemy/tags/0.2/README.txt
A zope.sqlalchemy/tags/0.2/README.txt
D zope.sqlalchemy/tags/0.2/setup.py
A zope.sqlalchemy/tags/0.2/setup.py
D zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt
A zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt
-=-
Copied: zope.sqlalchemy/tags/0.2 (from rev 87842, zope.sqlalchemy/trunk)
Deleted: zope.sqlalchemy/tags/0.2/CHANGES.txt
===================================================================
--- zope.sqlalchemy/trunk/CHANGES.txt 2008-06-28 13:49:55 UTC (rev 87842)
+++ zope.sqlalchemy/tags/0.2/CHANGES.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -1,15 +0,0 @@
-zope.sqlalchemy changes
-***********************
-
-0.2 (2008-06-28)
-================
-
-Feature changes
----------------
-
-* Updated to support SQLAlchemy 0.5. (0.4.6 is still supported).
-
-0.1 (2008-05-15)
-================
-
-Initial public release.
Copied: zope.sqlalchemy/tags/0.2/CHANGES.txt (from rev 87844, zope.sqlalchemy/trunk/CHANGES.txt)
===================================================================
--- zope.sqlalchemy/tags/0.2/CHANGES.txt (rev 0)
+++ zope.sqlalchemy/tags/0.2/CHANGES.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -0,0 +1,15 @@
+Changes
+=======
+
+0.2 (2008-06-28)
+----------------
+
+Feature changes
+~~~~~~~~~~~~~~~
+
+* Updated to support SQLAlchemy 0.5. (0.4.6 is still supported).
+
+0.1 (2008-05-15)
+----------------
+
+Initial public release.
Deleted: zope.sqlalchemy/tags/0.2/README.txt
===================================================================
--- zope.sqlalchemy/trunk/README.txt 2008-06-28 13:49:55 UTC (rev 87842)
+++ zope.sqlalchemy/tags/0.2/README.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -1,3 +0,0 @@
-***************
-zope.sqlalchemy
-***************
Copied: zope.sqlalchemy/tags/0.2/README.txt (from rev 87844, zope.sqlalchemy/trunk/README.txt)
===================================================================
--- zope.sqlalchemy/tags/0.2/README.txt (rev 0)
+++ zope.sqlalchemy/tags/0.2/README.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -0,0 +1 @@
+Minimal Zope/SQLAlchemy transaction integration
\ No newline at end of file
Deleted: zope.sqlalchemy/tags/0.2/setup.py
===================================================================
--- zope.sqlalchemy/trunk/setup.py 2008-06-28 13:49:55 UTC (rev 87842)
+++ zope.sqlalchemy/tags/0.2/setup.py 2008-06-28 14:34:56 UTC (rev 87845)
@@ -1,54 +0,0 @@
-from setuptools import setup, find_packages
-import sys, os
-
-def read(*rnames):
- return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-def desc(*texts):
- return '\n'.join(texts)
-
-SVN_VERSION = "`SVN version <svn://svn.zope.org/repos/main/zope.sqlalchemy/trunk#egg=zope.sqlalchemy-dev>`_\n"
-
-long_description = desc(
- read('README.txt'),
- read('src', 'zope', 'sqlalchemy', 'README.txt'),
- SVN_VERSION,
- read('CHANGES.txt'),
- 'Download\n********\n',
- )
-
-setup(name='zope.sqlalchemy',
- version='0.2', # Remember to update __version__ in __init__.py
- description="Minimal Zope/SQLAlchemy transaction integration",
- long_description=long_description,
- # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
- classifiers=[
- "Framework :: Zope3",
- "Programming Language :: Python",
- "License :: OSI Approved :: Zope Public License",
- "Topic :: Software Development :: Libraries :: Python Modules",
- ],
- keywords='',
- author='Laurence Rowe',
- author_email='laurence at lrowe.co.uk',
- url='http://pypi.python.org/pypi/zope.sqlalchemy',
- license='ZPL 2.1',
- packages=find_packages('src'),
- package_dir = {'':'src'},
- namespace_packages=['zope'],
- include_package_data=True,
- zip_safe=False,
- install_requires=[
- # -*- Extra requirements: -*-
- 'setuptools',
- 'SQLAlchemy>=0.4.6',
- 'transaction',
- 'zope.interface',
- ],
- entry_points="""
- # -*- Entry points: -*-
- """,
- extras_require = dict(
- test = ['zope.testing'],
- ),
- )
Copied: zope.sqlalchemy/tags/0.2/setup.py (from rev 87844, zope.sqlalchemy/trunk/setup.py)
===================================================================
--- zope.sqlalchemy/tags/0.2/setup.py (rev 0)
+++ zope.sqlalchemy/tags/0.2/setup.py 2008-06-28 14:34:56 UTC (rev 87845)
@@ -0,0 +1,92 @@
+import os
+from setuptools import setup, find_packages
+
+# generic helpers primarily for the long_description
+try:
+ import docutils
+except ImportError:
+ import warnings
+ def validateReST(text):
+ return ''
+else:
+ import docutils.utils
+ import docutils.parsers.rst
+ import StringIO
+ def validateReST(text):
+ doc = docutils.utils.new_document('validator')
+ # our desired settings
+ doc.reporter.halt_level = 5
+ doc.reporter.report_level = 1
+ stream = doc.reporter.stream = StringIO.StringIO()
+ # docutils buglets (?)
+ doc.settings.tab_width = 2
+ doc.settings.pep_references = doc.settings.rfc_references = False
+ doc.settings.trim_footnote_reference_space = None
+ # and we're off...
+ parser = docutils.parsers.rst.Parser()
+ parser.parse(text, doc)
+ return stream.getvalue()
+
+def text(*args, **kwargs):
+ # note: distutils explicitly disallows unicode for setup values :-/
+ # http://docs.python.org/dist/meta-data.html
+ tmp = []
+ for a in args:
+ if a.endswith('.txt'):
+ f = open(os.path.join(*a.split('/')))
+ tmp.append(f.read())
+ f.close()
+ tmp.append('\n\n')
+ else:
+ tmp.append(a)
+ if len(tmp) == 1:
+ res = tmp[0]
+ else:
+ res = ''.join(tmp)
+ report = validateReST(res)
+ if report:
+ print report
+ raise ValueError('ReST validation error')
+ return res
+# end helpers; below this line should be code custom to this package
+
+setup(
+ name='zope.sqlalchemy',
+ version='0.2', # Remember to update __version__ in __init__.py
+
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ include_package_data=True,
+ zip_safe=False,
+
+ namespace_packages=['zope'],
+
+ author='Laurence Rowe',
+ author_email='laurence at lrowe.co.uk',
+ url='http://pypi.python.org/pypi/zope.sqlalchemy',
+ description=text('README.txt'),
+ long_description=text('src/zope/sqlalchemy/README.txt',
+ 'CHANGES.txt',
+ out=True),
+ license='ZPL 2.1',
+ keywords='zope zope3 sqlalchemy',
+ classifiers=[
+ "Framework :: Zope3",
+ "Programming Language :: Python",
+ "License :: OSI Approved :: Zope Public License",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
+
+ install_requires=[
+ 'setuptools',
+ 'SQLAlchemy>=0.4.6',
+ 'transaction',
+ 'zope.interface',
+ ],
+ extras_require={
+ 'test': [
+ 'zope.testing',
+ 'docutils',
+ ]
+ },
+ )
Deleted: zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt 2008-06-28 13:49:55 UTC (rev 87842)
+++ zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -1,163 +0,0 @@
-zope.sqlalchemy
-***************
-
-Introduction
-============
-
-The aim of this package is to unify the plethora of existing packages
-integrating SQLAlchemy with Zope's transaction management. As such it seeks
-only to provide a data manager and makes no attempt to define a `zopeish` way
-to configure engines.
-
-You need to understand SQLAlchemy for this package and this README to make
-any sense. See http://sqlalchemy.org/docs/.
-
-
-Running the tests
-=================
-
-This package is distributed as a buildout. Using your desired python run:
-
-$ python bootstrap.py
-
-This will download the dependent packages and setup the test script, which may
-be run with:
-
-$ ./bin/test
-
-To enable testing with your own database set the TEST_DSN environment variable
-to your sqlalchemy database dsn. Two-phase commit behaviour may be tested by
-setting the TEST_TWOPHASE variable to a non empty string. e.g:
-
-$ TEST_DSN=postgres://test:test@localhost/test TEST_TWOPHASE=True bin/test
-
-Example
-=======
-
-This example is lifted directly from the SQLAlchemy declarative documentation.
-First the necessary imports.
-
- >>> from sqlalchemy import *
- >>> from sqlalchemy.ext.declarative import declarative_base
- >>> from sqlalchemy.orm import scoped_session, sessionmaker, relation
- >>> from zope.sqlalchemy import ZopeTransactionExtension, invalidate
- >>> import transaction
-
-Now to define the mapper classes.
-
- >>> Base = declarative_base()
- >>> class User(Base):
- ... __tablename__ = 'test_users'
- ... id = Column('id', Integer, primary_key=True)
- ... name = Column('name', String(50))
- ... addresses = relation("Address", backref="user")
- >>> class Address(Base):
- ... __tablename__ = 'test_addresses'
- ... id = Column('id', Integer, primary_key=True)
- ... email = Column('email', String(50))
- ... user_id = Column('user_id', Integer, ForeignKey('test_users.id'))
-
-Create an engine and setup the tables. Note that for this example to work a
-recent version of sqlite/pysqlite is required. 3.4.0 seems to be sufficient.
-
- >>> engine = create_engine(TEST_DSN, convert_unicode=True)
- >>> Base.metadata.create_all(engine)
-
-Now to create the session itself. As zope is a threaded web server we must use
-scoped sessions. Zope and SQLAlchemy sessions are tied together by using the
-ZopeTransactionExtension from this package.
-
- >>> if SA_0_5:
- ... Session = scoped_session(sessionmaker(bind=engine,
- ... twophase=TEST_TWOPHASE, extension=ZopeTransactionExtension()))
-
-The exact arguments depend on the version. Under SQLAlchemy 0.4 we must also
-supply transactional=True (equivalent to autocommit=False, which is default
-under 0.5).
-
- >>> if SA_0_4:
- ... Session = scoped_session(sessionmaker(bind=engine,
- ... twophase=TEST_TWOPHASE, extension=ZopeTransactionExtension(),
- ... transactional=True, autoflush=True,))
-
-Call the scoped session factory to retrieve a session. You may call this as
-many times as you like within a transaction and you will always retrieve the
-same session. At present there are no users in the database.
-
- >>> session = Session()
- >>> session.query(User).all()
- []
-
-We can now create a new user and commit the changes using Zope's transaction
-machinary, just as Zope's publisher would.
-
- >>> session.save(User(name='bob'))
- >>> transaction.commit()
-
-Engine level connections are outside the scope of the transaction integration.
-
- >>> engine.connect().execute('SELECT * FROM test_users').fetchall()
- [(1, ...'bob')]
-
-A new transaction requires a new session. Let's add an address.
-
- >>> session = Session()
- >>> bob = session.query(User).all()[0]
- >>> bob.name
- u'bob'
- >>> bob.addresses
- []
- >>> bob.addresses.append(Address(email='bob at bob.bob'))
- >>> transaction.commit()
- >>> session = Session()
- >>> bob = session.query(User).all()[0]
- >>> bob.addresses
- [<Address object at ...>]
- >>> bob.addresses[0].email
- u'bob at bob.bob'
- >>> bob.addresses[0].email = 'wrong at wrong'
-
-To rollback a transaction, use transaction.abort().
-
- >>> transaction.abort()
- >>> session = Session()
- >>> bob = session.query(User).all()[0]
- >>> bob.addresses[0].email
- u'bob at bob.bob'
- >>> transaction.abort()
-
-By default, zope.sqlalchemy puts sessions in an 'active' state when they are
-first used. ORM write operations automatically move the session into an
-'invalidated' state. This avoids unnecessary database commits. Sometimes it
-is necessary to interact with the database directly through SQL. It is not
-possible to guess whether such an operation is a read or a write. Therefore we
-must manually mark the session as invalidated when manual SQL statements write
-to the DB.
-
- >>> session = Session()
- >>> conn = session.connection()
- >>> users = Base.metadata.tables['test_users']
- >>> conn.execute(users.update(users.c.name=='bob'), name='ben')
- <sqlalchemy.engine.base.ResultProxy object at ...>
- >>> from zope.sqlalchemy import invalidate
- >>> invalidate(session)
- >>> transaction.commit()
- >>> session = Session()
- >>> session.query(User).all()[0].name
- u'ben'
- >>> transaction.abort()
-
-If this is a problem you may tell the extension to place the session in the
-'invalidated' state initially.
-
- >>> Session.configure(extension=ZopeTransactionExtension('invalidated'))
- >>> Session.remove()
- >>> session = Session()
- >>> conn = session.connection()
- >>> conn.execute(users.update(users.c.name=='ben'), name='bob')
- <sqlalchemy.engine.base.ResultProxy object at ...>
- >>> transaction.commit()
- >>> session = Session()
- >>> session.query(User).all()[0].name
- u'bob'
- >>> transaction.abort()
Copied: zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt (from rev 87844, zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt)
===================================================================
--- zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt (rev 0)
+++ zope.sqlalchemy/tags/0.2/src/zope/sqlalchemy/README.txt 2008-06-28 14:34:56 UTC (rev 87845)
@@ -0,0 +1,173 @@
+***************
+zope.sqlalchemy
+***************
+
+.. contents::
+ :local:
+
+Introduction
+============
+
+The aim of this package is to unify the plethora of existing packages
+integrating SQLAlchemy with Zope's transaction management. As such it seeks
+only to provide a data manager and makes no attempt to define a `zopeish` way
+to configure engines.
+
+You need to understand SQLAlchemy for this package and this README to make
+any sense. See http://sqlalchemy.org/docs/.
+
+
+Running the tests
+=================
+
+This package is distributed as a buildout. Using your desired python run:
+
+$ python bootstrap.py
+
+This will download the dependent packages and setup the test script, which may
+be run with:
+
+$ ./bin/test
+
+To enable testing with your own database set the TEST_DSN environment variable
+to your sqlalchemy database dsn. Two-phase commit behaviour may be tested by
+setting the TEST_TWOPHASE variable to a non empty string. e.g:
+
+$ TEST_DSN=postgres://test:test@localhost/test TEST_TWOPHASE=True bin/test
+
+Example
+=======
+
+This example is lifted directly from the SQLAlchemy declarative documentation.
+First the necessary imports.
+
+ >>> from sqlalchemy import *
+ >>> from sqlalchemy.ext.declarative import declarative_base
+ >>> from sqlalchemy.orm import scoped_session, sessionmaker, relation
+ >>> from zope.sqlalchemy import ZopeTransactionExtension, invalidate
+ >>> import transaction
+
+Now to define the mapper classes.
+
+ >>> Base = declarative_base()
+ >>> class User(Base):
+ ... __tablename__ = 'test_users'
+ ... id = Column('id', Integer, primary_key=True)
+ ... name = Column('name', String(50))
+ ... addresses = relation("Address", backref="user")
+ >>> class Address(Base):
+ ... __tablename__ = 'test_addresses'
+ ... id = Column('id', Integer, primary_key=True)
+ ... email = Column('email', String(50))
+ ... user_id = Column('user_id', Integer, ForeignKey('test_users.id'))
+
+Create an engine and setup the tables. Note that for this example to work a
+recent version of sqlite/pysqlite is required. 3.4.0 seems to be sufficient.
+
+ >>> engine = create_engine(TEST_DSN, convert_unicode=True)
+ >>> Base.metadata.create_all(engine)
+
+Now to create the session itself. As zope is a threaded web server we must use
+scoped sessions. Zope and SQLAlchemy sessions are tied together by using the
+ZopeTransactionExtension from this package.
+
+ >>> if SA_0_5:
+ ... Session = scoped_session(sessionmaker(bind=engine,
+ ... twophase=TEST_TWOPHASE, extension=ZopeTransactionExtension()))
+
+The exact arguments depend on the version. Under SQLAlchemy 0.4 we must also
+supply transactional=True (equivalent to autocommit=False, which is default
+under 0.5).
+
+ >>> if SA_0_4:
+ ... Session = scoped_session(sessionmaker(bind=engine,
+ ... twophase=TEST_TWOPHASE, extension=ZopeTransactionExtension(),
+ ... transactional=True, autoflush=True,))
+
+Call the scoped session factory to retrieve a session. You may call this as
+many times as you like within a transaction and you will always retrieve the
+same session. At present there are no users in the database.
+
+ >>> session = Session()
+ >>> session.query(User).all()
+ []
+
+We can now create a new user and commit the changes using Zope's transaction
+machinary, just as Zope's publisher would.
+
+ >>> session.save(User(name='bob'))
+ >>> transaction.commit()
+
+Engine level connections are outside the scope of the transaction integration.
+
+ >>> engine.connect().execute('SELECT * FROM test_users').fetchall()
+ [(1, ...'bob')]
+
+A new transaction requires a new session. Let's add an address.
+
+ >>> session = Session()
+ >>> bob = session.query(User).all()[0]
+ >>> bob.name
+ u'bob'
+ >>> bob.addresses
+ []
+ >>> bob.addresses.append(Address(email='bob at bob.bob'))
+ >>> transaction.commit()
+ >>> session = Session()
+ >>> bob = session.query(User).all()[0]
+ >>> bob.addresses
+ [<Address object at ...>]
+ >>> bob.addresses[0].email
+ u'bob at bob.bob'
+ >>> bob.addresses[0].email = 'wrong at wrong'
+
+To rollback a transaction, use transaction.abort().
+
+ >>> transaction.abort()
+ >>> session = Session()
+ >>> bob = session.query(User).all()[0]
+ >>> bob.addresses[0].email
+ u'bob at bob.bob'
+ >>> transaction.abort()
+
+By default, zope.sqlalchemy puts sessions in an 'active' state when they are
+first used. ORM write operations automatically move the session into an
+'invalidated' state. This avoids unnecessary database commits. Sometimes it
+is necessary to interact with the database directly through SQL. It is not
+possible to guess whether such an operation is a read or a write. Therefore we
+must manually mark the session as invalidated when manual SQL statements write
+to the DB.
+
+ >>> session = Session()
+ >>> conn = session.connection()
+ >>> users = Base.metadata.tables['test_users']
+ >>> conn.execute(users.update(users.c.name=='bob'), name='ben')
+ <sqlalchemy.engine.base.ResultProxy object at ...>
+ >>> from zope.sqlalchemy import invalidate
+ >>> invalidate(session)
+ >>> transaction.commit()
+ >>> session = Session()
+ >>> session.query(User).all()[0].name
+ u'ben'
+ >>> transaction.abort()
+
+If this is a problem you may tell the extension to place the session in the
+'invalidated' state initially.
+
+ >>> Session.configure(extension=ZopeTransactionExtension('invalidated'))
+ >>> Session.remove()
+ >>> session = Session()
+ >>> conn = session.connection()
+ >>> conn.execute(users.update(users.c.name=='ben'), name='bob')
+ <sqlalchemy.engine.base.ResultProxy object at ...>
+ >>> transaction.commit()
+ >>> session = Session()
+ >>> session.query(User).all()[0].name
+ u'bob'
+ >>> transaction.abort()
+
+Development version
+===================
+
+`SVN version <svn://svn.zope.org/repos/main/zope.sqlalchemy/trunk#egg=zope.sqlalchemy-dev>`_
+
More information about the Checkins
mailing list