cnvrg 1.5.3 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c00637f5ba127ddb1859179dff0b8ea44ba64ca8102146c36e5cef9d09b9e8bb
4
- data.tar.gz: 2036a76187827395553b717c3f5c47a272a5f480141294582c231e81d49b9bad
3
+ metadata.gz: cfc351ff0936f6dd53e58da8ced925f7000c68d2e5ffa3c687d15fc090faafc1
4
+ data.tar.gz: 2e32e0decc29ef4b41a08c82c74fdf8b197c8844d1d49f98efcb81284977b967
5
5
  SHA512:
6
- metadata.gz: dba5b7970a7db3e502d0582d4d9ed6279f444c794a8c08a1a4100f696e6b9cbb69f5f448b616fe9a3f7f451bbc00ece13017002f426ac095e226993bf732a954
7
- data.tar.gz: ccf55b4c78e2f2c068618539328786faf868a7a09f55a7b32a6b902f7a5569aabac69512aa76dfd6f168c9920331c121f5f57bea39ecacaa4e8f2ee162d90406
6
+ metadata.gz: 71928a5eba809f59237be1ff75e58df1ac8b41203705278cf110b96acade3ab04c5073135a1e0eae3c58621d896d13f47fc2be9099a715be0d3e1f1c4a6e7d5f
7
+ data.tar.gz: 563db133a90bccdca1ca4eec07cf8dc7356a551647ebfd19a9936752ea65097386b8c20f429f690c75525d83a72130b14aa1c5e023961617672e1d4c1fb05ad2
@@ -1948,19 +1948,22 @@ module Cnvrg
1948
1948
  method_option :all_files, :type => :boolean, :aliases => ["--all"], :desc => "download specified commit", :default => true
1949
1949
  method_option :parallel, :type => :numeric, :aliases => ["-p", "--parallel"], :desc => "uparallel upload at the same time", :default => 15
1950
1950
  method_option :init, :type => :boolean, :aliases => ["--initial"], :desc => "initial sync", :default => false
1951
+ method_option :message, :type => :string, :aliases => ["--message"], :desc => "create commit with message", :default => nil
1951
1952
 
1952
- def sync_data_new(new_branch, force, verbose, commit, all_files, tags ,parallel, chunk_size, init)
1953
+
1954
+ def sync_data_new(new_branch, force, verbose, commit, all_files, tags ,parallel, chunk_size, init, message)
1953
1955
  verify_logged_in(true)
1954
1956
  log_start(__method__, args, options)
1955
1957
  log_message('Syncing dataset', Thor::Shell::Color::BLUE, !options["verbose"])
1958
+
1956
1959
  if !force and !init
1957
1960
  # w(verbose=false, new_branch=false,sync=false, commit=nil,all_files=true)
1958
1961
  invoke :download_data_new,[verbose, new_branch, true, commit, all_files], :new_branch=>new_branch, :direct=>false, :force =>force
1959
1962
  end
1960
1963
 
1961
1964
  # w(new_branch, verbose,sync,force, tags, chunk_size)
1962
- invoke :upload_data_new,[new_branch, verbose,true,force, tags, chunk_size], :new_branch=>new_branch,
1963
- :direct=>false, :force =>force, :sync =>true, :tags =>tags, :parallel => parallel
1965
+ invoke :upload_data_new,[new_branch, verbose, true, force, tags, chunk_size, message:message], :new_branch=>new_branch,
1966
+ :direct=>false, :force =>force, :sync =>true, :tags =>tags, :parallel => parallel, :message => message
1964
1967
 
1965
1968
  end
1966
1969
  desc 'upload_data_new', 'upload_data_new', :hide => true
@@ -1970,14 +1973,16 @@ module Cnvrg
1970
1973
  method_option :sync, :type => :boolean, :aliases => ["-s","--sync"], :default => false
1971
1974
  method_option :tags, :type => :boolean, :aliases => ["--tags"], :desc => "upload file tags", :default => false
1972
1975
  method_option :parallel, :type => :numeric, :aliases => ["-p", "--parallel"], :desc => "uparallel upload at the same time", :default => 15
1973
- def upload_data_new(new_branch, verbose,sync,force, tags, chunk_size)
1976
+ method_option :message, :type => :string, :aliases => ["--message"], :desc => "create commit with message", :default => nil
1977
+
1978
+ def upload_data_new(new_branch, verbose, sync, force, tags, chunk_size, message:nil)
1974
1979
  begin
1975
- commit = invoke :start_commit_data,[], :new_branch=> new_branch, :direct=>false, :force =>force, :chunk_size => chunk_size
1980
+ commit = invoke :start_commit_data,[], :new_branch=> new_branch, :direct=>false, :force =>force, :chunk_size => chunk_size, :message => message
1976
1981
  upload_res = invoke :upload_data_files,[commit],:new_branch=>new_branch, :verbose =>verbose, :force =>force, :sync =>sync, :chunk_size => chunk_size
1977
1982
  if upload_res < 0
1978
1983
  return
1979
1984
  end
1980
- invoke :end_commit_data,[commit, success: true, uploaded_files: upload_res] , :new_branch=>new_branch, :force =>force
1985
+ invoke :end_commit_data,[commit, success: true, uploaded_files: upload_res], :new_branch=>new_branch, :force =>force
1981
1986
  if tags
1982
1987
  log_message('Uploading Tags', Thor::Shell::Color::BLUE)
1983
1988
  dataset_dir = is_cnvrg_dir(Dir.pwd)
@@ -2017,6 +2022,7 @@ module Cnvrg
2017
2022
  method_option :direct, :type => :boolean, :aliases => ["-d", "--direct"], :desc => "was called directed", :default => true
2018
2023
  method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
2019
2024
  method_option :chunk_size, :type => :numeric, :aliases => ["-ch"], :default => 0
2025
+ method_option :message, :type => :string, :aliases => ["--message"], :desc => "create commit with message", :default => nil
2020
2026
 
2021
2027
  def start_commit_data()
2022
2028
  verify_logged_in(true)
@@ -2026,13 +2032,14 @@ module Cnvrg
2026
2032
  new_branch = options["new_branch"] || false
2027
2033
  force = options["force"] || false
2028
2034
  chunk_size = options["chunk_size"] || false
2035
+ message = options["message"]
2029
2036
  commit_sha1 = nil
2030
2037
  @dataset = Dataset.new(dataset_dir)
2031
2038
  @dataset.backup_idx
2032
2039
  @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset)
2033
2040
  next_commit = @dataset.get_next_commit #if there was a partial commit..
2034
2041
  chunks = (@dataset.list_all_files.length.to_f / chunk_size).ceil
2035
- resp = @files.start_commit(new_branch, force, chunks: chunks, dataset: @dataset)
2042
+ resp = @files.start_commit(new_branch, force, chunks: chunks, dataset: @dataset, message: message)
2036
2043
  if !resp['result']['can_commit']
2037
2044
  log_message("Cant upload files because a new version of this dataset exists, please download it or upload with --force", Thor::Shell::Color::RED)
2038
2045
  exit(1)
@@ -2516,6 +2523,73 @@ module Cnvrg
2516
2523
  end
2517
2524
  end
2518
2525
 
2526
+ desc 'commit before termination', 'Commit job code before termination'
2527
+ def commit_before_termination()
2528
+ job_type = ENV['CNVRG_JOB_TYPE']
2529
+ job_id = ENV['CNVRG_JOB_ID']
2530
+ return unless job_type.present? and job_id.present?
2531
+ invoke :sync, [false], :job_slug => job_id, :job_type => job_type, :new_branch => true, :in_exp=> true
2532
+ rescue => e
2533
+ log_error(e)
2534
+ end
2535
+
2536
+ desc 'update_job_commit', 'Update job with its last commit'
2537
+ def update_job_commit()
2538
+ job_type = ENV['CNVRG_JOB_TYPE']
2539
+ job_id = ENV['CNVRG_JOB_ID']
2540
+ return unless job_type.present? and job_id.present?
2541
+ verify_logged_in(true)
2542
+ log_start(__method__, args, options)
2543
+ project_home = get_project_home
2544
+ @project = Project.new(project_home)
2545
+ current_commit = @project.get_idx[:commit] rescue nil
2546
+ commit = @project.get_job_last_commit(job_type, job_id)
2547
+ if commit.present? and commit != current_commit
2548
+ invoke :download, [false, "", true ], :commit => commit
2549
+ end
2550
+ rescue
2551
+ end
2552
+
2553
+ desc 'update running jupyter token to server', 'update running jupyter token to server', :hide =>true
2554
+ def update_jupyter_token()
2555
+ begin
2556
+ job_type = ENV['CNVRG_JOB_TYPE']
2557
+ job_id = ENV['CNVRG_JOB_ID']
2558
+ return unless job_type.present? and job_id.present?
2559
+ verify_logged_in(true)
2560
+ log_start(__method__, args, options)
2561
+ count = 0
2562
+ token = nil
2563
+ while count < 20
2564
+ res = `jupyter notebook list`
2565
+ match = res.match(/token=(\w+)/)
2566
+ if match.present?
2567
+ token = match[1]
2568
+ break
2569
+ end
2570
+ sleep(0.5)
2571
+ end
2572
+ if token.blank?
2573
+ log_message("Failed to find jupyter token", Thor::Shell::Color::RED)
2574
+ return
2575
+ end
2576
+ log_message("Found token #{token}", Thor::Shell::Color::BLUE)
2577
+ project_home = get_project_home
2578
+ @project = Project.new(project_home)
2579
+ puts(token)
2580
+ resp = @project.update_job_jupyter_token(job_type, job_id, token)
2581
+ if resp["status"] == 200
2582
+ log_message("Updated jupter token successfully", Thor::Shell::Color::BLUE)
2583
+ else
2584
+ log_message("Failed to update jupyter token ", Thor::Shell::Color::RED)
2585
+ end
2586
+ rescue => e
2587
+ log_error(e)
2588
+ log_message("Error while trying to get jupyter token ", Thor::Shell::Color::RED)
2589
+ return
2590
+ end
2591
+ end
2592
+
2519
2593
 
2520
2594
  desc 'download', 'Download updated files'
2521
2595
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
@@ -29,6 +29,8 @@ module Cnvrg
29
29
  method_option :sync, :type => :boolean, :aliases => ["-s","--sync"], :default => false
30
30
  method_option :tags, :type => :boolean, :aliases => ["--tags"], :desc => "upload file tags", :default => false
31
31
  method_option :chunk_size, :type => :numeric, :aliases => ["--chunk"], :desc => "upload file tags", :default => 1000
32
+ method_option :message, :type => :string, :aliases => ["--message"], :desc => "create commit with message", :default => nil
33
+
32
34
  def upload
33
35
  cli = Cnvrg::CLI.new()
34
36
  verbose = options["verbose"]
@@ -37,7 +39,8 @@ module Cnvrg
37
39
  new_branch = options["new_branch"]
38
40
  chunk_size = options["chunk_size"]
39
41
  tags = options["tags"]
40
- cli.upload_data_new(new_branch, verbose,sync,force, tags, chunk_size)
42
+ message = options["message"]
43
+ cli.upload_data_new(new_branch, verbose, sync, force, tags, chunk_size, message:message)
41
44
  end
42
45
  desc 'data sync', 'Synchronise local dataset directory with remote server'
43
46
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
@@ -49,6 +52,7 @@ module Cnvrg
49
52
  method_option :parallel, :type => :numeric, :aliases => ["-p", "--parallel"], :desc => "uparallel upload at the same time", :default => 15
50
53
  method_option :chunk_size, :type => :numeric, :aliases => ["--chunk_size"], :desc => "chunk size to communicate with the server", :default => 1000
51
54
  method_option :init, :type => :boolean, :aliases => ["--initial"], :desc => "initial upload of dataset", :default => false
55
+ method_option :message, :type => :string, :aliases => ["--message"], :desc => "create commit with message", :default => nil
52
56
 
53
57
  def sync_data_new()
54
58
  cli = Cnvrg::CLI.new()
@@ -61,7 +65,8 @@ module Cnvrg
61
65
  parallel=options["parallel"]
62
66
  chunk_size = options["chunk_size"]
63
67
  init = options["init"]
64
- cli.sync_data_new(new_branch, force, verbose,commit,all_files, tags,parallel, chunk_size, init)
68
+ message = options["message"]
69
+ cli.sync_data_new(new_branch, force, verbose, commit, all_files, tags, parallel, chunk_size, init, message)
65
70
  end
66
71
  desc 'data download', 'Download files from remote server'
67
72
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits", :default => false
@@ -854,7 +854,7 @@ module Cnvrg
854
854
  Cnvrg::CLI.is_response_success(response, true)
855
855
  return response
856
856
  end
857
- def start_commit(new_branch,force=false,delete_commit=nil, chunks: 0, dataset: @dataset)
857
+ def start_commit(new_branch,force=false,delete_commit=nil, chunks: 0, dataset: @dataset, message:nil)
858
858
  begin
859
859
  #if we are pushing with force or to branch we dont need to send current/next commit cause we want to
860
860
  # create a new commit.
@@ -862,7 +862,7 @@ module Cnvrg
862
862
  commit = idx[:commit]
863
863
  next_commit = idx[:next_commit]
864
864
  response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug, new_branch: new_branch,force:force,
865
- username: @owner,current_commit: commit, next_commit: next_commit, total_chunks: chunks})
865
+ username: @owner,current_commit: commit, next_commit: next_commit, total_chunks: chunks, message: message})
866
866
  Cnvrg::CLI.is_response_success(response, true)
867
867
  return response
868
868
  rescue => e
@@ -471,6 +471,13 @@ module Cnvrg
471
471
  return response
472
472
  end
473
473
 
474
+ def get_job_last_commit(job_type, job_id)
475
+ base_url = "users/#{self.owner}/projects/#{self.slug}/jobs/#{job_type.underscore}/#{job_id}"
476
+ resp = Cnvrg::API.request("#{base_url}/last_commit", "GET")
477
+ commit = resp["commit"]
478
+ return commit
479
+ end
480
+
474
481
  def compare_idx(new_branch, force:false, deploy: false, in_exp:false, specific_files: [], download: false)
475
482
  is_download = download
476
483
  if is_download
@@ -638,6 +645,12 @@ module Cnvrg
638
645
  @machines || []
639
646
  end
640
647
 
648
+
649
+ def update_job_jupyter_token(job_type, job_id, token)
650
+ base_url = "users/#{self.owner}/projects/#{self.slug}/jobs/#{job_type.underscore}/#{job_id}"
651
+ Cnvrg::API.request("#{base_url}/update_jupyter_token", "POST", {token: token})
652
+ end
653
+
641
654
  def check_machine(machine)
642
655
  Cnvrg::Logger.log_info("Check if #{machine} machine exists")
643
656
  machines = get_machines
@@ -1,4 +1,4 @@
1
1
  module Cnvrg
2
- VERSION = '1.5.3'
2
+ VERSION = '1.5.6'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-08-02 00:00:00.000000000 Z
13
+ date: 2019-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -432,7 +432,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
432
432
  - !ruby/object:Gem::Version
433
433
  version: '0'
434
434
  requirements: []
435
- rubygems_version: 3.0.3
435
+ rubyforge_project:
436
+ rubygems_version: 2.7.9
436
437
  signing_key:
437
438
  specification_version: 4
438
439
  summary: A CLI tool for interacting with cnvrg.io.