-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
172 lines (139 loc) · 4.58 KB
/
Rakefile
File metadata and controls
172 lines (139 loc) · 4.58 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'yaml'
# tasks
desc 'Default: Run tests.'
task :default => :test
desc 'Run tests.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = File.join('test', ENV['subset'] || '', ENV['pattern'] || '**/*_test.rb')
t.warning = true
t.verbose = true
end
#
# admin tasks
#
def gemspec
data = File.read('constants.gemspec')
spec = nil
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
spec
end
Rake::GemPackageTask.new(gemspec) do |pkg|
pkg.need_tar = true
end
task :print_manifest do
# collect files from the gemspec, labeling
# with true or false corresponding to the
# file existing or not
files = gemspec.files.inject({}) do |files, file|
files[File.expand_path(file)] = [File.exists?(file), file]
files
end
# gather non-rdoc/pkg files for the project
# and add to the files list if they are not
# included already (marking by the absence
# of a label)
Dir.glob("**/*").each do |file|
next if file =~ /^(rdoc|pkg)/ || File.directory?(file)
path = File.expand_path(file)
files[path] = ["", file] unless files.has_key?(path)
end
# sort and output the results
files.values.sort_by {|exists, file| file }.each do |entry|
puts "%-5s : %s" % entry
end
end
desc 'Generate documentation.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'constants'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include(["README", 'MIT-LICENSE'])
rdoc.rdoc_files.include(gemspec.files.select {|file| file =~ /^lib/})
end
desc "Publish RDoc to RubyForge"
task :publish_rdoc => [:rdoc] do
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
host = "#{config["username"]}@rubyforge.org"
rsync_args = "-v -c -r"
remote_dir = "/var/www/gforge-projects/bioactive/constants"
local_dir = "rdoc"
sh %{rsync #{rsync_args} #{local_dir}/ #{host}:#{remote_dir}}
end
#
# constants tasks
#
desc "Regenerate physical constants and relationship data"
task :generate_constants do
require 'open-uri'
nist_url = "http://www.physics.nist.gov/cuu/Constants/Table/allascii.txt"
nist_data = open(nist_url)
split_regexp = /^(.+?\s\s)(\d[\de\-\s\.]*?\s\s\s*)(\d[\de\-\s\.]*?\s\s\s*)(.*)$/
split_regexp_str = nil
constants = []
declarations = []
units = []
nist_data.each_line do |line|
next if line =~ /^(\s|-)/
unless line =~ split_regexp
raise "could not match line:\n#{line}\nwith: #{split_regexp_str}"
end
if split_regexp_str == nil
split_regexp_str = "^(.{#{$1.length}})(.{#{$2.length}})(.{#{$3.length}})(.*)$"
split_regexp = Regexp.new(split_regexp_str)
redo
end
name = $1
value = $2
uncertainty = $3
unit = $4
constant = name.split(/[\s\-]/).collect do |word|
word = word.gsub(/\./, "")
word = word.gsub("/", "_")
word =~ /^[A-z\d]+$/ ? word.upcase : nil
end.compact.join("_")
if constants.include?(constant)
raise "constant name conflict: #{constant}"
end
constants << constant
type = (constant =~ /_RELATIONSHIP$/ ? units : declarations)
type << [constant, name.strip, value.gsub(/\s/, ""), uncertainty.gsub(/\s/, "").gsub("(exact)", "0"), unit.strip]
end
puts "# Constants from: #{nist_url}"
puts "# Date: #{Time.now.to_s}"
max = declarations.inject(0) {|max, c| c.first.length > max ? c.first.length : max}
declarations.each do |declaration|
puts %Q{%-#{max}s = Physical.new("%s", "%s", "%s", "%s")} % declaration
end
puts
puts "# Relationships from: #{nist_url}"
puts "# Date: #{Time.now.to_s}"
require 'ruby-units'
base_units = Unit.class_eval('@@BASE_UNITS').collect {|u| u[1..-2] }
unit_map = Unit.class_eval('@@UNIT_MAP')
units = units.collect do |constant, name, value, uncertainty, unit|
# parse the relationship units
unit_name, relation_name = name.strip.chomp('relationship').split('-', 2).collect do |str|
str.strip!
case str
when 'atomic mass unit' then 'amu'
else str.gsub(/\s/, "-")
end
end
# format constants to sort in the correct declaration order
constant = constant.chomp('_RELATIONSHIP')
[constant, unit_name, relation_name, value, unit, uncertainty]
end
max = units.inject(0) {|max, c| c.first.length > max ? c.first.length : max}
units.each do |declaration|
puts %Q{%-#{max}s = ['%s', '%s', '%s', '%s', '%s']} % declaration
end
end
# desc "Regenerate elements data"
# task :generate_elements do
#
# end