mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
793 stars 220 forks source link

Accessing the version number of ciscoconfparse that is installed #120

Closed gmuloc closed 6 years ago

gmuloc commented 6 years ago

Not something too bothering, I think but thought I would flag it here as it caused one of my scripts to fail.

I have a script checking that ciscoconfparse version installed on the system is above some value (1.2.39)

>>> import ciscoconfparse
>>> ciscoconfparse.version.__version__
'1.2.49'
>>> ciscoconfparse.ciscoconfparse.__version__
'1.3.20'
>>> ciscoconfparse.version.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'version'

While I can easily fix it in my code thought I would mention this here. It was introduced in https://github.com/mpenning/ciscoconfparse/commit/7caadc34daec6398182ea74d39cbf0813c53744e when the version file stopped being imported.

mpenning commented 6 years ago

Hello,

Python provides an API to get which version of a module you have installed...

>>> import pkg_resources
>>> pkg_resources.get_distribution('ciscoconfparse').version
'1.3.20'
>>>

This should work, regardless of what version of ciscoconfparse you have installed.

If you want to require a certain version number, consider using the information from this stackoverflow answer

To ensure that you have higher than ciscoconfparse version 1.2.39...

>>> import pkg_resources
>>> pkg_resources.require("ciscoconfparse>=1.2.39")

This will raise a VersionConflict error if the condition isn't met