Replies: 1 comment
-
To overcome this you can move the definitions of types to a separate module and import it unconditionally. pdfsimuti/types.py class MyEnum(Enum):
...
class OtherType():
...pdfsimuti/merge.py from pdfsimuti.types import MyEnum, OtherType
...main.py from pdfsimuti.types import MyEnum, OtherType
...
@app.command(help="....")
def merge(params1: MyEnum, params2: OtherType):
from pdfsimuti import merge
merge(params1, params2) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I have wrote a program called
pdfsimutithat combines the feature of several PDF utility tools into a single CLI application. This includes watermarking, merging, compressing, splitting etc. All these modules import some heavy packages which reduces responds time on my machine. I wanted to make my program fast by importing only the modules that is called.If I wanted to use a module like merge, I would go something like
python main.py merge --help. But I ran into a problem with the other imports.To add the module on typer, I have to do something like this,
so that it shows the module's short help when
python main.py --helpis called.this is where the issue starts. Each of this modules has a lot of global variables tied to imports. Despite doing encapsulations, it still isn't enough. If I do something like
python main.py merge file.pdfthen it also calls compress and watermark as well.When they are called, their entire global variables are triggered. I do not need them to be called unless they are needed.
To use lazy imports on them, I have tried this~
but I have ran into another issue. The modules uses enum choices which is present only on the modules file itself. Not only that, the merge parameters also have their own typer properties as well which isn't shown when
python main.py merge--helpgets called.Before,
After my attempt on lazy imports,
Even if I attempt something like
on the
main.py, it won't solve the case if enum choices are used as they are not available onmain.pyConclusion
I want to have my modules imported in such way that~
--helpproperties are displayed.--helpproperties are displayed in such way even if they have enum choices, they will be displayedOperating System
Windows
Operating System Details
Windows 11 Version 24H2
Typer Version
0.12.5
Python Version
python 3.13.2
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions