piah 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe582fcfd679d1c51dcb5a7327fbeee7359b800e
4
+ data.tar.gz: 3905b220ab0c6dcc79d87910f3b1c7d966f33629
5
+ SHA512:
6
+ metadata.gz: c4089dde4306f8494ed6166632060801aa4a0903b922fe166908ecae0c7139f9327c3dbe582f7cbe8f825985f4c4dc922f609332da55c93463aaf41f58d166c9
7
+ data.tar.gz: 7e520595425f48ca64406b0100869c472851c879341682d69536beefc7d81ae93682e6c652d40bee3d3c702c473e5988bb14bb941bb75b85e7c28cbfba6576e8
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matt.edlefsen@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in piah.gemspec
4
+ #ruby=ruby-2.4
5
+ ruby '2.4.1'
6
+ gemspec
7
+
8
+ gem 'rake'
9
+ gem 'alki-console'
10
+ gem 'alki-testing'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Matt Edlefsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ [[piah]]
2
+ piah
3
+ ----
4
+
5
+ Piah is a library for constructing large data transformations out
6
+ of smaller individual processes. When given input data, and a set of
7
+ of processors, piah will automatically order and connect the processors
8
+ into a pipeline to produce output.
9
+
10
+ [[installation]]
11
+ Installation
12
+ ~~~~~~~~~~~~
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ [source,ruby]
17
+ ----
18
+ gem 'piah'
19
+ ----
20
+
21
+ And then execute:
22
+
23
+ ....
24
+ $ bundle
25
+ ....
26
+
27
+ Or install it yourself as:
28
+
29
+ ....
30
+ $ gem install piah
31
+ ....
32
+
33
+ [[usage]]
34
+ Usage
35
+ ~~~~~
36
+
37
+ TODO: Write usage instructions here
38
+
39
+
40
+ [[contributing]]
41
+ Contributing
42
+ ~~~~~~~~~~~~
43
+
44
+ Bug reports and pull requests are welcome on GitHub at
45
+ https://github.com/alki-project/piah. This project is intended to be a
46
+ safe, welcoming space for collaboration, and contributors are expected
47
+ to adhere to the http://contributor-covenant.org[Contributor Covenant]
48
+ code of conduct.
49
+
50
+ [[license]]
51
+ License
52
+ ~~~~~~~
53
+
54
+ The gem is available as open source under the terms of the
55
+ http://opensource.org/licenses/MIT[MIT License].
56
+
57
+ [[code-of-conduct]]
58
+ Code of Conduct
59
+ ~~~~~~~~~~~~~~~
60
+
61
+ Everyone interacting in the Piah project’s codebases, issue trackers,
62
+ chat rooms and mailing lists is expected to follow the
63
+ https://github.com/alki-project/piah/blob/master/CODE_OF_CONDUCT.md[code
64
+ of conduct].
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'alki/testing/tasks'
3
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ Alki do
2
+ set :processors do
3
+ []
4
+ end
5
+
6
+ service :root_processor do
7
+ require 'piah/processor_list'
8
+ Piah::ProcessorList.new(processors.to_a)
9
+ end
10
+
11
+ factory :process do
12
+ require 'piah/config_processor'
13
+ Piah::ConfigProcessor.new(root_processor).method(:process)
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ Alki::Loader.register 'piah/dsl.rb', builder: 'alki/dsls/dsl'
@@ -0,0 +1,2 @@
1
+ require 'alki'
2
+ Alki.project_assembly!
@@ -0,0 +1,137 @@
1
+ module Piah
2
+ class ConfigMergeError < StandardError
3
+ def initialize(a,b)
4
+ super "Failed to merge config values #{a.pretty_print_inspect}\n and\n#{b.pretty_print_inspect}"
5
+ end
6
+ end
7
+
8
+ class ConfigProcessorResultError < StandardError
9
+ def initialize(v)
10
+ super "Config processors must return a Hash or an Array of Hashes, got #{v.inspect}"
11
+ end
12
+ end
13
+
14
+ class ConfigProcessor
15
+ def initialize(processor)
16
+ @processor = processor
17
+ end
18
+
19
+ # Basic idea is that we have our list of config processors, along with the config types
20
+ # each one accepts. The list becomes our initial "chain", which is a particular ordering
21
+ # of the processors. We then run through the chain, providing each processor with the
22
+ # config types it wants, and adding it's outputs to the set of config types. The result
23
+ # is then a hash of all unhandled config types.
24
+ #
25
+ # If, when processing the chain, a processor (A) outputs a config type that has already been
26
+ # processed by an earlier (in the chain) processor (B), we abort and rearrange the chain so that
27
+ # the A processor will run before the B processor, and then execute the new chain.
28
+ # This repeats until we get all the way through the chain without encountering processors out
29
+ # of order.
30
+ def process(config)
31
+ types = @processor.types
32
+ chain = types.keys.map{|p| [p,{}] }
33
+ result = nil
34
+ config = copy(config)
35
+ until result
36
+ result = process_chain(types,chain,copy(config))
37
+ if result.is_a?(Set)
38
+ # Rearrange chain
39
+ move = chain.size.times.select do |i|
40
+ types[chain[i][0]].to_set.intersect? result
41
+ end
42
+ move.each do |i|
43
+ chain.push [chain[i][0],{}]
44
+ chain[i] = nil
45
+ end
46
+ chain.compact!
47
+ result = nil
48
+ end
49
+ end
50
+ result
51
+ end
52
+
53
+ private
54
+
55
+ # Returns final output or a Set of keys that have been generated
56
+ # after we've already processed them (requiring re-ordering)
57
+ def process_chain(types,chain,input)
58
+ output = input.dup
59
+ seen = Set.new
60
+ chain.each do |(p,cache)|
61
+ args = input.select{|k| types[p].include?(k) }
62
+ args.keys.each {|k| output.delete k }
63
+
64
+ unless cache[:result]
65
+ result = @processor.process(p, copy(args))
66
+ if result.is_a? Array
67
+ cache[:result] = result.inject({}) do |r,c|
68
+ merge(r,copy(c))
69
+ end
70
+ else
71
+ unless result.is_a? Hash
72
+ raise Piah::ConfigProcessorResultError.new result
73
+ end
74
+ cache[:result] = copy(result)
75
+ end
76
+ unless cache[:result].keys.all?{|k| k && k.size > 0}
77
+ raise Piah::ConfigProcessorResultError.new cache[:result]
78
+ end
79
+ end
80
+ keys = cache[:result].keys.to_set
81
+ out_of_order = seen & keys
82
+ # If chain is out of order, abort
83
+ return out_of_order unless out_of_order.empty?
84
+
85
+ seen.merge types[p]
86
+ begin
87
+ merge(output,copy(cache[:result]))
88
+ rescue => e
89
+ raise ConfigMergeError.new(output,cache[:result])
90
+ end
91
+ cache[:result].each_key {|k| input[k] = output[k] unless input.key? k }
92
+ end
93
+ output
94
+ end
95
+
96
+ def merge(a,b)
97
+ if a.is_a?(Hash) && b.is_a?(Hash)
98
+ a.merge!(b) do |key,av,bv|
99
+ merge av, bv
100
+ end
101
+ elsif a.is_a?(Array) && b.is_a?(Array)
102
+ a.push *b.reject{|e| a.include?(b)}
103
+ elsif a.is_a?(Proc) && b.is_a?(Proc)
104
+ b
105
+ elsif a != b
106
+ raise ConfigMergeError.new(a,b)
107
+ end
108
+ a
109
+ end
110
+
111
+ def copy(obj)
112
+ if obj.is_a?(Hash)
113
+ obj.each_with_object({}) do |(k,v),h|
114
+ new_k = k.to_sym rescue k
115
+ h[new_k] = copy(v)
116
+ end
117
+ elsif obj.is_a?(Array)
118
+ obj.map {|e| copy e }
119
+ else
120
+ obj.dup
121
+ end
122
+ end
123
+
124
+ def symbolize_keys(obj)
125
+ if obj.is_a?(Hash)
126
+ obj.each_with_object({}) do |(k,v),h|
127
+ new_k = k.to_sym rescue k
128
+ h[new_k] = symbolize_keys(v, &blk)
129
+ end
130
+ elsif obj.is_a?(Array)
131
+ obj.map{|e| symbolize_keys(e, &blk)}
132
+ else
133
+ obj
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,85 @@
1
+ Alki do
2
+ require_dsl 'alki/dsls/service'
3
+
4
+ init do
5
+ @auto_outputs = []
6
+ @types = {}
7
+ @has_process =false
8
+ end
9
+
10
+ dsl_method :input do |type,*args|
11
+ raise ArgumentError.new "Too many arguments" if args.size > 1
12
+ if type.is_a?(Hash) && type.size == 1
13
+ type, *args = type.to_a.first
14
+ end
15
+ has_default = !args.empty?
16
+ default = args.first
17
+ @types[type] = !has_default
18
+ add_method type, private: true, subclass: 'Instance' do
19
+ @_values[type] || default
20
+ end
21
+ end
22
+
23
+ dsl_method :passthrough do |type,*args|
24
+ input type, *args
25
+ @auto_outputs << type
26
+ end
27
+
28
+ dsl_method :process do |&blk|
29
+ @has_process = true
30
+ add_method :process, subclass: 'Instance', &blk
31
+ end
32
+
33
+ finish do
34
+ unless @has_process
35
+ raise "Processor must have process block!"
36
+ end
37
+ types = @types.keys
38
+ required_types = @types.inject([]) {|a,(n,r)| r ? a << n : a }.to_set
39
+ auto_outputs = @auto_outputs
40
+
41
+ ivs = class_builder[:initialize_params]&.map {|n,_| :"@#{n}"} || []
42
+
43
+ add_module ctx[:module], subclass: 'Instance'
44
+ ctx[:module] = nil
45
+ add_method :initialize, subclass: 'Instance' do |config_type,values,output|
46
+ @_config_type = config_type
47
+ ivs.each do |iv|
48
+ instance_variable_set iv, config_type.instance_variable_get(iv)
49
+ end
50
+ @_values = values
51
+ @_output = output
52
+ end
53
+
54
+ add_method :output, subclass: 'Instance' do |*keys,value,&blk|
55
+ if blk
56
+ keys << value
57
+ value = blk
58
+ end
59
+ @_output << keys.reverse.inject(value) do |v,k|
60
+ {k => v}
61
+ end
62
+ end
63
+
64
+ add_method :types do
65
+ types
66
+ end
67
+
68
+ add_method :process do |args|
69
+ output = []
70
+ unless auto_outputs.empty?
71
+ output << auto_outputs.map do |o|
72
+ args.key?(o) ? [o,args[o]] : nil
73
+ end.compact.to_h
74
+ end
75
+ unless required_types <= args.keys.to_set
76
+ return output
77
+ end
78
+ instance = self.class::Instance.new self, args, output
79
+ if instance.respond_to? :process
80
+ instance.process
81
+ end
82
+ output
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,15 @@
1
+ module Piah
2
+ class ProcessorList
3
+ def initialize(*processors)
4
+ @processors = processors.flatten
5
+ end
6
+
7
+ def types
8
+ @types ||= @processors.each_index.zip(@processors.map(&:types)).to_h
9
+ end
10
+
11
+ def process(p,args)
12
+ @processors[p].process args
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Piah
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "piah/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "piah"
8
+ spec.version = Piah::VERSION
9
+ spec.authors = ["Matt Edlefsen"]
10
+ spec.email = ["matt.edlefsen@gmail.com"]
11
+
12
+ spec.summary = %q{A library for constructing data pipelines.}
13
+ spec.homepage = "https://github.com/alki-project/piah"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "alki", "~> 0.13.0"
24
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Edlefsen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: alki
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.0
27
+ description:
28
+ email:
29
+ - matt.edlefsen@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.adoc
39
+ - Rakefile
40
+ - config/assembly.rb
41
+ - lib/alki_loader.rb
42
+ - lib/piah.rb
43
+ - lib/piah/config_processor.rb
44
+ - lib/piah/dsl.rb
45
+ - lib/piah/processor_list.rb
46
+ - lib/piah/version.rb
47
+ - piah.gemspec
48
+ homepage: https://github.com/alki-project/piah
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.6.12
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: A library for constructing data pipelines.
72
+ test_files: []