Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2191 (closed enhancement: fixed)

Opened 10 years ago

Last modified 10 years ago

Add a `__version__` attribute to tg

Reported by: pitrou Owned by: mramm
Priority: normal Milestone: 2.0b6
Component: TurboGears Version: trunk
Severity: trivial Keywords:
Cc:

Description

It is common practice to define a __version__ attribute in packaged or modules, but turbogears doesn't:

>>> import tg
>>> tg.__file__
'/usr/lib/python2.5/site-packages/TurboGears2-2.0b5.1-py2.5.egg/tg/__init__.pyc'
>>> tg.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'

Change History

comment:1 Changed 10 years ago by faide

  • Owner changed from faide to mramm
  • Type changed from defect to enhancement
  • Summary changed from Add `__version__` attribute to tg to Add a `__version__` attribute to tg

Mark?

comment:2 Changed 10 years ago by jorge.vargas

+1

comment:3 Changed 10 years ago by faide

only if version grabs the version from the egg info...

comment:4 Changed 10 years ago by pitrou

This is a code snippet I personally use:

__versioninfo__ = (0, 1, 7)

base_version = '.'.join(map(str, __versioninfo__))
full_version = base_version
try:
    import pkg_resources
except ImportError:
    pass
else:
    try:
        full_version = pkg_resources.get_distribution("hgsvn").version
    except pkg_resources.DistributionNotFound:
        pass

__version__ = full_version

(replace "hgsvn" with "TurboGears2" or something. The ImportError? dance allows the code to work even without an explicit install. You can yank it if you don't support this scenario)

comment:5 Changed 10 years ago by mramm

+1 here too

comment:6 Changed 10 years ago by mramm

  • Status changed from new to closed
  • Resolution set to fixed

We're keeping version info in tg.release.version, but I've aliased that to tg.version now.

Note: See TracTickets for help on using tickets.