[Checkins] SVN: zope.sqlalchemy/trunk/ merge 0.5 support to trunk

Laurence Rowe l at lrowe.co.uk
Thu Jun 19 17:01:22 EDT 2008


Log message for revision 87565:
  merge 0.5 support to trunk

Changed:
  _U  zope.sqlalchemy/trunk/
  A   zope.sqlalchemy/trunk/CHANGES.txt
  A   zope.sqlalchemy/trunk/CREDITS.txt
  U   zope.sqlalchemy/trunk/README.txt
  U   zope.sqlalchemy/trunk/setup.py
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py

-=-

Property changes on: zope.sqlalchemy/trunk
___________________________________________________________________
Name: svn:ignore
   + parts
.installed.cfg
develop-eggs
bin



Copied: zope.sqlalchemy/trunk/CHANGES.txt (from rev 87564, zope.sqlalchemy/branches/sqlalchemy-0.5-support/CHANGES.txt)
===================================================================
--- zope.sqlalchemy/trunk/CHANGES.txt	                        (rev 0)
+++ zope.sqlalchemy/trunk/CHANGES.txt	2008-06-19 21:01:21 UTC (rev 87565)
@@ -0,0 +1,15 @@
+zope.sqlalchemy changes
+***********************
+
+0.2 (unreleased)
+================
+
+Features changes
+----------------
+
+* Updated to support SQLAlchemy 0.5.
+
+0.1
+===
+
+Initial public release.

Copied: zope.sqlalchemy/trunk/CREDITS.txt (from rev 87564, zope.sqlalchemy/branches/sqlalchemy-0.5-support/CREDITS.txt)
===================================================================
--- zope.sqlalchemy/trunk/CREDITS.txt	                        (rev 0)
+++ zope.sqlalchemy/trunk/CREDITS.txt	2008-06-19 21:01:21 UTC (rev 87565)
@@ -0,0 +1,10 @@
+zope.sqlalchemy credits
+***********************
+
+* Laurence Rowe - creator and main developer
+
+* Martijn Faassen - updated to work with SQLAlchemy 0.5
+
+Also thanks to Michael Bayer for help with integration in SQLAlchemy
+and of course SQLAlchemy itself, as well as the many Zope developers
+who worked on Zope/SQLAlchemy integration projects.

Modified: zope.sqlalchemy/trunk/README.txt
===================================================================
--- zope.sqlalchemy/trunk/README.txt	2008-06-19 20:53:26 UTC (rev 87564)
+++ zope.sqlalchemy/trunk/README.txt	2008-06-19 21:01:21 UTC (rev 87565)
@@ -1,5 +1,3 @@
-=================
- zope.sqlalchemy
-=================
-
-Zope/SQLAlchemy transaction integration. See src/zope/sqlalchemy/README.txt.
+***************
+zope.sqlalchemy
+***************

Modified: zope.sqlalchemy/trunk/setup.py
===================================================================
--- zope.sqlalchemy/trunk/setup.py	2008-06-19 20:53:26 UTC (rev 87564)
+++ zope.sqlalchemy/trunk/setup.py	2008-06-19 21:01:21 UTC (rev 87565)
@@ -4,16 +4,21 @@
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
-version = '0.1'
+def desc(*texts):
+    return '\n'.join(texts)
 
-long_description = read('src', 'zope', 'sqlalchemy', 'README.txt') + """
+SVN_VERSION = "`SVN version <svn://svn.zope.org/repos/main/zope.sqlalchemy/trunk#egg=zope.sqlalchemy-dev>`_\n"
 
-`SVN version <svn://svn.zope.org/repos/main/zope.sqlalchemy/trunk#egg=zope.sqlalchemy-dev>`_.
+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=version,
+      version='0.2dev',
       description="Minimal Zope/SQLAlchemy transaction integration",
       long_description=long_description,
       # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2008-06-19 20:53:26 UTC (rev 87564)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2008-06-19 21:01:21 UTC (rev 87565)
@@ -1,7 +1,9 @@
-=================
- zope.sqlalchemy
-=================
+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
@@ -12,7 +14,7 @@
 
 
 Running the tests
------------------
+=================
 
 This package is distributed as a buildout. Using your desired python run:
 
@@ -30,7 +32,7 @@
 $ 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.
@@ -65,9 +67,19 @@
 scoped sessions. Zope and SQLAlchemy sessions are tied together by using the
 ZopeTransactionExtension from this package.
 
-    >>> Session = scoped_session(sessionmaker(bind=engine, twophase=TEST_TWOPHASE,
-    ... transactional=True, autoflush=True, extension=ZopeTransactionExtension()))
+    >>> 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.

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py	2008-06-19 20:53:26 UTC (rev 87564)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py	2008-06-19 21:01:21 UTC (rev 87565)
@@ -43,11 +43,7 @@
     implements(ISavepointDataManager)
 
     def __init__(self, session, status):
-        if session.transactional:
-            self.tx = session.transaction._iterate_parents()[-1]
-        else:
-            assert session.transaction is None
-            self.tx = session.begin()
+        self.tx = session.transaction._iterate_parents()[-1]
         self.session = session
         _SESSION_STATE[id(session)] = status
         self.state = 'init'

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py	2008-06-19 20:53:26 UTC (rev 87564)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py	2008-06-19 21:01:21 UTC (rev 87565)
@@ -36,7 +36,10 @@
 TEST_TWOPHASE = bool(os.environ.get('TEST_TWOPHASE'))
 TEST_DSN = os.environ.get('TEST_DSN', 'sqlite:///:memory:')
 
+SA_0_4 = sa.__version__.split('.')[:2] == ['0', '4']
+SA_0_5 = not SA_0_4
 
+
 class SimpleModel(object):
     def __init__(self, **kw):
         for k, v in kw.items():
@@ -51,20 +54,31 @@
 engine = sa.create_engine(TEST_DSN)
 engine2 = sa.create_engine(TEST_DSN)
 
-Session = orm.scoped_session(orm.sessionmaker(
-    bind=engine,
-    extension=tx.ZopeTransactionExtension(),
-    transactional=True,
-    autoflush=True,
-    twophase=TEST_TWOPHASE,
-    ))
+if SA_0_4:
+    Session = orm.scoped_session(orm.sessionmaker(
+        bind=engine,
+        extension=tx.ZopeTransactionExtension(),
+        transactional=True,
+        autoflush=True,
+        twophase=TEST_TWOPHASE,
+        ))
+    UnboundSession = orm.scoped_session(orm.sessionmaker(
+        extension=tx.ZopeTransactionExtension(),
+        transactional=True,
+        autoflush=True,
+        twophase=TEST_TWOPHASE,
+        ))
 
-UnboundSession = orm.scoped_session(orm.sessionmaker(
-    extension=tx.ZopeTransactionExtension(),
-    transactional=True,
-    autoflush=True,
-    twophase=TEST_TWOPHASE,
-    ))
+if SA_0_5:
+    Session = orm.scoped_session(orm.sessionmaker(
+        bind=engine,
+        extension=tx.ZopeTransactionExtension(),
+        twophase=TEST_TWOPHASE,
+        ))
+    UnboundSession = orm.scoped_session(orm.sessionmaker(
+        extension=tx.ZopeTransactionExtension(),
+        twophase=TEST_TWOPHASE,
+        ))
 
 metadata = sa.MetaData() # best to use unbound metadata
 
@@ -165,14 +179,14 @@
         session.save(User(id=2, firstname='heino', lastname='n/a'))
         session.flush()
         
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
         self.assertEqual(len(rows), 2)
         row1 = rows[0]
         d = row1.asDict()
         self.assertEqual(d, {'firstname' : 'udo', 'lastname' : 'juergens', 'id' : 1})
         
         # bypass the session machinary
-        stmt = sql.select(query.table.columns).order_by('id')
+        stmt = sql.select(test_users.columns).order_by('id')
         conn = session.connection()
         results = conn.execute(stmt)
         self.assertEqual(results.fetchall(), [(1, u'udo', u'juergens'), (2, u'heino', u'n/a')])
@@ -240,26 +254,26 @@
         session.save(User(id=2, firstname='heino', lastname='n/a'))
         session.flush()
 
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
         self.assertEqual(len(rows), 2)
         
         transaction.abort() # test that the abort really aborts
         session = Session()
         query = session.query(User)
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
         self.assertEqual(len(rows), 0)
         
         session.save(User(id=1, firstname='udo', lastname='juergens'))
         session.save(User(id=2, firstname='heino', lastname='n/a'))
         session.flush()
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
         row1 = rows[0]
         d = row1.asDict()
         self.assertEqual(d, {'firstname' : 'udo', 'lastname' : 'juergens', 'id' : 1})
         
         transaction.commit()
 
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
         self.assertEqual(len(rows), 2)
         row1 = rows[0]
         d = row1.asDict()
@@ -282,7 +296,7 @@
         query = session.query(User)
         # lets just test that savepoints don't affect commits
         t = transaction.get()
-        rows = query.order_by(query.table.c.id).all()
+        rows = query.order_by(User.id).all()
 
         s1 = t.savepoint()
         session.delete(rows[1])
@@ -348,7 +362,7 @@
                 session.save(User(id=2, firstname='heino', lastname='n/a'))
                 session.flush()
 
-                rows = query.order_by(query.table.c.id).all()
+                rows = query.order_by(User.id).all()
                 self.assertEqual(len(rows), 2)
                 row1 = rows[0]
                 d = row1.asDict()
@@ -403,5 +417,5 @@
     for cls in (ZopeSQLAlchemyTests, MultipleEngineTests):
         suite.addTest(makeSuite(cls))
     suite.addTest(doctest.DocFileSuite('README.txt', optionflags=optionflags, tearDown=tearDownReadMe,
-        globs={'TEST_DSN': TEST_DSN, 'TEST_TWOPHASE': TEST_TWOPHASE}))
+        globs={'TEST_DSN': TEST_DSN, 'TEST_TWOPHASE': TEST_TWOPHASE, 'SA_0_4': SA_0_4, 'SA_0_5': SA_0_5}))
     return suite



More information about the Checkins mailing list