Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
PyWake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
TOPFARM
PyWake
Commits
0d85deeb
Commit
0d85deeb
authored
6 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
add functions to update version and make new release
parent
be0af2e0
No related branches found
Branches containing commit
Tags
2.0
Tags containing commit
No related merge requests found
Pipeline
#66283
canceled
4 months ago
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
new_release.py
+45
-0
45 additions, 0 deletions
new_release.py
py_wake/__init__.py
+1
-0
1 addition, 0 deletions
py_wake/__init__.py
py_wake/utils/__init__.py
+0
-0
0 additions, 0 deletions
py_wake/utils/__init__.py
py_wake/utils/git_utils.py
+50
-0
50 additions, 0 deletions
py_wake/utils/git_utils.py
with
96 additions
and
0 deletions
new_release.py
0 → 100644
+
45
−
0
View file @
0d85deeb
from
py_wake.utils
import
git_utils
from
py_wake.utils.git_utils
import
_run_git_cmd
,
git_path
MAJOR
=
0
MINOR
=
1
PATCH
=
2
def
get_tag
(
git_repo_path
=
None
):
return
_run_git_cmd
([
'
git
'
,
'
describe
'
,
'
--tags
'
,
'
--abbrev=0
'
],
git_repo_path
)
def
set_tag
(
tag
,
push
,
git_repo_path
=
None
):
_run_git_cmd
([
"
git
"
,
"
tag
"
,
tag
],
git_repo_path
)
if
push
:
_run_git_cmd
([
"
git
"
,
"
push
"
],
git_repo_path
)
_run_git_cmd
([
"
git
"
,
"
push
"
,
"
--tags
"
],
git_repo_path
)
def
new_release
(
level
=
MINOR
):
"""
Make new tagged release
"""
if
'
dirty
'
in
git_utils
.
get_git_version
(
git_path
):
raise
Exception
(
"
Commit before making new release
"
)
last_tag
=
get_tag
(
git_path
)
def
next_tag
(
tag
):
return
"
.
"
.
join
([
str
(
int
(
n
)
+
(
0
,
1
)[
i
==
level
])
for
i
,
n
in
enumerate
(
tag
.
split
(
"
.
"
)[:
2
]
+
[
0
])])
new_tag
=
next_tag
(
last_tag
)
print
(
"
Making tag:
"
,
new_tag
)
set_tag
(
new_tag
,
push
=
True
,
git_repo_path
=
git_path
)
print
(
'
Done
'
,
new_tag
)
if
__name__
==
'
__main__
'
:
import
sys
if
len
(
sys
.
argv
)
==
2
:
new_release
(
int
(
sys
.
argv
[
1
]))
else
:
new_release
()
This diff is collapsed.
Click to expand it.
py_wake/__init__.py
+
1
−
0
View file @
0d85deeb
__version__
=
'
716d65a-dirty
'
This diff is collapsed.
Click to expand it.
py_wake/utils/__init__.py
0 → 100644
+
0
−
0
View file @
0d85deeb
This diff is collapsed.
Click to expand it.
py_wake/utils/git_utils.py
0 → 100644
+
50
−
0
View file @
0d85deeb
import
os
import
subprocess
import
py_wake
git_path
=
os
.
path
.
dirname
(
py_wake
.
__file__
)
+
"
/../
"
def
_run_git_cmd
(
cmd
,
git_repo_path
=
None
):
git_repo_path
=
git_repo_path
or
os
.
getcwd
()
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
git_repo_path
,
"
.git
"
)):
raise
Warning
(
"'
%s
'
does not appear to be a Git repository.
"
%
git_repo_path
)
try
:
process
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
,
cwd
=
os
.
path
.
abspath
(
git_repo_path
))
stdout
=
process
.
communicate
()[
0
]
if
process
.
returncode
!=
0
:
raise
EnvironmentError
()
return
stdout
.
strip
()
except
EnvironmentError
as
e
:
raise
Warning
(
"
Unable to run git
\n
%s
"
%
str
(
e
))
def
get_git_version
(
git_repo_path
=
None
):
cmd
=
[
"
git
"
,
"
describe
"
,
"
--tags
"
,
"
--dirty
"
,
"
--always
"
]
return
_run_git_cmd
(
cmd
,
git_repo_path
)
def
update_git_version
(
module
,
git_repo_path
=
None
):
"""
Update <version_module>.__version__ to git version
"""
version_str
=
get_git_version
(
git_repo_path
)
assert
os
.
path
.
isfile
(
module
.
__file__
)
with
open
(
module
.
__file__
,
"
w
"
)
as
fid
:
fid
.
write
(
"
__version__ =
'
%s
'
\n
"
%
version_str
)
# ensure file is written, closed and ready
with
open
(
module
.
__file__
)
as
fid
:
fid
.
read
()
return
version_str
def
main
():
"""
Example of how to run (pytest-friendly)
"""
if
__name__
==
'
__main__
'
:
update_git_version
(
py_wake
,
git_path
)
main
()
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