[英]How to make a list of the user-created python files that a module depends on?
I am interested in using doit
to automate the build process of a python package. 我对使用
doit
自动化python包的构建过程感兴趣。 If possible, I would like doit
to re-execute a task if any of the user-created source files it depends on have changed. 如果可能的话,如果它依赖于用户创建的任何源文件已更改,我希望
doit
重新执行任务。 From my understanding, the best way to accomplish this would be to use the file_dep
key and a list of the dependent source files, however I am having a lot of trouble generating this list. 据我了解,最好的方法是使用
file_dep
键和相关源文件的列表,但是在生成此列表时遇到很多麻烦。
I've tried using sys.modules
and inspect.getmembers()
, but these solutions can't deal with import statements that do not import a module, such as from x import Y
, which is unfortunately a common occurrence in the package I am developing. 我已经尝试过使用
sys.modules
和inspect.getmembers()
,但是这些解决方案无法处理不导入模块的导入语句,例如from x import Y
,不幸的是,这在我所使用的软件包中很常见发展。
Another route I investigated was to use the snakefood
tool, which initially looks like it would do exactly what I wanted, generate a list of file dependencies for every file in a given path. 我研究的另一种方法是使用
snakefood
工具,该工具最初看起来完全可以实现我想要的功能,为给定路径中的每个文件生成文件依赖关系列表。 Unfortunately, this tool seems to have limited Python 3 support, making it useless for my package. 不幸的是,该工具似乎对Python 3的支持有限,这使其对我的软件包无用。
Does anyone have any insight into how to get snakefood
-like features in Python 3, or is the only option to change all of my source code to only import modules? 是否有人对如何在Python 3中获得
snakefood
的功能有任何见识,还是将我的所有源代码更改为仅导入模块的唯一选择?
doit tutorial itself is about creating a graph of python module imports! doit 教程本身就是关于创建python模块导入图的!
It uses import_deps package, it is similar to snakefood . 它使用import_deps包,类似于snakefood 。
Note that for your use-case you will need to modify file_dep
itself during Task action's execution. 请注意,对于您的用例,您将需要在执行Task操作期间修改
file_dep
本身。 To achieve that you need to pass the task
parameter to your action (as described here ). 为了实现这一目标,您需要将传递
task
参数到你的动作(如描述在这里 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.