@@ -511,6 +511,16 @@ def _merge_metadata(paths):
511
511
return metadata
512
512
513
513
514
+ def get_free_port ():
515
+ """Finds an available port on the system.
516
+ """
517
+ import socket
518
+
519
+ with socket .socket () as _socket :
520
+ _socket .bind (('localhost' , 0 ))
521
+ return _socket .getsockname ()[1 ]
522
+
523
+
514
524
@tools .command (short_help = 'View a QIIME 2 Visualization.' ,
515
525
help = "Displays a QIIME 2 Visualization until the command "
516
526
"exits. To open a QIIME 2 Visualization so it can be "
@@ -521,7 +531,10 @@ def _merge_metadata(paths):
521
531
@click .option ('--index-extension' , required = False , default = 'html' ,
522
532
help = 'The extension of the index file that should be opened. '
523
533
'[default: html]' )
524
- def view (visualization_path , index_extension ):
534
+ @click .option ('--port' , required = False , type = click .IntRange (1024 , 49151 ),
535
+ default = get_free_port (),
536
+ help = 'The port the to serve the webapp on.' )
537
+ def view (visualization_path , index_extension , port ):
525
538
# Guard headless envs from having to import anything large
526
539
import sys
527
540
@@ -575,19 +588,9 @@ def do_GET(self):
575
588
else :
576
589
super ().do_GET ()
577
590
578
- def get_free_port ():
579
- """Finds an available port on the system.
580
- """
581
- import socket
582
-
583
- with socket .socket () as _socket :
584
- _socket .bind (('localhost' , 0 ))
585
- return _socket .getsockname ()[1 ]
586
-
587
591
VENDOR_PATH = '/home/anthony/src/qiime2/q2view/vendored/'
588
592
589
593
# Start server
590
- port = get_free_port ()
591
594
server = HTTPServer (('' , port ),
592
595
lambda * _ : Handler (* _ , directory = VENDOR_PATH ))
593
596
click .echo (f'Agent started on port: { port } ' )
0 commit comments