Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
c0e0f114
Commit
c0e0f114
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Add patchVersion function that I will use for version management
parent
c74de29c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/version.py
+47
-9
47 additions, 9 deletions
fsl/version.py
with
47 additions
and
9 deletions
fsl/version.py
+
47
−
9
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment