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

Reliable detecting the Zope version #411

Closed
d-maurer opened this Issue Dec 4, 2018 · 4 comments

Comments

2 participants
@d-maurer
Copy link
Contributor

d-maurer commented Dec 4, 2018

Add-ons interacting with the ZMI need to provide different templates for Zope 2 (old style ZMI) and Zope 4 (bootstrap based ZMI). Therefore, there is a need to reliable distinguish those versions -- potentially via a mechanism analogous to Python's sys.version_info.

@d-maurer

This comment has been minimized.

Copy link
Contributor Author

d-maurer commented Dec 4, 2018

Zope 2 used to have a function getZopeVersion in App.version_txt for this purpose. This function seems to have been lost. Can it be restored?

@icemac

This comment has been minimized.

Copy link
Member

icemac commented Dec 7, 2018

Nowadays I'd use pkg_resources to get the version number like this:

import pkg_resources
zope_version = pkg_resources.get_distribution('Zope').version

Could it be a solution in your use case, too?

@icemac icemac added the question label Dec 7, 2018

@icemac icemac added this to To do in Zope 4 final release via automation Dec 7, 2018

@icemac icemac added this to the 4.0 final milestone Dec 7, 2018

@d-maurer

This comment has been minimized.

Copy link
Contributor Author

d-maurer commented Dec 7, 2018

... pkg_resources.get_distribution('Zope').version ... Could it be a solution in your use case, too?

In fact, Zope2's getZopeVersion already used this approach internally. But, it employs an impressive regular expression to extract and repackage the version information -- code I would not like to reproduce.

There is another disadvantage with your proposed solution for my current use case, i.e. making extensions working fine in both "Zope2" and "Zope 4+". For "Zope2", I must look at the distribution "Zope2"; for "Zope 4+" at the distribution "Zope". In a typical "Zope 4" setup, there is also a "Zope2" distribution but apparently there is no strict relationship between the versions of "Zope" and "Zope2" (at the moment "4.0b7" and "4.0b1", respectively). This lets it seem doubtful to always look at the "Zope2" distribution version to determine the version of "Zope 4+".

In short: determining the version via pkg_resources would be possible but nasty. Currently, I use:

try:
  from App.version_txt import getZopeVersion
  zope_major_version = getZopeVersion()[0]
except ImportError: zope_major_version = 4 # workaround for Zope 4 beta bug
@icemac

This comment has been minimized.

Copy link
Member

icemac commented Dec 7, 2018

@d-maurer I get your point. I added this issue to the list of open issues for the final release. A pull request is highly welcome.

Note to the one who will fix this issue: getZopeVersion() was removed in eb3b5a1.

d-maurer added a commit to d-maurer/Zope that referenced this issue Dec 10, 2018

Zope 4 final release automation moved this from To do to Done Jan 24, 2019

d-maurer added a commit that referenced this issue Jan 24, 2019

Add back getZopeVersion() (#412)
* fix issue #411

* rename `dict` to `version_dict`

* `getZopeVersion`: Tests and `CHANGES.txt` entry

* Update CHANGES.rst (reference syntax)

Co-Authored-By: d-maurer <d-maurer@users.noreply.github.com>

* `self._assert(isinstance(...))` --> `self.assertIsInstance`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment