Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
c0e0f114
Commit
c0e0f114
authored
Jun 06, 2017
by
Paul McCarthy
🚵
Browse files
Add patchVersion function that I will use for version management
parent
c74de29c
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/version.py
View file @
c0e0f114
...
...
@@ -5,7 +5,7 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""The primary purpose of this module is as a container for the ``fslpy``
version number. A
couple
of convenien
s
e functions for
compar
ing version
version number. A
handful
of convenien
c
e functions for
manag
ing version
numbers are also defined here.
.. autosummary::
...
...
@@ -14,10 +14,13 @@ numbers are also defined here.
__version__
parseVersionString
compareVersions
patchVersion
The ``fslpy`` version number consists of three numbers, separated by a period,
which roughly obeys the Semantic Versioning conventions (http://semver.org/):
roughly obeys the Semantic Versioning conventions (http://semver.org/), and
is compatible with PEP 440 (https://www.python.org/dev/peps/pep-0440/):
1. The major release number. This gets updated for major/external releases.
...
...
@@ -26,13 +29,19 @@ which roughly obeys the Semantic Versioning conventions (http://semver.org/):
3. The point release number. This gets updated for minor/internal releases,
which primarily involve bug-fixes and minor changes.
The sole exception to the above convention are evelopment versions, which end
in ``'.dev'``.
"""
import
string
import
os.path
as
op
import
re
import
string
__version__
=
'dev'
__version__
=
'
1.0.2.
dev'
"""Current version number, as a string. """
...
...
@@ -44,21 +53,26 @@ def parseVersionString(versionString):
An error is raised if the ``versionString`` is invalid.
"""
if
versionString
==
'dev'
:
return
9999
,
9999
,
9999
components
=
versionString
.
split
(
'.'
)
# Truncate after three elements -
# a development (unreleased0 version
# number will end with '.dev', but
# we ignore this for the purposes of
# comparison.
if
len
(
components
)
==
4
and
components
[
3
]
==
'dev'
:
components
=
components
[:
3
]
# Major, minor, and point
# version are always numeric
major
,
minor
,
point
=
[
c
for
c
in
components
]
#
E
arly versions of FSLeyes
#
But e
arly versions of FSLeyes
# used a letter at the end
# to denote a hotfix release.
# Don't break if we get one
# of these old version numbers.
point
=
point
.
strip
(
string
.
ascii_letters
)
point
=
point
.
r
strip
(
string
.
ascii_letters
)
return
[
int
(
c
)
for
c
in
[
major
,
minor
,
point
]]
...
...
@@ -91,3 +105,27 @@ def compareVersions(v1, v2, ignorePoint=False):
if
p1
<
p2
:
return
-
1
return
0
def
patchVersion
(
filename
,
newversion
):
"""Patches the given ``filename``, in place, with the given
``newversion``. Searches for a line of the form::
__version__ = '<oldversion>'
and replaces ``<oldversion>`` with ``newversion``.
"""
filename
=
op
.
abspath
(
filename
)
with
open
(
filename
,
'rt'
)
as
f
:
lines
=
f
.
readlines
()
pattern
=
re
.
compile
(
'^__version__ *= *
\'
.*
\'
*$'
)
for
i
,
line
in
enumerate
(
lines
):
if
pattern
.
match
(
line
):
lines
[
i
]
=
'__version__ =
\'
{0}
\'\n
'
.
format
(
newversion
)
break
with
open
(
filename
,
'wt'
)
as
f
:
lines
=
f
.
writelines
(
lines
)
Write
Preview
Supports
Markdown
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