mortar 0.13.5 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -197,4 +197,18 @@ class Mortar::Command::Local < Mortar::Command::Base
197
197
  ctrl.validate(script, pig_version, pig_parameters)
198
198
  end
199
199
 
200
+
201
+ # local:repl
202
+ #
203
+ # Start a local Pig REPL session
204
+ # -p, --parameter NAME=VALUE # Set a pig parameter value in your script.
205
+ # -f, --param-file PARAMFILE # Load pig parameter values from a file.
206
+ # -g, --pigversion PIG_VERSION # Set pig version. Options are <PIG_VERSION_OPTIONS>.
207
+ #
208
+ def repl
209
+ validate_arguments!
210
+ ctrl = Mortar::Local::Controller.new
211
+ ctrl.repl(pig_version, pig_parameters)
212
+ end
213
+
200
214
  end
@@ -17,13 +17,16 @@
17
17
  # used under an MIT license (https://github.com/heroku/heroku/blob/master/LICENSE).
18
18
  #
19
19
 
20
+
20
21
  require "mortar/command/base"
21
22
  require "mortar/version"
23
+ require "mortar/helpers"
24
+ require "open3"
22
25
 
23
26
  # display version
24
27
  #
25
28
  class Mortar::Command::Version < Mortar::Command::Base
26
-
29
+ include Mortar::Helpers
27
30
  # version
28
31
  #
29
32
  # show mortar client version
@@ -34,4 +37,36 @@ class Mortar::Command::Version < Mortar::Command::Base
34
37
  display(Mortar::USER_AGENT)
35
38
  end
36
39
 
40
+ # upgrade [OPTIONAL_VERSION_NUMBER]
41
+ # version:upgrade [OPTIONAL_VERSION_NUMBER]
42
+ #
43
+ # Upgrade the Mortar development framework
44
+ #
45
+ # -v, --version VERSION_NUMBER # specify which version to upgrade to
46
+ def upgrade
47
+ validate_arguments!
48
+ if running_on_a_mac?
49
+ if installed_with_omnibus?
50
+ version_number = ''
51
+ if options[:version]
52
+ version_number = " -v " + options[:version]
53
+ end
54
+ shell_url = ENV.fetch("MORTAR_INSTALL", "http://install.mortardata.com")
55
+ dir = "/opt/mortar/installer"
56
+ begin
57
+ cmd = "sudo curl -sS -L -o #{dir}/install.sh #{shell_url} && sudo bash #{dir}/install.sh#{version_number}"
58
+ Kernel.system cmd
59
+ ensure
60
+ FileUtils.remove_entry_secure dir #removes temporaryily created directory
61
+ end
62
+ else
63
+ error("mortar upgrade is only for installations not conducted with ruby gem. Please upgrade by running 'gem install mortar'.")
64
+ end
65
+ else
66
+ error("mortar upgrade is currently only supported for OSX.")
67
+ end
68
+ end
69
+
70
+ alias_command "upgrade", "version:upgrade"
71
+
37
72
  end
@@ -49,6 +49,10 @@ module Mortar
49
49
  def test_name
50
50
  ENV['MORTAR_TEST_NAME']
51
51
  end
52
+
53
+ def installed_with_omnibus?
54
+ File.exists?('/opt/mortar/version-manifest.txt')
55
+ end
52
56
 
53
57
  def write_to_file(str_data, path, mkdir_p=true)
54
58
  if mkdir_p
@@ -194,4 +194,10 @@ EOF
194
194
  pig.validate_script(pig_script, pig_version, pig_parameters)
195
195
  end
196
196
 
197
+ def repl(pig_version, pig_parameters)
198
+ install_and_configure(pig_version)
199
+ pig = Mortar::Local::Pig.new()
200
+ pig.launch_repl(pig_version, pig_parameters)
201
+ end
202
+
197
203
  end
@@ -66,6 +66,10 @@ module Mortar
66
66
  File.expand_path("../../templates/project/gitignore", __FILE__)
67
67
  end
68
68
 
69
+ def ensure_mortar_local_directory(relative_dir)
70
+ FileUtils.mkdir_p(File.join(local_install_directory, relative_dir))
71
+ end
72
+
69
73
  # Drops a marker file for an installed package, used
70
74
  # to help determine if updates should be performed
71
75
  def note_install(subdirectory)
@@ -180,6 +180,10 @@ class Mortar::Local::Pig
180
180
  run_pig_command(" -check #{pig_script.path}", pig_version, pig_parameters)
181
181
  end
182
182
 
183
+ def launch_repl(pig_version, pig_parameters)
184
+ run_pig_command(" ", pig_version, pig_parameters)
185
+ end
186
+
183
187
 
184
188
  # run the pig script with user supplied pig parameters
