|
198 | 198 | "#export\n", |
199 | 199 | "def clean_type_str(x:str):\n", |
200 | 200 | " x = str(x)\n", |
201 | | - " x = re.sub(\"(class|function|__main__\\.|\\ at.*)\", '', x)\n", |
| 201 | + " x = re.sub(\"(enum |class|function|__main__\\.|\\ at.*)\", '', x)\n", |
202 | 202 | " x = re.sub(\"(<|>|'|\\ )\", '', x) # spl characters\n", |
203 | 203 | " return x" |
204 | 204 | ] |
|
231 | 231 | " choices=None, required=None, default=None):\n", |
232 | 232 | " if type==store_true: type,action,default=None,'store_true' ,False\n", |
233 | 233 | " if type==store_false: type,action,default=None,'store_false',True\n", |
| 234 | + " if type and isinstance(type,typing.Type) and issubclass(type,enum.Enum) and not choices: choices=list(type)\n", |
234 | 235 | " store_attr()\n", |
235 | 236 | " \n", |
236 | 237 | " def set_default(self, d):\n", |
|
245 | 246 | " def kwargs(self): return {k:v for k,v in self.__dict__.items()\n", |
246 | 247 | " if v is not None and k!='opt' and k[0]!='_'}\n", |
247 | 248 | " def __repr__(self):\n", |
248 | | - " if self.help is None and self.type is None: return \"\"\n", |
249 | | - " if self.help is None and self.type is not None: return f\"{clean_type_str(self.type)}\"\n", |
250 | | - " if self.help is not None and self.type is None: return f\"<{self.help}>\"\n", |
251 | | - " if self.help is not None and self.type is not None: return f\"{clean_type_str(self.type)} <{self.help}>\"" |
| 249 | + " if not self.help and self.type is None: return \"\"\n", |
| 250 | + " if not self.help and self.type is not None: return f\"{clean_type_str(self.type)}\"\n", |
| 251 | + " if self.help and self.type is None: return f\"<{self.help}>\"\n", |
| 252 | + " if self.help and self.type is not None: return f\"{clean_type_str(self.type)} <{self.help}>\"" |
252 | 253 | ] |
253 | 254 | }, |
254 | 255 | { |
|
333 | 334 | " param = func.__annotations__.get(k, Param())\n", |
334 | 335 | " param.set_default(v.default)\n", |
335 | 336 | " p.add_argument(f\"{param.pre}{k}\", **param.kwargs)\n", |
336 | | - " p.add_argument(f\"--pdb\", help=\"Run in pdb debugger (default: False)\", action='store_true')\n", |
337 | | - " p.add_argument(f\"--xtra\", help=\"Parse for additional args (default: '')\", type=str)\n", |
| 337 | + " p.add_argument(f\"--pdb\", help=argparse.SUPPRESS, action='store_true')\n", |
| 338 | + " p.add_argument(f\"--xtra\", help=argparse.SUPPRESS, type=str)\n", |
338 | 339 | " return p" |
339 | 340 | ] |
340 | 341 | }, |
|
354 | 355 | "name": "stdout", |
355 | 356 | "output_type": "stream", |
356 | 357 | "text": [ |
357 | | - "usage: progname [-h] [--b B] [--pdb] [--xtra XTRA] required a\n", |
| 358 | + "usage: progname [-h] [--b B] [--c {aa,bb,cc}] required a\n", |
358 | 359 | "\n", |
359 | 360 | "my docs\n", |
360 | 361 | "\n", |
361 | 362 | "positional arguments:\n", |
362 | | - " required Required param\n", |
363 | | - " a param 1\n", |
| 363 | + " required Required param\n", |
| 364 | + " a param 1\n", |
364 | 365 | "\n", |
365 | 366 | "optional arguments:\n", |
366 | | - " -h, --help show this help message and exit\n", |
367 | | - " --b B param 2 (default: test)\n", |
368 | | - " --pdb Run in pdb debugger (default: False)\n", |
369 | | - " --xtra XTRA Parse for additional args (default: '')\n" |
| 367 | + " -h, --help show this help message and exit\n", |
| 368 | + " --b B param 2 (default: test)\n", |
| 369 | + " --c {aa,bb,cc} param 3 (default: aa)\n" |
370 | 370 | ] |
371 | 371 | } |
372 | 372 | ], |
373 | 373 | "source": [ |
| 374 | + "_en = str_enum('_en', 'aa','bb','cc')\n", |
374 | 375 | "def f(required:Param(\"Required param\", int),\n", |
375 | 376 | " a:Param(\"param 1\", bool_arg),\n", |
376 | | - " b:Param(\"param 2\", str)=\"test\"):\n", |
| 377 | + " b:Param(\"param 2\", str)=\"test\",\n", |
| 378 | + " c:Param(\"param 3\", en)=_en.aa):\n", |
377 | 379 | " \"my docs\"\n", |
378 | 380 | " ...\n", |
379 | 381 | "\n", |
|
512 | 514 | "Converted 01_basics.ipynb.\n", |
513 | 515 | "Converted 02_foundation.ipynb.\n", |
514 | 516 | "Converted 03_xtras.ipynb.\n", |
| 517 | + "Converted 03a_parallel.ipynb.\n", |
| 518 | + "Converted 03b_net.ipynb.\n", |
515 | 519 | "Converted 04_dispatch.ipynb.\n", |
516 | 520 | "Converted 05_transform.ipynb.\n", |
517 | 521 | "Converted 07_meta.ipynb.\n", |
|
0 commit comments