Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LSO
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
LSO
Merge requests
!59
Add reqs_checker.py for synchronizing dependencies between requirements.txt and setup.py
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Add reqs_checker.py for synchronizing dependencies between requirements.txt and setup.py
feature/sync-requirement.txt-setup.py
into
develop
Overview
5
Commits
1
Pipelines
3
Changes
4
1 unresolved thread
Hide all comments
Closed
Mohammad Torkashvand
requested to merge
feature/sync-requirement.txt-setup.py
into
develop
1 year ago
Overview
5
Commits
1
Pipelines
3
Changes
4
1 unresolved thread
Hide all comments
Expand
0
0
Merge request reports
Compare
develop
version 4
59965018
1 year ago
version 3
59965018
1 year ago
version 2
bf95e876
1 year ago
version 1
33bb9b68
1 year ago
develop (base)
and
latest version
latest version
59965018
1 commit,
1 year ago
version 4
59965018
1 commit,
1 year ago
version 3
59965018
1 commit,
1 year ago
version 2
bf95e876
1 commit,
1 year ago
version 1
33bb9b68
1 commit,
1 year ago
4 files
+
75
−
19
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
reqs_checker.py
0 → 100644
+
54
−
0
Options
import
re
def
read_requirements_txt
(
file_path
:
str
)
->
list
[
str
]:
with
open
(
file_path
,
"
r
"
)
as
file
:
lines
=
file
.
readlines
()
def
_dev_req_index
()
->
int
:
return
next
((
i
for
i
,
line
in
enumerate
(
lines
)
if
"
# dev requirements
"
in
line
),
len
(
lines
))
dev_req_index
=
_dev_req_index
()
assert
dev_req_index
!=
len
(
lines
),
f
"
Missing # dev requirements section in
{
file_path
}
"
return
[
line
.
strip
()
for
line
in
lines
[:
_dev_req_index
()]
if
line
.
strip
()
and
not
line
.
startswith
(
"
#
"
)]
def
read_requirements_setup
(
file_path
:
str
)
->
list
[
str
]:
with
open
(
file_path
,
"
r
"
)
as
file
:
content
=
file
.
read
()
# Find and extract the install_requires section
matches
=
re
.
findall
(
r
"
install_requires=\[(.*?)\]
"
,
content
,
re
.
DOTALL
)
if
matches
:
return
re
.
findall
(
r
'"
([^
"
]+)
"'
,
matches
[
0
])
return
[]
def
compare_requirements
(
reqs
:
list
[
str
],
setup_reqs
:
list
[
str
])
->
tuple
[
set
[
str
],
set
[
str
]]:
missing_in_setup
=
set
(
reqs
)
-
set
(
setup_reqs
)
missing_in_requirements
=
set
(
setup_reqs
)
-
set
(
reqs
)
return
missing_in_setup
,
missing_in_requirements
def
main
()
->
None
:
reqs
=
read_requirements_txt
(
"
requirements.txt
"
)
setup_reqs
=
read_requirements_setup
(
"
setup.py
"
)
missing_in_setup
,
missing_in_requirements
=
compare_requirements
(
reqs
,
setup_reqs
)
if
not
missing_in_setup
and
not
missing_in_requirements
:
print
(
"
Requirements are synchronized.
"
)
# noqa: T201
else
:
if
missing_in_setup
:
print
(
"
Missing or different in setup.py:
"
,
"
,
"
.
join
(
missing_in_setup
))
# noqa: T201
if
missing_in_requirements
:
print
(
"
Missing or different in requirements.txt:
"
,
"
,
"
.
join
(
missing_in_requirements
))
# noqa: T201
exit
(
1
)
if
__name__
==
"
__main__
"
:
main
()
Loading