BstLabs / py-dynacli

DynaCLI is a cloud-friendly Python library for converting pure Python functions into Linux Shell commands.
https://bstlabs.github.io/py-dynacli/
MIT License
98 stars 5 forks source link

[BUG] Cannot use imports in package __init__ file #93

Closed asterkin closed 2 years ago

asterkin commented 2 years ago

Describe the bug I use init of feature to keep common stuf (see example in clvm redirect). When tried to import Tuple from typing got an error

To Reproduce add from typing import Tuple in any init file

Expected behavior Should work correctly and recognized it's not for all and this should be ignored

Screenshots If applicable, add screenshots to help explain your problem.

Extra info:

ShahriyarR commented 2 years ago

@asterkin Could you please clarify a bit? What is the exact issue? and also the exact error?

asterkin commented 2 years ago

"""start/stop/refresh port redirection session"""                                                        │~
from typing import Tuple                                                                                 │~
                                                                                                         │~
def _get_port_mapping(kwargs: dict) -> tuple[int, int]:                                                  │~
    for port, local_port in kwargs.items():                                                              │~
        try:                                                                                             │~
            return int(port), int(local_port)                                                            │~
        except ValueError:                                                                               │~
            pass  # not port numbers, mb something else                                                  │~
    return 8080, 8080                                                                                    │~
                                                                                                         │~
def _make_file_name(platform: str, profile: str, instance_name: str, port: int, local_port: int) -> str: │~
    return f'{platform}-{profile}-{instance_name}-{port}={local_port}'                                   │~
                                                                                                         │~
                                                                                                         │~
from .start import start                                                                                 │~
from .stop import stop                                                                                   │~
                                                                                                         │~
__all__=["start", "stop"] 
asterkin commented 2 years ago

asterkin@asterkin-ideacentre-AIO-510-23ISH ~/clvm (main)$ ./clvm -h
usage: clvm [-h] [-v] {connect,ls,redirect,web} ...

Command Line Utility to connect or redirect ports to a Cloud Virtual Machine

positional arguments:
  {connect,ls,redirect,web}
    connect             connect to a Virtual Machine
    ls                  [ERROR] failed to import ls - No module named '_ssm'
    redirect            [ERROR] failed to import redirect - 'type' object is not subscriptable
    web                 Initiate HTTP port redirection session and start either browser or GUI app

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
asterkin commented 2 years ago

Ignore the ls error, look at redirect. The init file above is from redirect package

ShahriyarR commented 2 years ago
from typing import Tuple                                                                                 │~
                                                                                                         │~
def _get_port_mapping(kwargs: dict) -> tuple[int, int]: 

I guess you use Python 3.8 and here the imported is Tuple but used one is a tuple, in 3.8 there is no tuple typing.

asterkin commented 2 years ago

It was just a typo. I indeed use 3.8