185
189
  def run_script(pig_script, pig_version, pig_parameters)
@@ -22,6 +22,8 @@ class Mortar::Local::Python
22
22
  PYTHON_OSX_TGZ_NAME = "mortar-python-osx.tgz"
23
23
  PYTHON_OSX_TGZ_DEFAULT_URL_PATH = "resource/python_osx"
24
24
 
25
+ MORTAR_PYTHON_PACKAGES = ["luigi"]
26
+
25
27
  # Path to the python binary that should be used
26
28
  # for running UDFs
27
29
  @command = nil
@@ -164,11 +166,18 @@ class Mortar::Local::Python
164
166
  return ENV.fetch('PYTHON_DISTRO_URL', default_url)
165
167
  end
166
168
 
169
+ def has_valid_virtualenv?
170
+ `#{@command} -m virtualenv #{python_env_dir}`
171
+ if 0 != $?.to_i
172
+ return false
173
+ end
174
+ return true
175
+ end
176
+
167
177
  # Creates a virtualenv in a well known location and installs any packages
168
178
  # necessary for the users python udf
169
179
  def setup_project_python_environment
170
- `#{@command} -m virtualenv #{python_env_dir}`
171
- if 0 != $?.to_i
180
+ if not has_valid_virtualenv?
172
181
  return false
173
182
  end
174
183
  if should_do_requirements_install
@@ -184,6 +193,11 @@ class Mortar::Local::Python
184
193
  note_install("pythonenv")
185
194
  end
186
195
  end
196
+ if should_install_python_dependencies?
197
+ unless install_python_dependencies()
198
+ return false
199
+ end
200
+ end
187
201
  return true
188
202
  end
189
203
 
@@ -215,4 +229,62 @@ class Mortar::Local::Python
215
229
  end
216
230
  end
217
231
 
232
+ def mortar_package_url(package)
233
+ return "http://s3.amazonaws.com/mortar-pypi/#{package}/#{package}.tar.gz";
234
+ end
235
+
236
+ def update_mortar_package?(package)
237
+ return is_newer_version(mortar_package_dir(package), mortar_package_url(package))
238
+ end
239
+
240
+ def mortar_packages_dir
241
+ return "pythonenv/mortar-packages"
242
+ end
243
+
244
+ def mortar_package_dir(package)
245
+ package_dir = "#{mortar_packages_dir}/#{package}"
246
+ end
247
+
248
+ def should_install_python_dependencies?
249
+ MORTAR_PYTHON_PACKAGES.each{ |package|
250
+ if update_mortar_package? package
251
+ return true
252
+ end
253
+ }
254
+ return false
255
+ end
256
+
257
+ def install_python_dependencies
258
+ action "Installing python dependencies to #{local_install_directory_name}" do
259
+ ensure_mortar_local_directory mortar_packages_dir
260
+ MORTAR_PYTHON_PACKAGES.each{ |package_name|
261
+ unless install_mortar_python_package(package_name)
262
+ return false
263
+ end
264
+ }
265
+ end
266
+ return true
267
+ end
268
+
269
+ def pip_install package_url
270
+ pip_output = `. #{python_env_dir}/bin/activate &&
271
+ #{python_env_dir}/bin/pip install #{package_url} --use-mirrors`
272
+ if 0 != $?.to_i
273
+ File.open(pip_error_log_path, 'w') { |f|
274
+ f.write(pip_output)
275
+ }
276
+ return false
277
+ else
278
+ return true
279
+ end
280
+ end
281
+
282
+ def install_mortar_python_package(package_name)
283
+ unless pip_install mortar_package_url(package_name)
284
+ return false
285
+ end
286
+ ensure_mortar_local_directory mortar_package_dir(package_name)
287
+ note_install mortar_package_dir(package_name)
288
+ end
289
+
218
290
  end
@@ -9,7 +9,9 @@ export PIG_MAIN_CLASS=com.mortardata.hawk.HawkMain
9
9
  export PIG_OPTS="<% @pig_opts.each do |k,v| %>-D<%= k %>=<%= v %> <% end %>"
10
10
 
11
11
  # UDF paths are relative to this direectory
12
- cd <%= @project_home %>/pigscripts
12
+ if [ -d "<%= @project_home %>/pigscripts" ]; then
13
+ cd <%= @project_home %>/pigscripts
14
+ fi
13
15
 
14
16
  # Setup python environment
15
17
  source <%= @local_install_dir %>/pythonenv/bin/activate
@@ -45,7 +45,11 @@ module Mortar
45
45
  newest_version = self.get_newest_version
46
46
 
47
47
  if compare_versions(newest_version, local_version) > 0
