Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken tests. tox, travis, and py2/py3 #416

Merged
merged 9 commits into from
Nov 11, 2016
Merged

Conversation

ralphbean
Copy link
Collaborator

@ralphbean ralphbean commented Nov 9, 2016

A number of changes here. See discussion in #406 as well as #384.

This version is giving us problems.  See discussion in #406.
Our use of `six.python_2_unicode_compatible` is only available in 1.9.0
and onwards.
@ralphbean
Copy link
Collaborator Author

A couple other changes got in here. Trying to reconcile a couple different changes.

The hash seed on different python versions will produce different test
results here unless we sort explicitly.
The file format changed and if you try to load a py2 cache on py3, it
barfs.  This changes our code to use different filenames for different
python versions.
@ralphbean ralphbean changed the title Avoid installing a version of future. Fix broken tests. tox, travis, and py2/py3 Nov 9, 2016
@ralphbean
Copy link
Collaborator Author

And... they're passing again. 🍏

os.getenv('XDG_CACHE_HOME', '~/.cache') + '/dagd.dbm')
PYVER = '%i.%i' % sys.version_info[:2]
DOGPILE_CACHE_PATH = os.path.expanduser(''.join([
os.getenv('XDG_CACHE_HOME', '~/.cache'), '/dagd-py', PYVER, '.dbm']))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the cache database really incompatible between python2/python3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, yes. Will verify.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual database format is different? That doesn't make much sense to me.

Or is it just a bytes-vs-strings issue where we could just convert bytes to unicode in python3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, here's some info:

# in python2
>>> import dogpile.cache
>>> cache = dogpile.cache.make_region().configure('dogpile.cache.dbm', arguments=dict(filename='foo.db'))
>>> cache.get_or_create('key', lambda: 'value')
'value'

and then...

# in python3
>>> import dogpile.cache
>>> cache = dogpile.cache.make_region().configure('dogpile.cache.dbm', arguments=dict(filename='foo.db'))
>>> cache.get_or_create('key', lambda: 'value')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    cache.get_or_create('key', lambda: 'value')
  File "/usr/lib/python3.5/site-packages/dogpile/cache/region.py", line 825, in get_or_create
    async_creator) as value:
  File "/usr/lib/python3.5/site-packages/dogpile/lock.py", line 154, in __enter__
    return self._enter()
  File "/usr/lib/python3.5/site-packages/dogpile/lock.py", line 87, in _enter
    value = value_fn()
  File "/usr/lib/python3.5/site-packages/dogpile/cache/region.py", line 780, in get_value
    value = self.backend.get(key)
  File "/usr/lib/python3.5/site-packages/dogpile/cache/backends/file.py", line 220, in get
    with self._dbm_file(False) as dbm:
  File "/usr/lib64/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.5/site-packages/dogpile/cache/backends/file.py", line 215, in _dbm_file
    "w" if write else "r")
  File "/usr/lib64/python3.5/dbm/__init__.py", line 88, in open
    raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
# Inspecting the file created by python2
~❯ file foo.db
foo.db: Berkeley DB (Hash, version 9, native byte-order)
# inspecting the file created by python3
~❯ file foo.db
foo.db: GNU dbm 1.x or ndbm database, little endian, 64-bit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ha, the python 3 docs point to this third party lib which explains that the berkeley db interface was included in py2.3 through py2.7 but is not included in python3. I'll see if just installing it will do as a workaround.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just installing pybsddb doesn't have any effect. dogpile.cache would have to invoke it explicitly and it doesn't look like it has a flag to tell it to do so.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ha, the python 3 docs point to this third party lib which explains that the berkeley db interface was included in py2.3 through py2.7 but is not included in python3.

I think including a comment to that effect here would be sufficient. Cache incompatibility isn't a problem, it's just surprising.

@ralphbean
Copy link
Collaborator Author

Thanks @ryneeverett!

@ralphbean ralphbean merged commit 11cb4a7 into develop Nov 11, 2016
@ralphbean ralphbean deleted the feature/unhappy-future branch November 11, 2016 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants