summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2013-09-07 01:37:43 -0400
committerChris McDonough <chrism@plope.com>2013-09-07 01:37:43 -0400
commite5374481eee64974d083ea74a293e999bf8c4205 (patch)
tree2bfbe7e944decfc889e043e520bc98ecd0e590b9
parent90b9686a20e6465b9a97ce02e4d10080c0cf271e (diff)
parent60945d27ec06ca5c1855e7d8341d010f51153e60 (diff)
downloadpyramid-e5374481eee64974d083ea74a293e999bf8c4205.tar.gz
pyramid-e5374481eee64974d083ea74a293e999bf8c4205.tar.bz2
pyramid-e5374481eee64974d083ea74a293e999bf8c4205.zip
Merge branch 'master' of github.com:Pylons/pyramid
-rw-r--r--CHANGES.txt6
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--docs/tutorials/wiki2/authorization.rst4
-rw-r--r--docs/tutorials/wiki2/basiclayout.rst15
-rw-r--r--docs/tutorials/wiki2/definingmodels.rst2
-rw-r--r--docs/tutorials/wiki2/src/authorization/tutorial/models.py3
-rw-r--r--docs/tutorials/wiki2/src/basiclayout/tutorial/models.py4
-rw-r--r--docs/tutorials/wiki2/src/models/tutorial/models.py4
-rw-r--r--docs/tutorials/wiki2/src/tests/tutorial/models.py3
-rw-r--r--docs/tutorials/wiki2/src/views/tutorial/models.py4
-rw-r--r--pyramid/path.py6
-rw-r--r--pyramid/scaffolds/alchemy/+package+/models.py4
-rw-r--r--pyramid/tests/test_path.py16
13 files changed, 43 insertions, 30 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6392c7b3b..5c058a9c5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,12 @@
Next Release
============
+Bug Fixes
+---------
+
+- Fix an exception in ``package_name()`` when resolving the package
+ name for namespace packages.
+
Backwards Incompatibilities
---------------------------
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 0ddaebf15..1a5b975d7 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -220,3 +220,5 @@ Contributors
- Matthew Wilkes, 2013/08/23
- Takahiro Fujiwara, 2013/08/28
+
+- Doug Hellmann, 2013/09/06
diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst
index 01c301e74..2af56868c 100644
--- a/docs/tutorials/wiki2/authorization.rst
+++ b/docs/tutorials/wiki2/authorization.rst
@@ -83,7 +83,7 @@ statement at the head:
Add the following class definition:
.. literalinclude:: src/authorization/tutorial/models.py
- :lines: 36-40
+ :lines: 33-37
:linenos:
:language: python
@@ -339,7 +339,7 @@ when we're done:
.. literalinclude:: src/authorization/tutorial/models.py
:linenos:
- :emphasize-lines: 1-4,36-40
+ :emphasize-lines: 1-4,33-37
:language: python
(Only the highlighted lines need to be added.)
diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst
index 0193afab4..1f3d630c7 100644
--- a/docs/tutorials/wiki2/basiclayout.rst
+++ b/docs/tutorials/wiki2/basiclayout.rst
@@ -225,10 +225,17 @@ To give a simple example of a model class, we define one named ``MyModel``:
:linenos:
:language: py
-Our example model has an ``__init__`` method that takes two arguments
-(``name``, and ``value``). It stores these values as ``self.name`` and
-``self.value`` on the instance created by the ``__init__`` function itself.
-The ``MyModel`` class also has a ``__tablename__`` attribute. This informs
+Our example model does not require an ``__init__`` method because SQLAlchemy
+supplies for us a default constructor if one is not already present,
+which accepts keyword arguments of the same name as that of the mapped attributes.
+
+.. note:: Example usage of MyModel:
+
+ .. code-block:: python
+
+ johnny = MyModel(name="John Doe", value=10)
+
+The ``MyModel`` class has a ``__tablename__`` attribute. This informs
SQLAlchemy which table to use to store the data representing instances of this
class.
diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst
index 60427a911..e30af12b2 100644
--- a/docs/tutorials/wiki2/definingmodels.rst
+++ b/docs/tutorials/wiki2/definingmodels.rst
@@ -24,7 +24,7 @@ following:
.. literalinclude:: src/models/tutorial/models.py
:linenos:
:language: py
- :emphasize-lines: 20-22,25,27,29
+ :emphasize-lines: 20-22,25
(The highlighted lines are the ones that need to be changed.)
diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/models.py b/docs/tutorials/wiki2/src/authorization/tutorial/models.py
index 91e5a0019..4f7e1e024 100644
--- a/docs/tutorials/wiki2/src/authorization/tutorial/models.py
+++ b/docs/tutorials/wiki2/src/authorization/tutorial/models.py
@@ -29,9 +29,6 @@ class Page(Base):
name = Column(Text, unique=True)
data = Column(Text)
- def __init__(self, name, data):
- self.name = name
- self.data = data
class RootFactory(object):
__acl__ = [ (Allow, Everyone, 'view'),
diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py
index aeeb9df64..0cdd4bbc3 100644
--- a/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py
+++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py
@@ -22,7 +22,3 @@ class MyModel(Base):
id = Column(Integer, primary_key=True)
name = Column(Text, unique=True)
value = Column(Integer)
-
- def __init__(self, name, value):
- self.name = name
- self.value = value
diff --git a/docs/tutorials/wiki2/src/models/tutorial/models.py b/docs/tutorials/wiki2/src/models/tutorial/models.py
index 9a078d757..f028c917a 100644
--- a/docs/tutorials/wiki2/src/models/tutorial/models.py
+++ b/docs/tutorials/wiki2/src/models/tutorial/models.py
@@ -23,7 +23,3 @@ class Page(Base):
id = Column(Integer, primary_key=True)
name = Column(Text, unique=True)
data = Column(Text)
-
- def __init__(self, name, data):
- self.name = name
- self.data = data
diff --git a/docs/tutorials/wiki2/src/tests/tutorial/models.py b/docs/tutorials/wiki2/src/tests/tutorial/models.py
index 91e5a0019..4f7e1e024 100644
--- a/docs/tutorials/wiki2/src/tests/tutorial/models.py
+++ b/docs/tutorials/wiki2/src/tests/tutorial/models.py
@@ -29,9 +29,6 @@ class Page(Base):
name = Column(Text, unique=True)
data = Column(Text)
- def __init__(self, name, data):
- self.name = name
- self.data = data
class RootFactory(object):
__acl__ = [ (Allow, Everyone, 'view'),
diff --git a/docs/tutorials/wiki2/src/views/tutorial/models.py b/docs/tutorials/wiki2/src/views/tutorial/models.py
index 9a078d757..f028c917a 100644
--- a/docs/tutorials/wiki2/src/views/tutorial/models.py
+++ b/docs/tutorials/wiki2/src/views/tutorial/models.py
@@ -23,7 +23,3 @@ class Page(Base):
id = Column(Integer, primary_key=True)
name = Column(Text, unique=True)
data = Column(Text)
-
- def __init__(self, name, data):
- self.name = name
- self.data = data
diff --git a/pyramid/path.py b/pyramid/path.py
index eb92ea62b..470e766f8 100644
--- a/pyramid/path.py
+++ b/pyramid/path.py
@@ -33,8 +33,12 @@ def package_name(pkg_or_module):
name of the package itself."""
if pkg_or_module is None or pkg_or_module.__name__ == '__main__':
return '__main__'
- pkg_filename = pkg_or_module.__file__
pkg_name = pkg_or_module.__name__
+ pkg_filename = getattr(pkg_or_module, '__file__', None)
+ if pkg_filename is None:
+ # Namespace packages do not have __init__.py* files,
+ # and so have no __file__ attribute
+ return pkg_name
splitted = os.path.split(pkg_filename)
if splitted[-1] in init_names:
# it's a package
diff --git a/pyramid/scaffolds/alchemy/+package+/models.py b/pyramid/scaffolds/alchemy/+package+/models.py
index db1fee832..a0d3e7b71 100644
--- a/pyramid/scaffolds/alchemy/+package+/models.py
+++ b/pyramid/scaffolds/alchemy/+package+/models.py
@@ -24,8 +24,4 @@ class MyModel(Base):
name = Column(Text)
value = Column(Integer)
- def __init__(self, name, value):
- self.name = name
- self.value = value
-
Index('my_index', MyModel.name, unique=True, mysql_length=255)
diff --git a/pyramid/tests/test_path.py b/pyramid/tests/test_path.py
index a07ebeffa..fd927996a 100644
--- a/pyramid/tests/test_path.py
+++ b/pyramid/tests/test_path.py
@@ -154,6 +154,12 @@ class TestPackageName(unittest.TestCase):
package = DummyPackageOrModule(tests)
result = self._callFUT(package)
self.assertEqual(result, 'pyramid.tests')
+
+ def test_it_namespace_package(self):
+ from pyramid import tests
+ package = DummyNamespacePackage(tests)
+ result = self._callFUT(package)
+ self.assertEqual(result, 'pyramid.tests')
def test_it_module(self):
from pyramid.tests import test_path
@@ -558,3 +564,13 @@ class DummyPackageOrModule:
if self.raise_exc is not None:
raise self.raise_exc
self.__dict__[key] = val
+
+class DummyNamespacePackage:
+ """Has no __file__ attribute.
+ """
+
+ def __init__(self, real_package_or_module):
+ self.__name__ = real_package_or_module.__name__
+ import os
+ self.package_path = os.path.dirname(
+ os.path.abspath(real_package_or_module.__file__))