Conversation
|
I don't know if you want this updated version of https://gist.github.com/BryonLewis/ac74e93f954eba591ed76cd84c954be4 Updates:
|
|
This is probably going to go stale for a while, I'll deal with updating it later. |
2d79301 to
b797d3b
Compare
server/scripts/cli.py
Outdated
| click.echo(f'wrote attrib {output_attrs.name}') | ||
|
|
||
|
|
||
| @convert.command(name="viame2dive") |
There was a problem hiding this comment.
It might also be nice to also add a dive2viame command since the export csv serializer already exists.
| import cv2 | ||
| import numpy as np | ||
| from PIL import Image | ||
| from tqdm import tqdm |
There was a problem hiding this comment.
numpy and tqdm should probably also be added to the dev requirements.
server/scripts/cli.py
Outdated
|
|
||
| from dive_server.serializers import kwcoco, viame | ||
| from dive_utils import models | ||
| from scripts import generateLargeDataset |
There was a problem hiding this comment.
generateLargeDataset imports numpy, opencv, and tqdm and since cli.py imports generateLargeDataset, it also require those imports. This isn't an issue if the dev requirements are installed, but if the user wants to use the CLI, they would need the dev requirements.
server/setup.py
Outdated
| version="1.4.1", | ||
| zip_safe=False, | ||
| entry_points={ | ||
| "console_scripts": ["dive=scripts.cli:cli"], |
There was a problem hiding this comment.
We should probably update the README with a really brief section that the CLI exists and how to use it.
cf702e2 to
6b649c8
Compare
|
Updated changes:
|
| ): | ||
| os.mkdir(directory) | ||
|
|
||
| with click.progressbar(range(int(frames))) as bar: |
There was a problem hiding this comment.
If frames is already an integer, is there a reason to cast it again?
| tracks[track] = track_obj | ||
| json_file = f"{directory}/result_test.json" | ||
| with open(json_file, "w") as outfile: | ||
| json.dump(tracks, outfile) |
There was a problem hiding this comment.
Might be nitpicking here, but since the other cli converters use indent=4, this should also probably have that to be consistent. Also makes viewing the output json way easier for anyone who uses it.
There was a problem hiding this comment.
should probably remove from both, it adds a lot of bytes to the file
There was a problem hiding this comment.
Agreed, it's probably better to have all json outputs be 1 line and compressed so people's text editors don't crash when opening massive files.
server/setup.py
Outdated
| "numpy", | ||
| "opencv-python", | ||
| "pytest", | ||
| "pytest-cov", |
There was a problem hiding this comment.
Is there a reason to add pytest-cov to the dev requirements? It doesn't seem to be used anywhere and if it is needed, tox can just automatically install it.
server/setup.py
Outdated
| include_package_data=True, | ||
| zip_safe=False, | ||
| entry_points={ | ||
| "console_scripts": ["dive=scripts.cli_dev:cli"], |
There was a problem hiding this comment.
This is using the dev cli. We should probably have two entry points for console scripts (one for standard and one for dev) like this:
"console_scripts": ["dive=scripts.cli:cli", "dive-dev=scripts.cli_dev:cli"],There was a problem hiding this comment.
There's no reason to expose both, IMO. The dev cli includes everything. The limited CLI is just so pyinstaller doesn't bundle numpy
There was a problem hiding this comment.
Got it. In that case, we should probably specify somewhere that the cli requires dev requirements.
server/tox.ini
Outdated
|
|
||
| [testenv:buildcli] | ||
| extra = | ||
| dev |
There was a problem hiding this comment.
If we're packaging the non-dev cli, there's no reason to include the dev requirements. This also brings the question if you should be able to build just one or both the dev and non-dev. tox can probably have a switch flag to choose. Alternatively, we can have two different tox options (buildcli and buildcli_dev).
There was a problem hiding this comment.
Should only be able to build the non-dev
There was a problem hiding this comment.
Got it. Then you can just remove the
extra =
devThis won't make a difference in the pyinstaller output, but by doing this tox won't need to install numpy and opencv just to setup the environment (which isn't needed for creating the non-dev cli). No effect on functionality, but will save some time.
server/tox.ini
Outdated
| deps = | ||
| pyinstaller | ||
| commands = | ||
| pyinstaller --onefile scripts/cli.py |
There was a problem hiding this comment.
This doesn't seem to work correctly since the generated output file doesn't have any options other than --help and --version. I'm not sure if this still WIP or actually has a bug. I'm suspecting it might be something to do with the cli.py file not importing stuff correctly for pyinstaller to use in click.
Also be sure to add {posargs} at the end so additional optional flags can be passed.
There was a problem hiding this comment.
Had to blow away my tox env to reproduce. rm -rf .tox && tox -e buildcli && ./dist/cli . Something I had before was making this work.
server/scripts/cli.py
Outdated
| pass | ||
|
|
||
|
|
||
| import scripts.commands # noqa: E402 F401 |
There was a problem hiding this comment.
This is kind of hacky to import all the click commands and rely on the import registering all the click commands. There are much better ways to separate out the commands and cli files.
The top answer in this stackoverflow post is pretty good:
https://stackoverflow.com/questions/34643620/how-can-i-split-my-click-commands-each-with-a-set-of-sub-commands-into-multipl
But I'd recommend doing something similar to what girder is doing:
https://github.com/girder/girder/tree/master/girder/cli
This also might be the reason why the pyinstaller build doesn't work.
|
This is great. I was emphasizing the tox -e buildcli -- --distpath path/to/output --clean --log-level DEBUGEverything else seems to work great. I ran some tests and validation, conversion, and data generation all work perfectly. Just a few minor points
|
|
Update on the @click.group()
@click.version_option(package_name='dive_server')
def cli():
passIf you don't want the version number being displayed at all, add the message parameter. Source: https://github.com/girder/girder/blob/master/girder/cli/__init__.py @click.group()
@click.version_option(package_name='dive_server', message='%(package)s')
def cli():
pass |
|
@f4str I addressed those comments.
|
f4str
left a comment
There was a problem hiding this comment.
Looks great! Tested it out (including --version) and everything runs without issue).
|
@BryonLewis would you like to review again? |
Uh oh!
There was an error while loading. Please reload this page.