app_version Package¶
app_version
Package¶
-
app_version.
get_versions
(name, default_string='Please install this application with setup.py', default_tuple=(0, 0, 0), allow_ambiguous=True)[source]¶ Get string and tuple versions from installed package information
It will return
default_string
anddefault_tuple
values when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (string) – A default returning value used when the named application is not installed yet
- default_tuple (tuple) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information.
Returns: A version string and version tuple
Return type: tuple
Examples
>>> import re >>> v1, v2 = get_versions('app_version', allow_ambiguous=True) >>> isinstance(v1, str) True >>> isinstance(v2, tuple) True >>> get_versions('distribution_which_is_not_installed') ('Please install this application with setup.py', (0, 0, 0))
-
app_version.
get_tuple_version
(name, default=(0, 0, 0), allow_ambiguous=True)[source]¶ Get tuple version from installed package information for easy handling.
It will return
default
value when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (tuple) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information.
Returns: A version tuple
Return type: string
Examples
>>> v = get_tuple_version('app_version', allow_ambiguous=True) >>> len(v) >= 3 True >>> isinstance(v[0], int) True >>> isinstance(v[1], int) True >>> isinstance(v[2], int) True >>> get_tuple_version('distribution_which_is_not_installed') (0, 0, 0)
-
app_version.
get_string_version
(name, default='Please install this application with setup.py', allow_ambiguous=True)[source]¶ Get string version from installed package information.
It will return
default
value when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (string) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information. Turn this argument toFalse
ifget_string_version
report wrong version.
Returns: A version string or not found message (
default
)Return type: string
Examples
>>> import re >>> v = get_string_version('app_version', allow_ambiguous=True) >>> re.match('^\d+.\d+\.\d+', v) is not None True >>> get_string_version('distribution_which_is_not_installed') 'Please install this application with setup.py'
core
Module¶
app_version
Get version information from setup.py
via pkg_resources
.
The concept is taken from this answer
http://stackoverflow.com/a/17638236
written by Martijn Pietersp
-
app_version.core.
get_string_version
(name, default='Please install this application with setup.py', allow_ambiguous=True)[source]¶ Get string version from installed package information.
It will return
default
value when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (string) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information. Turn this argument toFalse
ifget_string_version
report wrong version.
Returns: A version string or not found message (
default
)Return type: string
Examples
>>> import re >>> v = get_string_version('app_version', allow_ambiguous=True) >>> re.match('^\d+.\d+\.\d+', v) is not None True >>> get_string_version('distribution_which_is_not_installed') 'Please install this application with setup.py'
-
app_version.core.
get_tuple_version
(name, default=(0, 0, 0), allow_ambiguous=True)[source]¶ Get tuple version from installed package information for easy handling.
It will return
default
value when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (tuple) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information.
Returns: A version tuple
Return type: string
Examples
>>> v = get_tuple_version('app_version', allow_ambiguous=True) >>> len(v) >= 3 True >>> isinstance(v[0], int) True >>> isinstance(v[1], int) True >>> isinstance(v[2], int) True >>> get_tuple_version('distribution_which_is_not_installed') (0, 0, 0)
-
app_version.core.
get_versions
(name, default_string='Please install this application with setup.py', default_tuple=(0, 0, 0), allow_ambiguous=True)[source]¶ Get string and tuple versions from installed package information
It will return
default_string
anddefault_tuple
values when the named package is not installed.Parameters: - name (string) – An application name used to install via setuptools.
- default (string) – A default returning value used when the named application is not installed yet
- default_tuple (tuple) – A default returning value used when the named application is not installed yet
- allow_ambiguous (boolean) –
True
for allowing ambiguous version information.
Returns: A version string and version tuple
Return type: tuple
Examples
>>> import re >>> v1, v2 = get_versions('app_version', allow_ambiguous=True) >>> isinstance(v1, str) True >>> isinstance(v2, tuple) True >>> get_versions('distribution_which_is_not_installed') ('Please install this application with setup.py', (0, 0, 0))