48
- Mortar::Helpers.warning("There is a new version of the Mortar development framework available. Please run 'gem install mortar' to install the latest version.\n\n")
48
+ if installed_with_omnibus? and running_on_a_mac?
49
+ Mortar::Helpers.warning("There is a new version of the Mortar development framework available. Please run 'mortar upgrade' to install the latest version.\n\n")
50
+ else
51
+ Mortar::Helpers.warning("There is a new version of the Mortar development framework available. Please run 'gem install mortar' to install the latest version.\n\n")
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module Mortar
18
18
  # see http://semver.org/
19
- VERSION = "0.13.5"
19
+ VERSION = "0.14.0"
20
20
  end
@@ -0,0 +1,114 @@
1
+ #
2
+ # Copyright 2014 Mortar Data Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ require "spec_helper"
17
+ require "mortar/command/version"
18
+
19
+ module Mortar::Command
20
+ describe Version do
21
+
22
+ before(:each) do
23
+ stub_core
24
+
25
+ end
26
+
27
+ base_url = "http://install.mortardata.com"
28
+ base_version = "1.0"
29
+ tmp_dir_dumm = "/opt/mortar/installer"
30
+ curl_command = "sudo curl -sS -L -o #{tmp_dir_dumm}/install.sh #{base_url} && sudo bash #{tmp_dir_dumm}/install.sh"
31
+
32
+ context("version in prod") do
33
+ mortar_install_env = ENV['MORTAR_INSTALL']
34
+ before(:each) do
35
+ ENV['MORTAR_INSTALL'] = nil
36
+ end
37
+
38
+ after(:all) do
39
+ ENV['MORTAR_INSTALL'] = mortar_install_env
40
+ end
41
+ it "makes a curl request to download default version" do
42
+ mock(FileUtils).remove_entry_secure(tmp_dir_dumm)
43
+ mock(Kernel).system (curl_command)
44
+ any_instance_of(Mortar::Command::Version) do |base|
45
+ mock(base).installed_with_omnibus? {true}
46
+ mock(base).running_on_a_mac? {true}
47
+ execute("version:upgrade");
48
+ end
49
+ end
50
+
51
+ it "makes curl request for different versions when requested" do
52
+ mortar_version = "1.0"
53
+ curl_command_with_version = curl_command + " -v " + mortar_version
54
+ mock(FileUtils).remove_entry_secure(tmp_dir_dumm)
55
+ mock(FileUtils).remove_entry_secure(tmp_dir_dumm)
56
+ mock(Kernel).system( curl_command_with_version)
57
+ mock(Kernel).system( curl_command_with_version)
58
+ any_instance_of(Mortar::Command::Version) do |base|
59
+ mock(base).installed_with_omnibus? {true}
60
+ mock(base).installed_with_omnibus? {true}
61
+ mock(base).running_on_a_mac? {true}
62
+ mock(base).running_on_a_mac? {true}
63
+ execute( "upgrade -v #{mortar_version}");
64
+ execute( "version:upgrade --version #{mortar_version}");
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ context("version dev") do
71
+ dev_url = "dev_url.com"
72
+ dev_curl = "sudo curl -sS -L -o #{tmp_dir_dumm}/install.sh #{dev_url} && sudo bash #{tmp_dir_dumm}/install.sh"
73
+ before(:each) do
74
+ ENV['MORTAR_INSTALL'] = dev_url
75
+ end
76
+
77
+ it "makes a curl request to download default version on dev" do
78
+ mock(Kernel).system(dev_curl)
79
+
80
+ mock(FileUtils).remove_entry_secure(tmp_dir_dumm)
81
+ any_instance_of(Mortar::Command::Version) do |base|
82
+ mock(base).installed_with_omnibus? {true}
83
+ mock(base).running_on_a_mac? {true}
84
+ execute("upgrade");
85
+ end
86
+ end
87
+ end
88
+
89
+ context("version not Mac OSX") do
90
+ it "throws error when not on mac" do
91
+ any_instance_of(Mortar::Command::Version) do |base|
92
+ mock(base).running_on_a_mac? {false}
93
+ stderr, stdout = execute("version:upgrade");
94
+ stderr.should == <<-STDERR
95
+ ! mortar upgrade is currently only supported for OSX.
96
+ STDERR
97
+ end
98
+ end
99
+
100
+ it "throws an error when running on a mac but installed with ruby gem" do
101
+ any_instance_of(Mortar::Command::Version) do |base|
102
+ mock(base).running_on_a_mac? {true}
103
+ mock(base).installed_with_omnibus? {false}
104
+ stderr, stdout = execute("version:upgrade");
105
+ stderr.should == <<-STDERR
106
+ ! mortar upgrade is only for installations not conducted with ruby gem. Please upgrade by running 'gem install mortar'.
107
+ STDERR
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ end
114
+
@@ -64,5 +64,69 @@ module Mortar::Local
64
64
 
65
65
  end
66
66
 
67
+ context "mortar python dependencies" do
68
+ it "no install if not necessary" do
69
+ python = Mortar::Local::Python.new
70
+ stub(python).has_valid_virtualenv?.returns(true)
71
+ stub(python).should_do_requirements_install.returns(false)
72
+ mock(python).should_install_python_dependencies?.returns(false)
73
+ stub(python).install_python_dependencies { raise "Shouldn't be called" }
74
+ python.setup_project_python_environment
75
+ end
76
+ it "install if necessary" do
77
+ python = Mortar::Local::Python.new
78
+ stub(python).has_valid_virtualenv?.returns(true)
79
+ stub(python).should_do_requirements_install.returns(false)
80
+ mock(python).should_install_python_dependencies?.returns(true)
81
+ mock(python).install_python_dependencies.returns(true)
82
+ python.setup_project_python_environment
83
+ end
84
+
85
+ it "doesn't detect needing any update if all packages up to date" do
86
+ python = Mortar::Local::Python.new
87
+ stub(python).update_mortar_package?.returns(false)
88
+ expect(python.should_install_python_dependencies?).to equal(false)
89
+ end
90
+
91
+ it "detects necessary install if any packages need any update" do
92
+ python = Mortar::Local::Python.new
93
+ stub(python).update_mortar_package?.returns(true)
94
+ expect(python.should_install_python_dependencies?).to equal(true)
95
+ end
96
+
97
+ it "creates directory where install timestamps are stored" do
98
+ python = Mortar::Local::Python.new
99
+ stub(python).install_mortar_python_package.returns(true)
100
+ FakeFS do
101
+ FileUtils.mkdir_p "#{python.local_install_directory}/pythonenv"
102
+ capture_stdout do
103
+ python.install_python_dependencies
104
+ end
105
+ dir_to_be_created = "#{python.local_install_directory}/#{python.mortar_packages_dir}"
106
+ expect(File.exists?(dir_to_be_created)).to be_true
107
+ end
108
+ end
109
+
110
+ it "stops if installation failed" do
111
+ python = Mortar::Local::Python.new
112
+ stub(python).pip_install.returns(false)
113
+ stub(python).note_install { raise "Shouldn't be called" }
114
+ python.install_mortar_python_package "pip"
115
+ end
116
+
117
+ it "creates directory to store package install date" do
118
+ python = Mortar::Local::Python.new
119
+ stub(python).pip_install.returns(true)
120
+ mock(python).note_install(python.mortar_package_dir("pip"))
121
+ FakeFS do
122
+ FileUtils.mkdir_p "#{python.local_install_directory}/#{python.mortar_packages_dir}"
123
+ python.install_mortar_python_package "pip"
124
+ dir_to_be_created = "#{python.local_install_directory}/#{python.mortar_packages_dir}/pip"
125
+ expect(File.exists?(dir_to_be_created)).to be_true
126
+ end
127
+ end
128
+
129
+ end
130
+
67
131
  end
68
132
  end
@@ -87,9 +87,17 @@ module Mortar
87
87
  Mortar::VERSION = "1.0.0"
88
88
  end
89
89
  capture_stdout do
90
+ stub(Updater).installed_with_omnibus?{false}
91
+ stub(Updater).running_on_a_mac?{false}
90
92
  Updater.update_check
91
93
  end.should == "WARNING: There is a new version of the Mortar development framework available. Please run 'gem install mortar' to install the latest version.\n\n"
94
+ capture_stdout do
95
+ mock(Updater).installed_with_omnibus?{true}
96
+ mock(Updater).running_on_a_mac?{true}
97
+ Updater.update_check
98
+ end.should == "WARNING: There is a new version of the Mortar development framework available. Please run 'mortar upgrade' to install the latest version.\n\n"
99
+
92
100
  end
93
101
  end
94
102
  end
95
- end
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-04 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -302,6 +302,7 @@ files:
302
302
  - spec/mortar/command/pigscripts_spec.rb
303
303
  - spec/mortar/command/projects_spec.rb
304
304
  - spec/mortar/command/validate_spec.rb
305
+ - spec/mortar/command/version_spec.rb
305
306
  - spec/mortar/command_spec.rb
306
307
  - spec/mortar/git_spec.rb
307
308
  - spec/mortar/helpers_spec.rb
@@ -337,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
338
  version: '0'
338
339
  requirements: []
339
340
  rubyforge_project:
340
- rubygems_version: 1.8.24
341
+ rubygems_version: 1.8.23
341
342
  signing_key:
342
343
  specification_version: 3
343
344
  summary: Client library and CLI to interact with the Mortar service.