Created
November 1, 2016 17:00
-
-
Save coffeemancy/9f38e812e513bcea4f4fc2a0ac8b19ac to your computer and use it in GitHub Desktop.
Using ruby to test python on file changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# REQUIREMENTS | |
# | |
# Needs ruby and the watchr gem, which can be installed | |
# globally via: | |
# | |
# sudo gem install watchr | |
# USAGE | |
# | |
# watchr watch.rb | |
dep = Gem::Dependency.new("watchr", "~>0.7.0") | |
unless dep.matching_specs.max_by(&:version) | |
puts "You need to install '#{dep}'" | |
puts "e.g. 'sudo gem install watchr'" | |
exit! | |
end | |
IGNORED_DIRS = ["./bin", "./docs"] | |
IGNORED_PATTERNS = [/__pycache__/, | |
/.egg-info/] | |
is_watched = Proc.new do |f| | |
File.directory?(f) && | |
IGNORED_DIRS.none? { |d| f.start_with?(d) } && | |
IGNORED_PATTERNS.none? { |p| p.match(f) } | |
end | |
test_dirs, code_dirs = Dir["./**/*"].select(&is_watched). | |
map { |d| d[2..-1] }. | |
partition { |d| d.start_with?("tests") } | |
puts "Watching test dirs: #{test_dirs}" | |
puts "Watching code dirs: #{code_dirs}" | |
pytest = "py.test -svv --run-slow --skip-launch --skip-tear-down" | |
test_dirs.map { |d| /#{d}\/test_.+\.py$/ }.each do |to_watch| | |
watch(to_watch) do |md| | |
system("#{pytest} #{md[0]}") | |
end | |
end | |
code_dirs.map { |d| /#{d}\/.+\.py$/ }.each do |to_watch| | |
watch(to_watch) do |md| | |
system("flake8") && system("pep257") && system(pytest) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment