libyear-bundler 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cd3378215fe47cbc740474dd3a8d5cf32a82aac
4
+ data.tar.gz: acc89ac6b9819ca27899a77fea914cd6f6d62496
5
+ SHA512:
6
+ metadata.gz: 90134e10c548ae10330bf66b7405220f6d60750f2a0c27e197011ebfb0369807b4c36b2b5025f8f8777964bb815ac650e26d1d4c6ac6a44599b3e5b0fadd30ca
7
+ data.tar.gz: ffe3db93db14c0ad62a1694a5952e252cc0ba1faf90ae0539d6b30432a5b6fd63e9b9b831bb6986b20e7423e5d4b3de06218975d5ae08eefee2868879940bb56
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,71 @@
1
+ # libyear
2
+
3
+ This project follows [semver 2.0.0][1] and the recommendations
4
+ of [keepachangelog.com][2].
5
+
6
+ ## 0.2.0 (2017-03-10)
7
+
8
+ Breaking changes:
9
+
10
+ - Rename project
11
+ - Rename project from libyear-rb to libyear-bundler
12
+ - Rename binary from libyear to libyear-bundler
13
+ - Discussion: https://github.com/jaredbeck/libyear-rb/issues/1
14
+
15
+ Added:
16
+
17
+ - None
18
+
19
+ Fixed:
20
+
21
+ - None
22
+
23
+ ## 0.1.3 (2017-03-07)
24
+
25
+ Breaking changes:
26
+
27
+ - None
28
+
29
+ Added:
30
+
31
+ - None
32
+
33
+ Fixed:
34
+
35
+ - Don't crash when Gemfile uses git
36
+
37
+ ## 0.1.2 (2017-02-16)
38
+
39
+ Breaking changes:
40
+
41
+ - None
42
+
43
+ Added:
44
+
45
+ - None
46
+
47
+ Fixed:
48
+
49
+ - Better handling of weird sources like rails-assets
50
+ - Wider report columns
51
+
52
+ ## 0.1.1 (2017-02-14)
53
+
54
+ Breaking changes:
55
+
56
+ - None
57
+
58
+ Added:
59
+
60
+ - None
61
+
62
+ Fixed:
63
+
64
+ - Better handling of error when bundle outdated fails
65
+
66
+ ## 0.1.0 (2017-02-13)
67
+
68
+ Initial version. Proof of concept.
69
+
70
+ [1]: http://semver.org/spec/v2.0.0.html
71
+ [2]: http://keepachangelog.com/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libyear.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Libyear
2
+
3
+ A simple measure of dependency freshness for ruby apps.
4
+
5
+ A libyear (library year) is a measure of how old a software dependency is.
6
+
7
+ If your system has two dependencies, the first one year old, the second three,
8
+ then your system is four libyears out-of-date.
9
+
10
+ A dependency is one year old when the version you are using is one year older
11
+ than its latest version.
12
+
13
+ ## Usage
14
+
15
+ Early access. Output and usage subject to change.
16
+
17
+ ```
18
+ gem install libyear-bundler
19
+ libyear-bundler Gemfile
20
+ activesupport 4.2.7.1 2016-08-10 5.0.1 2016-12-21 0.4
21
+ json 1.8.6 2017-01-13 2.0.3 2017-01-12 0.0
22
+ minitest_to_rspec 0.6.0 2015-06-09 0.8.0 2017-01-02 1.6
23
+ System is 1.9 libyears behind
24
+ ```
25
+
26
+ ## Development
27
+
28
+ ```
29
+ ruby -I lib bin/libyear-bundler spec/fixtures/01/Gemfile
30
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "libyear_bundler"
3
+ LibyearBundler::CLI.new(ARGV).run
@@ -0,0 +1,23 @@
1
+ require "bundler/cli"
2
+ require "bundler/cli/outdated"
3
+ require "libyear_bundler/report"
4
+ require "libyear_bundler/query"
5
+
6
+ module LibyearBundler
7
+ class CLI
8
+ def initialize(argv)
9
+ validate_arguments(argv)
10
+ @gemfile_path = argv.first
11
+ end
12
+
13
+ def run
14
+ print Report.new(Query.new(@gemfile_path).execute).to_s
15
+ end
16
+
17
+ private
18
+
19
+ def validate_arguments(argv)
20
+ # todo
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,88 @@
1
+ require "English"
2
+ require "open3"
3
+
4
+ module LibyearBundler
5
+ # Responsible for getting all the data that goes into the `Report`.
6
+ class Query
7
+ # Format of `bundle outdated --parseable` (BOP)
8
+ BOP_FMT = /\A(?<name>[^ ]+) \(newest (?<newest>[^,]+), installed (?<installed>[^,)]+)/
9
+
10
+ def initialize(gemfile_path)
11
+ @gemfile_path = gemfile_path
12
+ end
13
+
14
+ def execute
15
+ gems = []
16
+ bundle_outdated.lines.each do |line|
17
+ match = BOP_FMT.match(line)
18
+ next if match.nil?
19
+ gems.push(
20
+ installed: { version: match["installed"] },
21
+ name: match["name"],
22
+ newest: { version: match["newest"] }
23
+ )
24
+ end
25
+ gems.each do |gem|
26
+ di = release_date(gem[:name], gem[:installed][:version])
27
+ dn = release_date(gem[:name], gem[:newest][:version])
28
+ gem[:installed][:date] = di
29
+ gem[:newest][:date] = dn
30
+ if di.nil? || dn.nil? || dn <= di
31
+ # Known issue: Backports and maintenance releases of older minor versions.
32
+ # Example: json 1.8.6 (2017-01-13) was released *after* 2.0.3 (2017-01-12)
33
+ years = 0.0
34
+ else
35
+ days = (dn - di).to_f
36
+ years = days / 365.0
37
+ end
38
+ gem[:libyears] = years
39
+ end
40
+ gems
41
+ end
42
+
43
+ private
44
+
45
+ def bundle_outdated
46
+ stdout, stderr, status = Open3.capture3(
47
+ %Q(BUNDLE_GEMFILE="#{@gemfile_path}" bundle outdated --parseable)
48
+ )
49
+ # Known statuses:
50
+ # 0 - Nothing is outdated
51
+ # 256 - Something is outdated
52
+ # 1792 - Unable to determine if something is outdated
53
+ unless [0, 256].include?(status.to_i)
54
+ $stderr.puts "`bundle outdated` failed with status: #{status.to_i}"
55
+ $stderr.puts "stderr: #{stderr}"
56
+ $stderr.puts "stdout: #{stdout}"
57
+ $stderr.puts "Try running `bundle install`."
58
+ Kernel.exit(1)
59
+ end
60
+ stdout
61
+ end
62
+
63
+ # Known issue: Probably performs a network request every time, unless
64
+ # there's some kind of caching.
65
+ def release_date(gem_name, gem_version)
66
+ dep = nil
67
+ begin
68
+ dep = ::Bundler::Dependency.new(gem_name, gem_version)
69
+ rescue ::Gem::Requirement::BadRequirementError => e
70
+ $stderr.puts "Could not find release date for: #{gem_name}"
71
+ $stderr.puts(e)
72
+ $stderr.puts(
73
+ "Maybe you used git in your Gemfile, which libyear doesn't support " \
74
+ "yet. Contributions welcome."
75
+ )
76
+ return nil
77
+ end
78
+ tuples, _errors = ::Gem::SpecFetcher.fetcher.search_for_dependency(dep)
79
+ if tuples.empty?
80
+ $stderr.puts "Could not find release date for: #{gem_name}"
81
+ return nil
82
+ end
83
+ tup, source = tuples.first # Gem::NameTuple
84
+ spec = source.fetch_spec(tup) # raises Gem::RemoteFetcher::FetchError
85
+ spec.date.to_date
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,30 @@
1
+ module LibyearBundler
2
+ # Responsible presenting data from the `Query`. Should only be concerned
3
+ # with presentation, nothing else.
4
+ class Report
5
+ # `gems` - Array of hashes.
6
+ def initialize(gems)
7
+ @gems = gems
8
+ end
9
+
10
+ def to_s
11
+ sum_years = 0.0
12
+ @gems.each do |gem|
13
+ years = gem[:libyears]
14
+ sum_years += years
15
+ puts(
16
+ format(
17
+ "%30s%15s%15s%15s%15s%10.1f",
18
+ gem[:name],
19
+ gem[:installed][:version],
20
+ gem[:installed][:date],
21
+ gem[:newest][:version],
22
+ gem[:newest][:date],
23
+ years
24
+ )
25
+ )
26
+ end
27
+ puts format("System is %.1f libyears behind", sum_years)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module LibyearBundler
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "bundler"
2
+ require "libyear_bundler/version"
3
+ require "libyear_bundler/cli"
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'libyear_bundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libyear-bundler"
8
+ spec.version = LibyearBundler::VERSION
9
+ spec.authors = ["Jared Beck"]
10
+ spec.email = ["jared@jaredbeck.com"]
11
+ spec.summary = "A simple measure of dependency freshness"
12
+ spec.homepage = "https://libyear.com"
13
+ spec.licenses = ["GPL-3.0"]
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "bin"
18
+ spec.executables = ["libyear-bundler"]
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "bundler", "~> 1.14"
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libyear-bundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jared Beck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ description:
28
+ email:
29
+ - jared@jaredbeck.com
30
+ executables:
31
+ - libyear-bundler
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - bin/libyear-bundler
41
+ - lib/libyear_bundler.rb
42
+ - lib/libyear_bundler/cli.rb
43
+ - lib/libyear_bundler/query.rb
44
+ - lib/libyear_bundler/report.rb
45
+ - lib/libyear_bundler/version.rb
46
+ - libyear-bundler.gemspec
47
+ homepage: https://libyear.com
48
+ licenses:
49
+ - GPL-3.0
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.6.10
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A simple measure of dependency freshness
71
+ test_files: []