File: Rakefile

package info (click to toggle)
tvdb-api 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 224 kB
  • sloc: python: 2,168; makefile: 12
file content (103 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'fileutils'

task :default => [:clean]

task :clean do
  [".", "tests"].each do |cd|
    puts "Cleaning directory #{cd}"
    Dir.new(cd).each do |t|
      if t =~ /.*\.pyc$/
        puts "Removing #{File.join(cd, t)}"
        File.delete(File.join(cd, t))
      end
    end
  end
end

desc "Upversion files"
task :upversion do
  puts "Upversioning"

  Dir.glob("*.py").each do |filename|
    f = File.new(filename, File::RDWR)
    contents = f.read()

    contents.gsub!(/__version__ = ".+?"/){|m|
      cur_version = m.scan(/\d+\.\d+/)[0].to_f
      new_version = cur_version + 0.1

      puts "Current version: #{cur_version}"
      puts "New version: #{new_version}"

      new_line = "__version__ = \"#{new_version}\""

      puts "Old line: #{m}"
      puts "New line: #{new_line}"

      m = new_line
    }

    puts contents[0]

    f.truncate(0) # empty the existing file
    f.seek(0)
    f.write(contents.to_s) # write modified file
    f.close()
  end
end

desc "Upload current version to PyPi"
task :topypi => :test do
  cur_file = File.open("tvdb_api.py").read()
  tvdb_api_version = cur_file.scan(/__version__ = "(.*)"/)
  tvdb_api_version = tvdb_api_version[0][0]

  puts "Build sdist and send tvdb_api v#{tvdb_api_version} to PyPi?"
  if $stdin.gets.chomp == "y"
    puts "Sending source-dist (sdist) to PyPi"

    if system("python setup.py sdist register upload")
      puts "tvdb_api uploaded!"
    end

  else
    puts "Cancelled"
  end
end

desc "Profile by running unittests"
task :profile do
  cd "tests"
  puts "Profiling.."
  `python -m cProfile -o prof_runtest.prof runtests.py`
  puts "Converting prof to dot"
  `python gprof2dot.py -o prof_runtest.dot -f pstats prof_runtest.prof`
  puts "Generating graph"
  `~/Applications/dev/graphviz.app/Contents/macOS/dot -Tpng -o profile.png prof_runtest.dot -Gbgcolor=black`
  puts "Cleanup"
  rm "prof_runtest.dot"
  rm "prof_runtest.prof"
end

task :test do
  puts "Nosetest'ing"
  if not system("nosetests -v --with-doctest")
    raise "Test failed!"
  end

  puts "Doctesting *.py (excluding setup.py)"
  Dir.glob("*.py").select{|e| ! e.match(/setup.py/)}.each do |filename|
    if filename =~ /^setup\.py/
      skip
    end
    puts "Doctesting #{filename}"
    if not system("python", "-m", "doctest", filename)
      raise "Failed doctest"
    end
  end

  puts "Doctesting readme.md"
  if not system("python", "-m", "doctest", "readme.md")
    raise "Doctest"
  end
end