Repository: piskvorky/gensim
Pull request: Make LSI dispatcher CLI param for number of jobs optional
Closes #3104.

Problem statement:
lsi_dispatcher is not working from command-line when not specifying maxsize argument
#### Problem description

When running `lsi_dispatcher` from the command-line, if you don't specify the `maxsize` argument explicitly, you get an error for the missing positional argument:

```
usage: lsi_dispatcher.py [-h] maxsize
lsi_dispatcher.py: error: the following arguments are required: maxsize
```

According to the documentation, this argument should be optional.

The issue seems to be that the nargs argument to `add_argument` is missing:

```python
    parser.add_argument(
        'maxsize', type=int, help='Maximum number of jobs to be kept pre-fetched in the queue.', default=MAX_JOBS_QUEUE
    )
 ```
In order to make this argument optional, this should be:

```python
    parser.add_argument(
        'maxsize', nargs='?', type=int, help='Maximum number of jobs to be kept pre-fetched in the queue.', default=MAX_JOBS_QUEUE
    )
```

#### Steps/code/corpus to reproduce

Include full tracebacks, logs and datasets if necessary. Please keep the examples minimal ("minimal reproducible example").

If your problem is with a specific Gensim model (word2vec, lsimodel, doc2vec, fasttext, ldamodel etc), include the following:

```python
$ python3 -m gensim.models.lsi_dispatcher
usage: lsi_dispatcher.py [-h] maxsize
lsi_dispatcher.py: error: the following arguments are required: maxsize
```

#### Versions

```python
Linux-5.4.0-67-generic-x86_64-with-glibc2.2
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]
Bits 64
NumPy 1.19.4
SciPy 1.6.0
gensim 4.0.1
FAST_VERSION 1
```

Hints from issue discussion:
Thanks Rob. 

Quite possible – the distributed stuff in Gensim is not under automated testing.

Are you able to open a PR?
Sure, I can do that.
See PR #3106. I hope I did it right. :-)

Commit message: Make LSI dispatcher CLI param for number of jobs optional

Patch to review:
diff --git a/gensim/models/lsi_dispatcher.py b/gensim/models/lsi_dispatcher.py
index b593e94cd3..5899739c49 100755
--- a/gensim/models/lsi_dispatcher.py
+++ b/gensim/models/lsi_dispatcher.py
@@ -278,7 +278,11 @@ def exit(self):
     logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
     parser = argparse.ArgumentParser(description=__doc__[:-135], formatter_class=argparse.RawTextHelpFormatter)
     parser.add_argument(
-        'maxsize', type=int, help='Maximum number of jobs to be kept pre-fetched in the queue.', default=MAX_JOBS_QUEUE
+        'maxsize',
+        nargs='?',
+        type=int,
+        help='Maximum number of jobs to be kept pre-fetched in the queue.',
+        default=MAX_JOBS_QUEUE
     )
     args = parser.parse_args()
 


Code review comments:
diff_hunk: @@ -278,7 +278,11 @@ def exit(self):
     logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
     parser = argparse.ArgumentParser(description=__doc__[:-135], formatter_class=argparse.RawTextHelpFormatter)
     parser.add_argument(
-        'maxsize', type=int, help='Maximum number of jobs to be kept pre-fetched in the queue.', default=MAX_JOBS_QUEUE
+        'maxsize',
+        nargs='?',
+        type=int,
+        help='Maximum number of jobs to be kept pre-fetched in the queue.',
+        default=MAX_JOBS_QUEUE
path: gensim/models/lsi_dispatcher.py
text: @user1:
```suggestion
        default=MAX_JOBS_QUEUE,
```