Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_core
Commits
f134fe73
Commit
f134fe73
authored
8 months ago
by
Grégoire Kubler
Browse files
Options
Downloads
Patches
Plain Diff
chore : moved run_command in aidge_core/utils.py
parent
f74cfbfc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!212
Version 0.3.0
,
!116
feat/release_pip
Pipeline
#51002
canceled
8 months ago
Stage: static_analysis
Stage: build
Stage: test
Stage: coverage
Changes
2
Pipelines
17
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aidge_core/unit_tests/test_export.py
+5
-60
5 additions, 60 deletions
aidge_core/unit_tests/test_export.py
aidge_core/utils.py
+84
-3
84 additions, 3 deletions
aidge_core/utils.py
with
89 additions
and
63 deletions
aidge_core/unit_tests/test_export.py
+
5
−
60
View file @
f134fe73
...
...
@@ -8,15 +8,14 @@ http://www.eclipse.org/legal/epl-2.0.
SPDX-License-Identifier: EPL-2.0
"""
import
unittest
import
aidge_core
import
pathlib
from
aidge_core.utils
import
run_command
import
unittest
import
os
import
sys
import
subprocess
import
pathlib
import
shutil
import
queue
import
threading
import
subprocess
import
sys
def
initFiller
(
model
):
...
...
@@ -44,60 +43,6 @@ def initFiller(model):
pass
def
enqueue_output
(
stream
,
queue
):
for
line
in
iter
(
stream
.
readline
,
""
):
queue
.
put
(
line
)
stream
.
close
()
def
run_command
(
command
:
list
[
str
],
cwd
:
pathlib
.
Path
=
None
):
"""
This function has the job to run a command and return stdout and stderr that are not shown
by subprocess.check_call / call.
If the subprocess returns smthg else than 0, it will raise an error.
Arg:
command : written with the same syntax as subprocess.call
cwd : path from where the command must be called
"""
process
=
subprocess
.
Popen
(
command
,
cwd
=
cwd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
text
=
True
)
stdout_queue
=
queue
.
Queue
()
stderr_queue
=
queue
.
Queue
()
stdout_thread
=
threading
.
Thread
(
target
=
enqueue_output
,
args
=
(
process
.
stdout
,
stdout_queue
)
)
stderr_thread
=
threading
.
Thread
(
target
=
enqueue_output
,
args
=
(
process
.
stderr
,
stderr_queue
)
)
stdout_thread
.
start
()
stderr_thread
.
start
()
while
(
stdout_thread
.
is_alive
()
or
stderr_thread
.
is_alive
()
or
not
stdout_queue
.
empty
()
or
not
stderr_queue
.
empty
()
):
try
:
stdout_line
=
stdout_queue
.
get_nowait
()
yield
stdout_line
except
queue
.
Empty
:
pass
try
:
stderr_line
=
stderr_queue
.
get_nowait
()
yield
stderr_line
except
queue
.
Empty
:
pass
return_code
=
process
.
wait
()
if
return_code
!=
0
:
raise
subprocess
.
CalledProcessError
(
return_code
,
command
)
def
clean_dir
(
dir
:
pathlib
.
Path
)
->
None
:
if
not
dir
.
is_dir
():
print
(
f
"
Error : directory
{
dir
}
doesn
'
t exist. Exiting clean_dir().
"
)
...
...
This diff is collapsed.
Click to expand it.
aidge_core/utils.py
+
84
−
3
View file @
f134fe73
import
queue
import
threading
import
subprocess
import
pathlib
def
template_docstring
(
template_keyword
,
text_to_replace
):
"""
Method to template docstring
...
...
@@ -6,11 +12,86 @@ def template_docstring(template_keyword, text_to_replace):
:param text_to_replace: Text to replace your template with.
:type text_to_replace: str
"""
def
dec
(
func
):
if
"
{
"
+
template_keyword
+
"
}
"
not
in
func
.
__doc__
:
if
"
{
"
+
template_keyword
+
"
}
"
not
in
func
.
__doc__
:
raise
RuntimeError
(
f
"
The function
{
function
.
__name__
}
docstring does not contain the template keyword:
{
template_keyword
}
.
"
)
f
"
The function
{
func
.
__name__
}
docstring does not contain the template keyword:
{
template_keyword
}
.
"
)
func
.
__doc__
=
func
.
__doc__
.
replace
(
"
{
"
+
template_keyword
+
"
}
"
,
text_to_replace
)
"
{
"
+
template_keyword
+
"
}
"
,
text_to_replace
)
return
func
return
dec
def
enqueue_output
(
stream
,
queue
):
for
line
in
iter
(
stream
.
readline
,
""
):
queue
.
put
(
line
)
stream
.
close
()
def
run_command
(
command
:
list
[
str
],
cwd
:
pathlib
.
Path
=
None
):
"""
This function has the job to run a command and return stdout and stderr that are not shown
by subprocess.check_call / call.
If the subprocess returns smthg else than 0, it will raise an error.
Arg:
command : written with the same syntax as subprocess.call
cwd : path from where the command must be called
Call example:
```python
try:
for std_line in run_command(
[
"
cmake
"
,
str(self.EXPORT_PATH.absolute()),
"
-DPYBIND=1
"
,
f
"
-DCMAKE_INSTALL_PREFIX:PATH={install_path}
"
,
],
cwd=str(self.BUILD_DIR),
):
print(std_line, end=
""
)
except subprocess.CalledProcessError as e:
print(f
"
An error occurred: {e}
\n
Failed to configure export.
"
)
```
"""
process
=
subprocess
.
Popen
(
command
,
cwd
=
cwd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
text
=
True
)
stdout_queue
=
queue
.
Queue
()
stderr_queue
=
queue
.
Queue
()
stdout_thread
=
threading
.
Thread
(
target
=
enqueue_output
,
args
=
(
process
.
stdout
,
stdout_queue
)
)
stderr_thread
=
threading
.
Thread
(
target
=
enqueue_output
,
args
=
(
process
.
stderr
,
stderr_queue
)
)
stdout_thread
.
start
()
stderr_thread
.
start
()
while
(
stdout_thread
.
is_alive
()
or
stderr_thread
.
is_alive
()
or
not
stdout_queue
.
empty
()
or
not
stderr_queue
.
empty
()
):
try
:
stdout_line
=
stdout_queue
.
get_nowait
()
yield
stdout_line
except
queue
.
Empty
:
pass
try
:
stderr_line
=
stderr_queue
.
get_nowait
()
yield
stderr_line
except
queue
.
Empty
:
pass
return_code
=
process
.
wait
()
if
return_code
!=
0
:
raise
subprocess
.
CalledProcessError
(
return_code
,
command
)
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