Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pip-deps
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
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
SCS
pip-deps
Commits
623e9356
Commit
623e9356
authored
6 years ago
by
Marek Chrastina
Browse files
Options
Downloads
Patches
Plain Diff
Make pylint happy
parent
d93556e8
No related branches found
Tags
Tags containing commit
1 merge request
!1
Add py script
Pipeline
#7913
passed
6 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
pipupgradedependencies/__init__.py
+3
-0
3 additions, 0 deletions
pipupgradedependencies/__init__.py
pipupgradedependencies/pipupgradedependencies.py
+76
-47
76 additions, 47 deletions
pipupgradedependencies/pipupgradedependencies.py
with
80 additions
and
48 deletions
.gitlab-ci.yml
+
1
−
1
View file @
623e9356
...
@@ -9,7 +9,7 @@ mdcheck:
...
@@ -9,7 +9,7 @@ mdcheck:
-
mdl *.md
-
mdl *.md
pylint
:
pylint
:
allow_failure
:
true
#
allow_failure: true
stage
:
test
stage
:
test
image
:
it4innovations/docker-pycheck:latest
image
:
it4innovations/docker-pycheck:latest
script
:
script
:
...
...
This diff is collapsed.
Click to expand it.
pipupgradedependencies/__init__.py
+
3
−
0
View file @
623e9356
"""
pipupgradedependencies init
"""
__import__
(
'
pkg_resources
'
).
declare_namespace
(
__name__
)
__import__
(
'
pkg_resources
'
).
declare_namespace
(
__name__
)
This diff is collapsed.
Click to expand it.
pipupgradedependencies/pipupgradedependencies.py
+
76
−
47
View file @
623e9356
"""
pipupgradedependencies
"""
import
argparse
import
argparse
import
json
import
json
import
os
import
os
...
@@ -6,69 +9,95 @@ import subprocess
...
@@ -6,69 +9,95 @@ import subprocess
import
sys
import
sys
def
find_dependencies
(
json_input
,
package
):
def
find_dependencies
(
json_input
,
package
):
"""
find package dependencies in json tree
"""
if
isinstance
(
json_input
,
dict
):
if
isinstance
(
json_input
,
dict
):
keys
=
json_input
.
keys
()
keys
=
json_input
.
keys
()
if
'
package_name
'
in
keys
and
'
required_version
'
in
keys
:
if
'
package_name
'
in
keys
and
'
required_version
'
in
keys
:
if
re
.
search
(
r
'
^%s$
'
%
package
,
json_input
[
'
package_name
'
],
re
.
IGNORECASE
):
if
re
.
search
(
r
'
^%s$
'
%
package
,
json_input
[
'
package_name
'
],
re
.
IGNORECASE
):
yield
json_input
[
'
required_version
'
]
yield
json_input
[
'
required_version
'
]
for
child_val
in
find_dependencies
(
json_input
[
'
dependencies
'
],
package
):
for
child_val
in
find_dependencies
(
json_input
[
'
dependencies
'
],
package
):
yield
child_val
yield
child_val
elif
isinstance
(
json_input
,
list
):
elif
isinstance
(
json_input
,
list
):
for
item
in
json_input
:
for
item
in
json_input
:
for
item_val
in
find_dependencies
(
item
,
package
):
for
item_val
in
find_dependencies
(
item
,
package
):
yield
item_val
yield
item_val
def
arg_parse
():
def
arg_parse
():
parser
=
argparse
.
ArgumentParser
(
description
=
"
Pipupgradedependencies upgrades all outdated packages with respect to existing dependencies.
"
)
"""
parser_args
=
parser
.
parse_args
()
argument parser
"""
parser
=
argparse
.
ArgumentParser
(
description
=
"
Pipupgradedependencies upgrades all outdated packages with respect to
\
existing dependencies.
"
)
parser
.
parse_args
()
def
main
():
def
main
():
arg_parse
()
"""
os
.
environ
[
"
PYTHONWARNINGS
"
]
=
"
ignore:DEPRECATION
"
main function
"""
try
:
arg_parse
()
subprocess
.
check_call
([
"
pip
"
,
"
install
"
,
"
--upgrade
"
,
"
pip
"
],
stderr
=
subprocess
.
STDOUT
)
os
.
environ
[
"
PYTHONWARNINGS
"
]
=
"
ignore:DEPRECATION
"
except
subprocess
.
CalledProcessError
:
sys
.
exit
(
1
)
finished_upgrades
=
[]
while
True
:
try
:
try
:
outdated_packages
=
subprocess
.
check_
output
([
"
pip
"
,
"
list
"
,
"
--outdated
"
],
stderr
=
subprocess
.
STDOUT
)
subprocess
.
check_
call
([
"
pip
"
,
"
install
"
,
"
--upgrade
"
,
"
pip
"
],
stderr
=
subprocess
.
STDOUT
)
except
subprocess
.
CalledProcessError
:
except
subprocess
.
CalledProcessError
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
outdated_packages
=
[
line
.
split
()[
0
]
for
line
in
outdated_packages
.
strip
().
split
(
"
\n
"
)[
2
:]]
try
:
finished_upgrades
=
[]
pipdeptree
=
subprocess
.
check_output
([
"
pipdeptree
"
,
"
--json-tree
"
],
stderr
=
subprocess
.
STDOUT
)
while
True
:
except
subprocess
.
CalledProcessError
:
try
:
sys
.
exit
(
1
)
outdated_packages
=
subprocess
.
check_output
(
pipdeptree
=
pipdeptree
.
strip
()
[
"
pip
"
,
"
list
"
,
"
--outdated
"
],
jsonpipdeptree
=
json
.
loads
(
pipdeptree
)
stderr
=
subprocess
.
STDOUT
)
except
subprocess
.
CalledProcessError
:
sys
.
exit
(
1
)
outdated_packages
=
[
line
.
split
()[
0
]
for
line
in
outdated_packages
.
strip
().
split
(
"
\n
"
)[
2
:]]
possible_upgrades
=
[]
try
:
for
package
in
outdated_packages
:
pipdeptree
=
subprocess
.
check_output
(
if
package
in
finished_upgrades
:
[
"
pipdeptree
"
,
"
--json-tree
"
],
continue
stderr
=
subprocess
.
STDOUT
package_dependencies
=
[
_
for
_
in
find_dependencies
(
jsonpipdeptree
,
package
)]
)
package_dependencies
=
list
(
set
(
package_dependencies
))
except
subprocess
.
CalledProcessError
:
if
len
(
filter
(
lambda
dependency
:
re
.
search
(
r
'
(^==.*|^\d.*)
'
,
dependency
),
package_dependencies
))
==
0
:
sys
.
exit
(
1
)
possible_upgrades
.
append
({
'
package
'
:
package
,
'
dependencies
'
:
[
dependency
for
dependency
in
package_dependencies
if
'
Any
'
not
in
dependency
]})
pipdeptree
=
pipdeptree
.
strip
()
jsonpipdeptree
=
json
.
loads
(
pipdeptree
)
try
:
possible_upgrades
=
[]
package
=
possible_upgrades
[
-
1
]
for
package
in
outdated_packages
:
except
IndexError
:
if
package
in
finished_upgrades
:
break
continue
finished_upgrades
.
append
(
package
[
'
package
'
])
dependencies
=
[
_
for
_
in
find_dependencies
(
jsonpipdeptree
,
package
)]
dependencies
=
list
(
set
(
dependencies
))
if
not
[
dep
for
dep
in
dependencies
if
re
.
search
(
r
'
(^==.*|^\d.*)
'
,
dep
)
is
not
None
]:
possible_upgrades
.
append
(
{
'
package
'
:
package
,
'
dependencies
'
:
[
dep
for
dep
in
dependencies
if
'
Any
'
not
in
dep
]}
)
try
:
try
:
subprocess
.
check_call
([
"
pip
"
,
"
install
"
,
"
--upgrade
"
,
"
%s%s
"
%
(
package
[
'
package
'
],
""
.
join
(
package
[
'
dependencies
'
]))],
stderr
=
subprocess
.
STDOUT
)
package
=
possible_upgrades
[
-
1
]
except
subprocess
.
CalledProcessError
:
except
IndexError
:
sys
.
exit
(
1
)
break
finished_upgrades
.
append
(
package
[
'
package
'
])
try
:
subprocess
.
check_call
(
[
"
pip
"
,
"
install
"
,
"
--upgrade
"
,
"
%s%s
"
%
(
package
[
'
package
'
],
""
.
join
(
package
[
'
dependencies
'
]))],
stderr
=
subprocess
.
STDOUT
)
except
subprocess
.
CalledProcessError
:
sys
.
exit
(
1
)
if
len
(
possible_upgrades
)
==
len
(
finished_upgrades
):
if
len
(
possible_upgrades
)
==
len
(
finished_upgrades
):
break
break
print
"
Done.
"
print
"
Done.
"
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
()
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