pyrosome 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: a8c7f462ebcbd7ad7c2f1fbce5a6bda419e9f7d7
4
- data.tar.gz: 1285e2335b94289a86f6268850d054aef584e126
3
+ metadata.gz: cc5a6ff3c7d4e715388878be49a9bd371abc2115
4
+ data.tar.gz: bc5610d94c47f2bfe40bb55532dd757658eb9373
5
5
  SHA512:
6
- metadata.gz: 177a82d33c424b9a5cc7a4a2425088b685096c1c9cf75faf8c7f9d27f1a9a6c525b46a03456f24f2b450487f09edcb8f2a7ab30ef3a830ac9801eebff7af3474
7
- data.tar.gz: 84505ba050f17f6904e3bcd76f360898c28871e86c667b244d66b748cc34bc9fd1b55f298138fb28112974554f8902c80db016a604e302532297431760746ceb
6
+ metadata.gz: 196c87ac11f16c8837df5367693a6fc9d0671df65e9ffe02b67cd30b7a34fd5e27804413824665a76b3b714db92b83713f9e705a23fed0b8664ffcd6249396f2
7
+ data.tar.gz: 1c9cbc02a78e8bdf43d99f1334ed3335291b84b636393be0bb3e3398b9c4ec4407bd95c24a944f9924be27dab0a4a7934c4e3fd0295c72461b761ec94e97a93b
@@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.
3
3
  This file should follow the standards specified on [http://keepachangelog.com/]
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.3.0] - 11-27-2015
7
+
8
+ ### Changed
9
+
10
+ - Changed `-f`/`--format` flag to `-i`/`--input`
11
+
12
+ ### Added
13
+
14
+ - Added `-f`/`--forks` option to specify number of forks to process in parallel
15
+
6
16
  ## [0.2.0] - 11-27-2015
7
17
 
8
18
  ### Changed
data/README.md CHANGED
@@ -23,15 +23,15 @@ Install the gem:
23
23
 
24
24
  The command to execute is `psome` (pronounced `p-some`, ryhmes with `roam`). It takes a stream like this:
25
25
 
26
- cat file.csv | psome -f csv -e "puts _[0]"
26
+ cat file.csv | psome -i csv -e "puts _[0]"
27
27
 
28
28
  You can see that we specify the format that is expected and a bit of Ruby code which exects to use a `_` variable
29
29
 
30
30
  ### Arguments
31
31
 
32
- #### -f [FORMAT] / --format [FORMAT]
32
+ #### -i [FORMAT] / --input [FORMAT]
33
33
 
34
- Specify a format. `json` and `csv` currently supported
34
+ Specify a input. `json` and `csv` currently supported
35
35
 
36
36
  #### -e [CODE] / --exec [CODE]
37
37
 
@@ -41,6 +41,34 @@ Give some Ruby code to be executed. A `_` variable will be in scope and will re
41
41
 
42
42
  If the data is tabular, should we expect headers?
43
43
 
44
+ ## TODOs
45
+
46
+ By default process lines like Ruby
47
+
48
+ Parallel option
49
+ * Threads or forks
50
+ * Way to do mutex (`sync` method?)
51
+
52
+ -i to do in place replacement of files
53
+
54
+ Support file names as arguments.
55
+
56
+ Support file name for code execution instead of -e? Could files have both `_` and `ARGV` in scope so that scripts not made for pyrosome be used?
57
+
58
+ Flag to echo sample of what you would get with the specified options (do I get an array or a hash? Does the hash have keys?)
59
+
60
+ Support for colors?
61
+
62
+ Support for different enumerators? Sort_by comes to mind, but that wouldn't work for streaming (or would it?). Select/reject. Does any?/all? make sense?
63
+
64
+ Support for loading an app environment (automatically load Rails if inside a project to get models?)
65
+
66
+ Easy generation of CSV / JSON from Ruby data?
67
+
68
+ Some way to load libraries?
69
+
70
+ Refer to https://robm.me.uk/ruby/2015/10/31/dollar-underscore.html
71
+
44
72
  ## Contributing
45
73
 
46
74
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pyrosome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
data/bin/psome CHANGED
@@ -8,10 +8,10 @@ options = {}
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: example.rb [options]"
10
10
 
11
- opts.on("-f", "--format [FORMAT]", "Format of input") do |f|
12
- fail ArgumentError, "Invalid format: #{f}" unless VALID_FORMATS.include?(f.to_s)
11
+ opts.on("-i", "--input [FORMAT]", "Format of input (#{VALID_FORMATS.inspect})") do |i|
12
+ fail ArgumentError, "Invalid input format: #{i}" unless VALID_FORMATS.include?(i.to_s)
13
13
 
14
- options[:format] = f
14
+ options[:input] = i
15
15
  end
16
16
 
17
17
  opts.on("-e", "--exec [CODE]", "Ruby code to execute. `datum` variable will be in scope") do |code|
@@ -27,6 +27,12 @@ OptionParser.new do |opts|
27
27
  opts.on('-p', '--print', "Prints the result of the evaluated code") do |print|
28
28
  options[:print] = print
29
29
  end
30
+
31
+ opts.on('-f', '--forks [FORK_COUNT]', "Number of forks to use (parallel mode)") do |forks|
32
+ fail ArgumentError, "Invalid argument for fork count: #{forks.inspect}" if !forks.match(/^\d+$/)
33
+
34
+ options[:forks] = forks.to_i
35
+ end
30
36
  end.parse!
31
37
 
32
38
  def process_datum(_, options)
@@ -39,15 +45,30 @@ def process_datum(_, options)
39
45
  end
40
46
  end
41
47
 
42
- case options[:format]
43
- when 'json'
44
- require 'yajl'
45
- Yajl::Parser.new.parse(STDIN).each do |datum|
46
- process_datum(datum, options)
47
- end
48
- when 'csv'
49
- require 'csv'
50
- CSV.new(STDIN, headers: options[:headers]).each do |datum|
51
- process_datum(datum, options)
48
+ def iterate(stream, options)
49
+ iterator = case options[:input]
50
+ when 'json'
51
+ require 'yajl'
52
+ Yajl::Parser.new.parse(STDIN)
53
+ when 'csv'
54
+ require 'csv'
55
+ CSV.new(STDIN, headers: options[:headers])
56
+ end
57
+
58
+ if options[:forks]
59
+ puts 'parallel!'
60
+ require 'parallel'
61
+ puts 'parallel?'
62
+ puts 'iterator.shift', iterator.shift.inspect
63
+ Parallel.each(lambda { iterator.shift || Parallel::Stop }, in_processes: options[:forks]) do |datum|
64
+ process_datum datum, options
65
+ end
66
+ else
67
+ iterator.each do |datum|
68
+ process_datum datum, options
69
+ end
52
70
  end
53
71
  end
72
+
73
+ iterate(STDIN, options)
74
+
@@ -1,3 +1,3 @@
1
1
  module Pyrosome
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'yajl-ruby', '~> 1.2.1'
22
+ spec.add_dependency 'parallel', '~> 1.6.1'
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.10"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pyrosome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: parallel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,8 +102,6 @@ files:
88
102
  - lib/pyrosome.rb
89
103
  - lib/pyrosome/version.rb
90
104
  - pyrosome.gemspec
91
- - test.csv
92
- - test.json
93
105
  homepage: https://github.com/cheerfulstoic/pyrosome
94
106
  licenses:
95
107
  - MIT
data/test.csv DELETED
@@ -1,2 +0,0 @@
1
- test,"foo"
2
- "bar,baz",2
data/test.json DELETED
@@ -1 +0,0 @@
1
- [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]