1

I'm trying to follow the advice here regarding version controlling a package I'm writing. For some reason the version always comes back as '5.0.6' instead of '1.0.0' as expected.

To try and get to the bottom of this I've made a simple package with the following structure / files:

\
    \VersioningExperiments\
        __init__.py
        _version.py

Where __init__.py looks like this:

from _version import __version__

and _version.py looks like this:

__version__ = '1.0.0'

When I sit at the root and run the following commands I get 5.0.6 instead of 1.0.0:

python
Python 3.5.2 |Anaconda 2.5.0 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import VersioningExperiments
>>> VersioningExperiments.__version__
'5.0.6'

If I comment out that lint from __init__.py I get:

AttributeError: module 'VersioningExperiments' has no attribute '__version__'

So where on earth is the 5.0.6 coming from?

duffymo
  • 305,152
  • 44
  • 369
  • 561
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
  • Shouldn't it be `from ._version import __version__`? – jdehesa Jun 07 '18 at 13:30
  • Yes, that was the magic trick I discovered as per my answer below. – Jon Cage Jun 08 '18 at 09:10
  • If you add that as an answer with an explanation as to _why_ it fixes it, I'll accept yours as the answer. – Jon Cage Jun 08 '18 at 09:11
  • 1
    No, you're right, your answer already solves it. I mean, for a deeper explanation one could just check [PEP 328](https://www.python.org/dev/peps/pep-0328/) or [the top SO question on the topic](https://stackoverflow.com/questions/14132789). – jdehesa Jun 08 '18 at 09:49

1 Answers1

1

Okay, just in case anyone else runs into this, I got it:

>>> import _version
>>> _version.__version__
'5.0.6'
>>> _version.__file__
'C:\\Anaconda3\\lib\\site-packages\\_version.py'

The simplest fix I could find is to alter __init__.py in Test to this:

from ._version import __version__
Jon Cage
  • 36,366
  • 38
  • 137
  • 215