Commit 1736338b authored by Kirill Smelkov's avatar Kirill Smelkov Committed by GitHub

Deprecate ?demostorage in favour of demo://

In 2021 in 2f02bc90 (demo: URI resolver) we added support for generic
demo:// URI scheme which allows combining any two storages into a
DemoStorage. This support is more generic because e.g. previously
?demostorage was provided only by file:// and zeo:// URI schemes, with
the "changes" part there being hardcoded to in-memory MappingStorage.

Now there is no need to use ?demostorage option as we can use demo://
uniformly.

Deprecating ?demostorage in favour of dedicated DemoStorage resolver was
actually suggested several times in the past:

https://github.com/Pylons/zodburi/pull/25#issuecomment-485506959
https://github.com/Pylons/zodburi/pull/25#issuecomment-511480572
https://github.com/Pylons/zodburi/pull/25#issuecomment-622931793

/reviewed-by @stevepiercy, @tseaver
/reviewed-on https://github.com/Pylons/zodburi/pull/33
parent 4c0e3a01
...@@ -6,7 +6,7 @@ Change Log ...@@ -6,7 +6,7 @@ Change Log
2.6.1 (unreleased) 2.6.1 (unreleased)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
- Nothing changed yet. - Deprecate ``?demostorage`` in favour of ``demo:`` URI scheme.
2.6.0 (2023-05-17) 2.6.0 (2023-05-17)
......
...@@ -166,7 +166,7 @@ blobstorage_layout ...@@ -166,7 +166,7 @@ blobstorage_layout
Misc Misc
++++ ++++
demostorage demostorage (deprecated in favour of ``demo:`` URI scheme)
boolean (if true, wrap FileStorage in a DemoStorage) boolean (if true, wrap FileStorage in a DemoStorage)
Example Example
...@@ -246,7 +246,7 @@ client_label ...@@ -246,7 +246,7 @@ client_label
Misc Misc
++++ ++++
demostorage demostorage (deprecated in favour of ``demo:`` URI scheme)
boolean (if true, wrap ClientStorage in a DemoStorage) boolean (if true, wrap ClientStorage in a DemoStorage)
Connection-related Connection-related
......
from io import BytesIO from io import BytesIO
import os import os
import re import re
import warnings
from ZConfig import loadConfig from ZConfig import loadConfig
from ZConfig import loadSchemaFile from ZConfig import loadSchemaFile
...@@ -89,6 +90,8 @@ class FileStorageURIResolver(Resolver): ...@@ -89,6 +90,8 @@ class FileStorageURIResolver(Resolver):
if 'demostorage'in kw: if 'demostorage'in kw:
kw.pop('demostorage') kw.pop('demostorage')
demostorage = True demostorage = True
warnings.warn("demostorage option is deprecated, use demo:// instead",
DeprecationWarning)
blobstorage_dir = None blobstorage_dir = None
blobstorage_layout = 'automatic' blobstorage_layout = 'automatic'
...@@ -149,6 +152,8 @@ class ClientStorageURIResolver(Resolver): ...@@ -149,6 +152,8 @@ class ClientStorageURIResolver(Resolver):
kw, unused = self.interpret_kwargs(kw) kw, unused = self.interpret_kwargs(kw)
if 'demostorage' in kw: if 'demostorage' in kw:
kw.pop('demostorage') kw.pop('demostorage')
warnings.warn("demostorage option is deprecated, use demo:// instead",
DeprecationWarning)
def factory(): def factory():
return DemoStorage(base=ClientStorage(*args, **kw)) return DemoStorage(base=ClientStorage(*args, **kw))
else: else:
......
from unittest import mock from unittest import mock
import pkg_resources import pkg_resources
import unittest import unittest
import warnings
class Base: class Base:
...@@ -154,8 +155,13 @@ class TestFileStorageURIResolver(Base, unittest.TestCase): ...@@ -154,8 +155,13 @@ class TestFileStorageURIResolver(Base, unittest.TestCase):
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
resolver = self._makeOne() resolver = self._makeOne()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
factory, dbkw = resolver( factory, dbkw = resolver(
'file://%s/db.db?demostorage=true' % self.tmpdir) 'file://%s/db.db?demostorage=true' % self.tmpdir)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("demostorage option is deprecated, use demo:// instead", str(w[-1].message))
storage = factory() storage = factory()
self.assertTrue(isinstance(storage, DemoStorage)) self.assertTrue(isinstance(storage, DemoStorage))
self.assertTrue(isinstance(storage.base, FileStorage)) self.assertTrue(isinstance(storage.base, FileStorage))
...@@ -193,10 +199,15 @@ class TestFileStorageURIResolver(Base, unittest.TestCase): ...@@ -193,10 +199,15 @@ class TestFileStorageURIResolver(Base, unittest.TestCase):
BLOB_DIR = os.path.join(self.tmpdir, 'blob') BLOB_DIR = os.path.join(self.tmpdir, 'blob')
self.assertFalse(os.path.exists(DB_FILE)) self.assertFalse(os.path.exists(DB_FILE))
resolver = self._makeOne() resolver = self._makeOne()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
factory, dbkw = resolver( factory, dbkw = resolver(
'file://%s/db.db?quota=200&demostorage=true' 'file://%s/db.db?quota=200&demostorage=true'
'&blobstorage_dir=%s/blob' '&blobstorage_dir=%s/blob'
'&blobstorage_layout=bushy' % (self.tmpdir, q(self.tmpdir))) '&blobstorage_layout=bushy' % (self.tmpdir, q(self.tmpdir)))
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("demostorage option is deprecated, use demo:// instead", str(w[-1].message))
storage = factory() storage = factory()
self.assertTrue(isinstance(storage, DemoStorage)) self.assertTrue(isinstance(storage, DemoStorage))
try: try:
...@@ -340,8 +351,13 @@ class TestClientStorageURIResolver(unittest.TestCase): ...@@ -340,8 +351,13 @@ class TestClientStorageURIResolver(unittest.TestCase):
def test_invoke_factory_demostorage(self, ClientStorage): def test_invoke_factory_demostorage(self, ClientStorage):
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
resolver = self._makeOne() resolver = self._makeOne()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
factory, dbkw = resolver('zeo:///var/nosuchfile?wait=false' factory, dbkw = resolver('zeo:///var/nosuchfile?wait=false'
'&demostorage=true') '&demostorage=true')
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("demostorage option is deprecated, use demo:// instead", str(w[-1].message))
storage = factory() storage = factory()
storage.close() storage.close()
self.assertTrue(isinstance(storage, DemoStorage)) self.assertTrue(isinstance(storage, DemoStorage))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment