-
Notifications
You must be signed in to change notification settings - Fork 0
Headless exec #6
base: master
Are you sure you want to change the base?
Conversation
Futurize stage1 changes applied to all python files. pyrovito_utils.py left the same by futurize.
Extra "#!/usr/bin/env" line was added by futurize but makes __init__.py break flake8 statements. So removed.
Extra parenthesis were added at futurize process. Removed since unnecesary.
"# -*- coding: utf-8 -*-" line is added in order to indicate the respective file encoding.
A scripts that creates all the yarp interfaces that normal pyrovito would create, but instead of providing a visualization, it logs all the info gathered from its opened ports. This is the first step towards Headless execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also PEP-8 makes no recommendation on string quotes (relevant part of PEP-8, also note the exception to the rule), but I REALLY dislike the lack of consistency. Please turn all your strings to either use single quote ''
or dobule quotes, whatever you choose I'll add to our python code styling guide.
Please rebase this branch on master to keep the commits order organized now that stage1 branch was meged
@@ -11,4 +12,4 @@ | |||
url='http://www.arcoslab.org/', | |||
package_dir={'pyrovito': ''}, | |||
packages=['pyrovito'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only package pyrovito, not your new script. I suggest changing to the src/
directory structure:
├── COPYING
├── Makefile
├── README.md
├── setup.py
└── src
└── pyrovito
├── __init__.py
├── pyrovito_utils.py
└── scripts
├── __init__.py
├── pyrovito
└── vis_sink.py
And adjust the setup.py
accordingly
@@ -11,4 +12,4 @@ | |||
url='http://www.arcoslab.org/', | |||
package_dir={'pyrovito': ''}, | |||
packages=['pyrovito'], | |||
scripts=['pyrovito']) | |||
scripts=['pyrovito', 'vis_sink.py']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is new code I'd rather you used a console_scripts
entry points (link to docs) instead of the old scripts
way. If you follow the file struture suggestion it could be something like this:
entry_points={
'console_scripts': [
'vis_sink'='pyrovito.scripts.vis_sink:main'
' pyrovito'='pyrovito.scripts.pyrovito:main'
]
},
And move the top level instructions (the ones with no indent) to a main
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what is the point with this. What to we gain? just removing the .py at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to clarify you could remove the .py
form the script name yourself if you wanted and it is a minor detail, it is nice since *NIX shell executables by convension don't use it, but it is a minor detail.
-
console_scripts
require minimal changes to be supported, the directory structure that I suggest is just that, a suggestion. All you need to do is put the top level module instructions on a function. -
console_scripts
entry point manages a few things thatscripts
doesn't regarding operating system interoperability. You could argue that this is not important for us since we only use Debian, and you'd be right, however this is also a free software project and it might be useful for someone else and it takes little effort to support doing this the right way. Similarly, I think doing things that brings extra unsued advantages that bring no disadvantages with them is useful since we might use them or need them in the future, specially for low effort things like this one. -
console_scripts
IS right way™️ to do this.console_scripts
is the recommended way to provide executable scripts and in line with best practices regarding packaging in the python community, which we, ARCOS-Lab, internally agreed to follow, this alone should be enough argument. -
script
is actually a legacy feature. It won't probably be removed in the future so it's save to keep using, but given the chance, and in general, prefer coding using with non-legacy/recommended features unless there is a justification not to. Given the low effort for the change I don't think that using the legacyscripts
feature is justified.
Hope this clears my positions regarding this.
vis_sink.py
Outdated
|
||
from arcospyu.control.control_loop import Controlloop | ||
|
||
sys.path.append('../hand_cart') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on the file being ran form a specific directory or else this will fail...
I don't see a good instance where this is a good idea. I know a lot of our repos has things like this one but lets not copy bad methods.
Maybe passing the path to this as a commandline option?
vis_sink.py
Outdated
from arcospyu.control.control_loop import Controlloop | ||
|
||
sys.path.append('../hand_cart') | ||
sys.path.append('../config_data/lwr') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
vis_sink.py
Outdated
parser = optparse.OptionParser( | ||
'usage: %prog [options]', add_help_option=False) | ||
parser.add_option('-e', '--help', action='help') | ||
parser.add_option( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this help strings are bad. Most of them are things I could infer from the option names...
vis_sink.py
Outdated
thumb_speed = 0.0 # TODO: Calculate thumb speed | ||
self.add_log({ | ||
"id": | ||
"Hand" + side_str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ''.join()
as mentioned above.
vis_sink.py
Outdated
"Hand" + side_str, | ||
"finger": | ||
finger, | ||
"angles": ([thumb_angle] + list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lists have an extend()
method that is better suited for this task: docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require to define a new variable, just for using extend. I do not see any performance issues or formatting issues associating to adding lists. I prefer to leave it as it is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you are right I hadn't consider that, I'll remove the comments since I think it's preferable to use +
than to create single use variables.
In the general sense (when there are no single use variables) do think is preferable to use extend
vis_sink.py
Outdated
else: | ||
self.add_log({ | ||
"id": | ||
"Hand" + side_str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ''.join()
as mentioned above.
vis_sink.py
Outdated
|
||
def terminate_handler(self, signum, stack_frame): | ||
print(('Catched signal', signum)) | ||
log_file = open("log_file_" + str(time.time()), 'w') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ''.join()
as mentioned above.
vis_sink.py
Outdated
sys.exit() | ||
|
||
|
||
loop = VisSinkLoop(15.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this inside a main()
function to use the console_script
entry point
vis_sink.py
Outdated
default=False, | ||
help='arm right side') | ||
help="Enable the configuration and simulation or a right arm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here should be: simulation of a hand. Just commenting since it is easy to miss.
@arcoslab/simulator-coordinators This fixes #4
This also includes the futurization done by @liewhnic
I am adding a new script that opens the same ports as pyrovito, but instead of creeating the visualization, it logs waht it gets from the ports.