Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EO Time Series Viewer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
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
Benjamin Jakimow
EO Time Series Viewer
Commits
0f73e89e
Commit
0f73e89e
authored
11 years ago
by
Luke Campagnola
Browse files
Options
Downloads
Patches
Plain Diff
make setup.py more robust to possible errors during version string modification
parent
09e0bf73
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
setup.py
+56
-39
56 additions, 39 deletions
setup.py
with
56 additions
and
39 deletions
setup.py
+
56
−
39
View file @
0f73e89e
from
distutils.core
import
setup
import
distutils.dir_util
import
os
,
re
import
os
,
sys
,
re
from
subprocess
import
check_output
## generate list of all sub-packages
...
...
@@ -17,48 +17,57 @@ if os.path.isdir(buildPath):
## Determine current version string
init
=
open
(
os
.
path
.
join
(
path
,
'
pyqtgraph
'
,
'
__init__.py
'
)).
read
()
initfile
=
os
.
path
.
join
(
path
,
'
pyqtgraph
'
,
'
__init__.py
'
)
init
=
open
(
initfile
).
read
()
m
=
re
.
search
(
r
'
__version__ = (\S+)\n
'
,
init
)
if
m
is
None
:
raise
Exception
(
"
Cannot determine version
number!
"
)
if
m
is
None
or
len
(
m
.
groups
())
!=
1
:
raise
Exception
(
"
Cannot determine
__
version
__ from init file:
'
%s
'
!
"
%
initfile
)
version
=
m
.
group
(
1
).
strip
(
'
\'\"
'
)
initVersion
=
version
# If this is a git checkout, append the current commit
if
os
.
path
.
isdir
(
os
.
path
.
join
(
path
,
'
.git
'
)):
def
gitCommit
(
name
):
commit
=
check_output
([
'
git
'
,
'
show
'
,
name
],
universal_newlines
=
True
).
split
(
'
\n
'
)[
0
]
assert
commit
[:
7
]
==
'
commit
'
return
commit
[
7
:]
# Find last tag matching "pyqtgraph-.*"
tagNames
=
check_output
([
'
git
'
,
'
tag
'
],
universal_newlines
=
True
).
strip
().
split
(
'
\n
'
)
while
True
:
if
len
(
tagNames
)
==
0
:
raise
Exception
(
"
Could not determine last tagged version.
"
)
lastTagName
=
tagNames
.
pop
()
if
re
.
match
(
r
'
pyqtgraph-.*
'
,
lastTagName
):
break
# If this is a git checkout, try to generate a more decriptive version string
try
:
if
os
.
path
.
isdir
(
os
.
path
.
join
(
path
,
'
.git
'
)):
def
gitCommit
(
name
):
commit
=
check_output
([
'
git
'
,
'
show
'
,
name
],
universal_newlines
=
True
).
split
(
'
\n
'
)[
0
]
assert
commit
[:
7
]
==
'
commit
'
return
commit
[
7
:]
# is this commit an unchanged checkout of the last tagged version?
lastTag
=
gitCommit
(
lastTagName
)
head
=
gitCommit
(
'
HEAD
'
)
if
head
!=
lastTag
:
branch
=
re
.
search
(
r
'
\* (.*)
'
,
check_output
([
'
git
'
,
'
branch
'
])).
group
(
1
)
version
=
version
+
"
-%s-%s
"
%
(
branch
,
head
[:
10
])
# any uncommitted modifications?
modified
=
False
status
=
check_output
([
'
git
'
,
'
status
'
,
'
-s
'
],
universal_newlines
=
True
).
strip
().
split
(
'
\n
'
)
for
line
in
status
:
if
line
[:
2
]
!=
'
??
'
:
modified
=
True
break
if
modified
:
version
=
version
+
'
+
'
# Find last tag matching "pyqtgraph-.*"
tagNames
=
check_output
([
'
git
'
,
'
tag
'
],
universal_newlines
=
True
).
strip
().
split
(
'
\n
'
)
while
True
:
if
len
(
tagNames
)
==
0
:
raise
Exception
(
"
Could not determine last tagged version.
"
)
lastTagName
=
tagNames
.
pop
()
if
re
.
match
(
r
'
pyqtgraph-.*
'
,
lastTagName
):
break
# is this commit an unchanged checkout of the last tagged version?
lastTag
=
gitCommit
(
lastTagName
)
head
=
gitCommit
(
'
HEAD
'
)
if
head
!=
lastTag
:
branch
=
re
.
search
(
r
'
\* (.*)
'
,
check_output
([
'
git
'
,
'
branch
'
])).
group
(
1
)
version
=
version
+
"
-%s-%s
"
%
(
branch
,
head
[:
10
])
# any uncommitted modifications?
modified
=
False
status
=
check_output
([
'
git
'
,
'
status
'
,
'
-s
'
],
universal_newlines
=
True
).
strip
().
split
(
'
\n
'
)
for
line
in
status
:
if
line
[:
2
]
!=
'
??
'
:
modified
=
True
break
if
modified
:
version
=
version
+
'
+
'
sys
.
stderr
.
write
(
"
Detected git commit; will use version string:
'
%s
'
\n
"
%
version
)
except
:
version
=
initVersion
sys
.
stderr
.
write
(
"
This appears to be a git checkout, but an error occurred
"
"
while attempting to determine a version string for the
"
"
current commit.
\n
Using the unmodified version string
"
"
instead:
'
%s
'
\n
"
%
version
)
sys
.
excepthook
(
*
sys
.
exc_info
())
print
(
"
PyQtGraph version:
"
+
version
)
import
distutils.command.build
...
...
@@ -73,8 +82,16 @@ class Build(distutils.command.build.build):
return
ret
initfile
=
os
.
path
.
join
(
path
,
self
.
build_lib
,
'
pyqtgraph
'
,
'
__init__.py
'
)
data
=
open
(
initfile
,
'
r
'
).
read
()
open
(
initfile
,
'
w
'
).
write
(
re
.
sub
(
r
"
__version__ = .*
"
,
"
__version__ =
'
%s
'"
%
version
,
data
))
if
not
os
.
path
.
isfile
(
initfile
):
sys
.
stderr
.
write
(
"
Warning: setup detected a git install and attempted
"
"
to generate a descriptive version string; however,
"
"
the expected build file at %s was not found.
"
"
Installation will use the original version string
"
"
%s instead.
\n
"
%
(
initfile
,
initVersion
)
)
else
:
data
=
open
(
initfile
,
'
r
'
).
read
()
open
(
initfile
,
'
w
'
).
write
(
re
.
sub
(
r
"
__version__ = .*
"
,
"
__version__ =
'
%s
'"
%
version
,
data
))
return
ret
...
...
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