Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
c2b51f54
Commit
c2b51f54
authored
Feb 22, 2012
by
Kostas Papadimitriou
Browse files
Fixed version extraction from git describe
Refs #2022
parent
c40c3cf7
Changes
2
Hide whitespace changes
Inline
Side-by-side
snf-common/Changelog
View file @
c2b51f54
...
...
@@ -4,6 +4,8 @@ Changelog
0.8.0 -> dev
------------
* Fixed update_version util to handle namespaced tags (see
get_version_from_describe doctests)
* Skip entry points for python distributions names existing in
``SYNNEFO_EXCLUDE_PACKAGES`` environmental variable
* Avoid duplicate entries in list settings objects
...
...
snf-common/synnefo/util/version.py
View file @
c2b51f54
import
pkg_resources
import
os
import
pprint
import
re
def
get_dist_from_module
(
modname
):
pkgroot
=
pkg_resources
.
get_provider
(
modname
).
egg_root
...
...
@@ -38,7 +39,13 @@ def get_component_version(modname):
def
vcs_info
():
"""
Return current git HEAD commit information
Return current git HEAD commit information.
Returns a tuple containing
- branch name
- commit id
- commit index
- git describe output
"""
import
subprocess
callgit
=
lambda
(
cmd
):
subprocess
.
Popen
(
...
...
@@ -54,22 +61,36 @@ def vcs_info():
return
branch
,
revid
,
revno
,
desc
def
vcs
_version
(
):
def
get
_version
_from_describe
(
describe
):
"""
Package version based on `git describe`
, c
ompatible with setuptools
Package version based on `git describe`
output. C
ompatible with setuptools
version format
>>> get_version_from_describe("v0.8.0")
'0.8.0'
>>> get_version_from_describe("debian/v0.8.0")
'0.8.0'
>>> get_version_from_describe("0.8.0")
'0.8.0'
>>> get_version_from_describe("v0.8.0-34-g8f9a1bf")
'0.8.0-34-g8f9a1bf'
>>> get_version_from_describe("debian/v0.8.0-34-g8f9a1bf")
'0.8.0-34-g8f9a1bf'
"""
return
"-"
.
join
(
vcs_info
()[
3
].
lstrip
(
'v'
).
split
(
"-"
)[:
-
1
])
version
=
describe
.
split
(
"/"
)[
-
1
].
lstrip
(
'v'
)
version
=
version
.
lstrip
(
'v'
)
return
version
def
update_version
(
module
,
name
=
'version'
,
root
=
"."
):
"""
Helper util to generate/replace a version.py file containing version
information retrieved from
vcs
_version as a submodule of passed `module`
information retrieved from
get
_version
_from_describe
as a submodule of passed `module`
"""
# exit early if not in development environment
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
root
,
'..'
,
'.git'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
root
,
'..'
,
'.git'
))
and
\
not
os
.
path
.
exists
(
os
.
path
.
join
(
root
,
'.git'
)):
return
paths
=
[
root
]
+
module
.
split
(
"."
)
+
[
"%s.py"
%
name
]
...
...
@@ -78,7 +99,7 @@ def update_version(module, name='version', root="."):
__version__ = "%(version)s"
__version_info__ = __version__.split(".")
__version_vcs_info__ = %(vcs_info)s
"""
%
dict
(
version
=
vcs_version
(
),
"""
%
dict
(
version
=
get_version_from_describe
(
vcs_info
()[
3
]
),
vcs_info
=
pprint
.
PrettyPrinter
().
pformat
(
vcs_info
()))
module_file
=
file
(
module_filename
,
"w+"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment