python watchdog:文件中命令的定义

0 投票
1 回答
502 浏览
提问于 2025-04-18 17:42

我使用 grunt 和 Gruntfile.js 来监视文件并启动测试,像这样

// Gruntfile.js
module.exports = function(grunt){
    grunt.initConfig({
        watch: {
            grunt: {
                files: ['Gruntfile.js']
            },
            python: {
                files : ['./tests/*.py','./libs/*/*.py'],
                tasks: ['pythontest'],
            },
        }
    });

    grunt.registerTask('pythontest', function(){
        grunt.util.spawn({
            cmd: 'python',
            args: ['setup.py','test'],
            opts: {stdio: 'inherit'},
        });
    });

    grunt.registerTask('default', ['watch']);

};

我在寻找一个 Python 的解决方案,像 watchdog 这样的。

在定义任务和命令方面,watchdog 有没有类似于 Gruntfile.js 的文件?

1 个回答

0

对于一个单独的命令,可以使用安装在Python的watchdog模块中的watchmedo脚本命令:

watchmedo shell-command --patterns="*.py" --recursive --command='echo python setup.py test # "${watch_src_path}"'

撰写回答