I am working on a project and I developed a library and I would like to export only a subset of functions and objects of this library to a new library. Is there a way to do this algorithmically instead of just copying and pasting the desired functions and classes (with it dependences) to the new library?
To give you a little of context. I am working in a Machine Learning project, in which I have a main library which is the developer library. In this library I have lots of models and utils that are useful in the research context, but I only use a little subgroup of these models, objects and functions in production.
My question is, is there a way to define some kind of file, or something similar in which I write down which functions and and objects I want to export to a new library, so in my new library I have only the desired functions and objects and not the whole library.
For example with my main library I can:
from main_lib.models import ModelA, ModelB, ModelC...
from main_lib.utils import parse, save_data, load_data
from main_lib.images import augmentate, change_format
but in prod I only use main_lib.models.ModelB
and main_lib.parse
.
So I would like to ideally export only those two to a new lib prod_lib
from which I can also do
from prod_lib.models import ModelB...
from prod_lib.utils import parse
and here for example ModelB
uses change_format, so this magical solution should also know that ModelB
uses main_lib.images.change_format
and export it as well.
So ideally, when I think I have a new release, I just export those submodules and functions to the new lib.
One of the main motivations behind my questions is that each of this different models ModelA
, ModelB
etc sometimes have a lot of configurations files that I don't want to move to the prod environment but are needed in the dev one.
Of course I just can do it by hand, and just copy the needed methods, but duplicating code and doing things by hand probably is the worst solution. Or maybe I am thinking wrong the problem and there is another approach to organize the library which also may solve my problem.
I think that being able to export just a subgroup of functions will answer my question, but any other suggestion is very welcomed.