fibonaccia 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b5052b89b8d22c7a2aa2f693d6833163bd9e471
4
+ data.tar.gz: 2bd4231043ff7f5a058cfff7c9a667c378bdac80
5
+ SHA512:
6
+ metadata.gz: 7991693751b1582cbc22db692ba68d7986f67a96a35b0be260b9afbf55b216f20b8c7b96a7d9e7a96b3a5373d234a75c5cb7d5a546e4d721710a2c69aeb80715
7
+ data.tar.gz: a16b49e6134a7b897235363126930c9ba3e2c4110f20bda992e05ce0659526d9a2529b395b7daf5a1539af94935e427a9d6baf24ead4401419e1336551a64e8f
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright © (c) 2015 Ken Coar
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+ # Based on
12
+ # https://github.com/dgoodwin/tito/blob/master/src/tito/tagger/main.py
13
+ #
14
+ """
15
+ Code for tagging Ruby gems based on their <gemname>::VERSION constant.
16
+ """
17
+
18
+ import os
19
+ import re
20
+ import rpm
21
+ import shutil
22
+ import subprocess
23
+ import tempfile
24
+ import textwrap
25
+ import sys
26
+
27
+ from string import Template
28
+
29
+ from time import strftime
30
+
31
+ from tito.common import (debug, error_out, run_command,
32
+ find_file_with_extension, find_spec_file,
33
+ get_project_name, get_latest_tagged_version,
34
+ get_spec_version_and_release,
35
+ replace_version, tag_exists_locally,
36
+ tag_exists_remotely, head_points_to_tag,
37
+ undo_tag, increase_version, reset_release,
38
+ increase_zstream, BUILDCONFIG_SECTION,
39
+ get_relative_project_dir_cwd)
40
+ from tito.compat import *
41
+ from tito.exception import TitoException
42
+ from tito.config_object import ConfigObject
43
+ from tito.tagger import VersionTagger
44
+
45
+ class RubyGemTagger(VersionTagger):
46
+ """
47
+ Releases will be tagged by obtaining the value of the VERSION constant
48
+ from the gem.
49
+ """
50
+
51
+ def __init__(self, config=None, keep_version=False, offline=False, user_config=None):
52
+ VersionTagger.__init__(self, config=config)
53
+ self.gemspec_file_name = find_file_with_extension(suffix=".gemspec")
54
+ new_version = subprocess.check_output(
55
+ [
56
+ "ruby",
57
+ "-e",
58
+ "gspec = eval(File.read('" + self.gemspec_file_name + "')); " +
59
+ "print(gspec.version)"
60
+ ])
61
+ regex = re.compile("^(\d+(?:\.\d+)*)-?(.*)$")
62
+ match = re.match(regex, new_version)
63
+ if match:
64
+ debug("Deduced version='%s' release='%s'" % (match.group(1), match.group(2)))
65
+ self._use_version = match.group(1)
66
+ """ The release value is currently parsed, but unused. """
67
+ self._use_release = match.group(2)
68
+
69
+ def _tag_release(self):
70
+ """
71
+ Tag a new version of the package based upon the gem version.
72
+ """
73
+ self._make_changelog()
74
+ self._check_tag_does_not_exist(self._get_new_tag(self._use_version))
75
+ self._update_changelog(self._use_version)
76
+ self._update_setup_py(self._use_version)
77
+ self._update_package_metadata(self._use_version)
78
+ self._bump_version(force=True)
79
+
80
+ def release_type(self):
81
+ """ return short string which explain type of release.
82
+ e.g. 'minor release
83
+ Child classes probably want to override this.
84
+ """
85
+ return "release"
86
+
87
+
88
+ class ReleaseTagger(VersionTagger):
89
+ """
90
+ Tagger which increments the spec file release instead of version.
91
+
92
+ Used for:
93
+ - Packages we build from a tarball checked directly into git.
94
+ - Satellite packages built on top of Spacewalk tarballs.
95
+ """
96
+
97
+ def _tag_release(self):
98
+ """
99
+ Tag a new release of the package. (i.e. x.y.z-r+1)
100
+ """
101
+ self._make_changelog()
102
+ new_version = self._bump_version(release=True)
103
+
104
+ self._check_tag_does_not_exist(self._get_new_tag(new_version))
105
+ self._update_changelog(new_version)
106
+ self._update_package_metadata(new_version)
107
+
108
+ def release_type(self):
109
+ """ return short string "minor release" """
110
+ return "minor release"
111
+
112
+
@@ -0,0 +1,3 @@
1
+ the .tito/packages directory contains metadata files
2
+ named after their packages. Each file has the latest tagged
3
+ version and the project's relative directory.
@@ -0,0 +1 @@
1
+ 1.0.0-2 ./
@@ -0,0 +1,6 @@
1
+ [buildconfig]
2
+ builder = tito.builder.Builder
3
+ tagger = tito.tagger.ReleaseTagger
4
+ lib_dir = .tito/custom/
5
+ changelog_do_not_remove_cherrypick = 0
6
+ changelog_format = %s (%ae)
@@ -0,0 +1,30 @@
1
+ ---
2
+ #
3
+ # Try using the container mechanism.
4
+ #
5
+ sudo: false
6
+
7
+ #
8
+ # Package info.
9
+ #
10
+ language: ruby
11
+ rvm:
12
+ - 1.9.3
13
+ - 2.0.0
14
+ - 2.1.0
15
+ - 2.2.0
16
+
17
+ gemfile:
18
+ - Gemfile
19
+
20
+ notifications:
21
+ email:
22
+ - RoUS@redhat.com
23
+
24
+ before_install:
25
+ - gem install bundler
26
+ - gem install versionomy
27
+
28
+ script:
29
+ - bundle exec rake features
30
+ - bundle exec rake yard
@@ -0,0 +1,7 @@
1
+ # CONTRIBUTORS:
2
+ -------------
3
+
4
+ * Ken Coar `<The.Rodent.of.Unusual.Size near GMail.Com>`
5
+ Initial creator, author, and maintainer.
6
+ * [Michael Trout](https://www.patreon.com/foundup),
7
+ [Patreon sponsor](https://www.patreon.com/theRoUS)
@@ -0,0 +1,3 @@
1
+ ```
2
+ %changelog
3
+ ```
@@ -0,0 +1,304 @@
1
+ # Fibonaccia Details
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fibonaccia.svg)](http://badge.fury.io/rb/fibonaccia)
4
+
5
+ *As though there weren't enough Ruby gems for dealing with the
6
+ Fibonacci sequence.. here's another one!*
7
+
8
+ ---
9
+ ### <a name="TOC">Table of Contents</a>
10
+
11
+ * [Introduduction](#Introduction)
12
+ * [Internals](#Internals)
13
+ * [Automatic Growth](#Automatic_Growth)
14
+ * [Usage](#Usage)
15
+ * [Querying](#Querying)
16
+ * [Metadata](#Metadata)
17
+ * [Fibonacci-ness](#Fibonacci-ness)
18
+ * [Constants](#Constants)
19
+ * [Memory considerations](#Memory_considerations)
20
+ * [Licence and Copyright](#Licence_and_Copyright)
21
+
22
+ ---
23
+
24
+ ## <a name="Introduction">Introduction</a>
25
+
26
+ `Fibonaccia` is a very simple package for accessing the series of
27
+ [Fibonacci numbers](https://en.wikipedia.org/wiki/Fibonacci_number).
28
+ It's implemented as a set of methods and constants wrapped in the `Fibonaccia`
29
+ namespace. All methods are module methods; it is *not* intended for
30
+ use as a mix-in; although attempting to import it with `include` will
31
+ do no harm, it won't accomplish much other than generating a warning
32
+ on `$stdout`.
33
+
34
+ `Fibonaccia` also provides the irrational constant
35
+ [`PHI` (`φ`)](#Constants), which represents the
36
+ [Golden Ratio](https://en.wikipedia.org/wiki/Golden_ratio) but which isn't in
37
+ Ruby's own *Math* module. `φ` is provided in both `Float` precision
38
+ and as a `BigDecimal` ( *q.v.*) value.
39
+
40
+ ---
41
+
42
+ <a name="Zero-based">**Note:**</a> `Fibonaccia` uses Ruby semantics
43
+ for dealing with the series. Most importantly, remember when querying
44
+ it that it is **zero-based** -- that is, the first term has index **`0`**.
45
+
46
+ ---
47
+
48
+ ## <a name="Internals">Internals</a>
49
+
50
+ `Fibonaccia` internally maintains an array of the Fibonacci sequence
51
+ covering whatever terms have been accessed through its API. That is,
52
+ if you requested the one-thousandth term, the internal array would
53
+ contain *at least* 1000 elements.
54
+
55
+ This internal array is referred to as the **internal series** in the
56
+ API documentation. It is not directly accessible from outside the
57
+ module; the {Fibonaccia.series} method returns a copy.
58
+
59
+ ### <a name="Automatic_Growth">Automatic Growth and Controlling the Size of the Series</a>
60
+
61
+ If you refer to a term that does not [yet] exist in the internal
62
+ series, the series will be automatically extended to include it. It
63
+ is never trimmed automatically, so memory consumption may be a concern
64
+ -- expecially if you use the {Fibonaccia.series} method, since that
65
+ will make an additional copy of the array.
66
+
67
+ The following example illustrates this:
68
+
69
+ ```ruby
70
+ Fibonaccia.series
71
+ => [ 0, 1, 1 ]
72
+ Fibonaccia.terms
73
+ => 3
74
+ Fibonaccia[12]
75
+ => 144
76
+ Fibonaccia.series
77
+ => [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 ]
78
+ Fibonaccia.terms
79
+ => 13
80
+ Fibonaccia[8]
81
+ => 21
82
+ Fibonaccia.series
83
+ => [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 ]
84
+ Fibonaccia.terms
85
+ => 13
86
+ ```
87
+
88
+ You can explicitly control the size of the internal series with the
89
+ following methods:
90
+
91
+ * {Fibonaccia.reset}
92
+ -- Resets the internal series to the basic default set of terms (see below).
93
+ * {Fibonaccia.grow}( *n*)
94
+ -- Extends the internal series by *`n`* terms.
95
+ * {Fibonaccia.shrink}( *n*)
96
+ -- Shrinks the internal series by removing *`n`* terms from the end.
97
+ * {Fibonaccia.terms=} *n*
98
+ -- Sets the total number of terms in the internal series, which will
99
+ be grown or shrunk as needed.
100
+
101
+ The internal series **always** includes the first three Fibonacci terms:
102
+ `[ 0, 1, 1 ]`. You cannot shrink or set the number of terms to fewer than
103
+ 3.
104
+
105
+ ## <a name="Usage">Usage</a>
106
+
107
+ All of the methods of the public API are documented in the usual
108
+ manner and places; this section is intended to provide a little more
109
+ detail about them than just the bare calling sequence.
110
+
111
+ ### <a name="Slicing_Indexing">Slicing/Indexing</a>
112
+
113
+ The internal series can be queried for single terms or slices of
114
+ consecutive ones, using either the {Fibonaccia.slice} method or the
115
+ shorthand (and possibly more readable) alias {Fibonaccia.[]}.
116
+
117
+ You can request a specific term in the Fibonacci series:
118
+
119
+ ```ruby
120
+ thirty_fifth = Fibonaccia[34] # remember: zero-based!
121
+ ```
122
+
123
+ or a slice:
124
+
125
+ ```ruby
126
+ fourth_through_seventh = Fibonaccia[3,3] # remember: zero-based!
127
+ fourth_through_seventh = Fibonaccia.slice(3,3)
128
+ ```
129
+
130
+ If any of the terms you request are beyond the end of the internal
131
+ series' current list of values, it will
132
+ [automatically be grown](#Automatic_Growth)
133
+ to include them.
134
+
135
+ The normal `Array` method semantics are available; for example:
136
+
137
+ ```ruby
138
+ Fibonaccia[-1] # return the last term in the internal series
139
+ Fibonaccia[-3,3] # return the last 3 terms
140
+ ```
141
+
142
+ Most of the methods provided by the `Enumerable` mix-in ( *q.v.*) are
143
+ available and apply to the internal series:
144
+
145
+ ```ruby
146
+ Fibonaccia.reset
147
+ Fibonaccia.last
148
+ => 1
149
+ Fibonaccia.include?(144)
150
+ => false # internal series not extended far enough yet
151
+ Fibonaccia.terms = 13
152
+ Fibonaccia.include?(144)
153
+ => true
154
+ Fibonaccia.series.reduce(:+) # cumulative sum of internal series
155
+ => 376
156
+ ```
157
+
158
+ Although it might seem appropriate to have `#include?` and `#member?`
159
+ return `true` if their arguments exist somewhere in the Fibonacci
160
+ series, that would conflict with their canonical meanings.
161
+ Consequently, the
162
+ '[is this arbitrary number in the Fibonacci series](#Fibonacci-ness)'
163
+ test has its own method, {Fibonaccia.is_fibonacci?}.
164
+
165
+ ### <a name="Metadata">Metadata</a>
166
+
167
+ Although the internal series is not directly accessible by user code,
168
+ you can obtain a *copy* using the {Fibonaccia.series} method:
169
+
170
+ ```ruby
171
+ series_so_far = Fibonaccia.series
172
+ ```
173
+
174
+ Querying the {Fibonaccia.terms} attribute will return the number of
175
+ terms currently in the internal series:
176
+
177
+ ```ruby
178
+ term_count = Fibonaccia.terms
179
+ ```
180
+
181
+ ### <a name="Fibonacci-ness">Fibonacci-ness</a>
182
+ or check to see if an arbitrary integer is a Fibonacci number:
183
+
184
+ ```ruby
185
+ Fibonaccia.is_fibonacci?(354224848179261915075)
186
+ => true
187
+ Fibonaccia.is_fibonacci?(354224848179261915075 + 1)
188
+ => false
189
+ ```
190
+
191
+ If memory becomes a concern (see
192
+ [Memory considerations](#Memory_considerations)),
193
+ you can trim the internal series back to the initial three terms:
194
+
195
+ ```ruby
196
+ Fibonaccia.reset
197
+ Fibonaccia.terms
198
+ => 3
199
+ ```
200
+
201
+ You can grow or shrink the list by any number of terms (although you
202
+ **cannot** shrink it to fewer than 3):
203
+
204
+ ```ruby
205
+ Fibonaccia.terms
206
+ => 3
207
+ Fibonaccia.grow(20)
208
+ => 23
209
+ Fibonaccia.terms
210
+ => 23
211
+ Fibonaccia.shrink(10)
212
+ => 13
213
+ Fibonaccia.terms
214
+ => 13
215
+ ```
216
+
217
+ or you can set the size of the series to any arbitrary number of terms
218
+ (again, you cannot set the series to fewer than 3 terms):
219
+
220
+ ```ruby
221
+ Fibonaccia.reset
222
+ Fibonaccia.terms
223
+ => 3
224
+ Fibonaccia.terms = 2048
225
+ Fibonaccia.terms
226
+ => 2048
227
+ ```
228
+
229
+ ### <a name="Constants">Constants</a>
230
+
231
+ `Fibonaccia` provides only a single constant -- `PHI` (`φ`), the
232
+ [Golden Ratio](https://en.wikipedia.org/wiki/Golden_ratio). It
233
+ is available as both a `Float` of implementation-specific precision
234
+ and as an arbitrary-precision `BigDecimal` ( *q.v.*).
235
+
236
+ There are two ways of accessing the constant:
237
+
238
+ ```ruby
239
+ #
240
+ # Using conventional Ruby constant syntax:
241
+ #
242
+ Fibonaccia::PHI # Float
243
+ Fibonaccia::PHI(false) # Float
244
+ Fibonaccia::PHI(true) # BigDecimal
245
+ #
246
+ # Or as a method:
247
+ #
248
+ Fibonaccia.PHI # Float
249
+ Fibonaccia.PHI(false) # Float
250
+ Fibonaccia.PHI(true) # BigDecimal
251
+ ```
252
+
253
+ The latter syntax is recommended and preferred.
254
+
255
+ ### <a name="Memory_considerations">Memory considerations</a>
256
+
257
+ Although the internal series is expanded only at need, the fact that
258
+ it is never automatically trimmed back means that the more terms are
259
+ requested, the more memory will be consumed by it. Although this
260
+ shouldn't be an issue unless you're dealing with thousands of terms,
261
+ it *can* be a concern if you use the {Fibonaccia.series} method -- as
262
+ each invocation thereof will return a *duplicate* of the internal
263
+ series as it currently stands. (That is, extending the internal
264
+ series after making a copy with {Fibonaccia.series} does **not**
265
+ result in the copy being extended as well.)
266
+
267
+ You can use the {Fibonaccia.terms} method to determine how many terms
268
+ are currently in the internal series, and so get an idea of how much
269
+ of a resource impact an invocation of {Fibonaccia.series} would have.
270
+
271
+ If you seed to work with the series itself rather than through the
272
+ methods provided by the module, you can reduce the impact by obtaining
273
+ the copy and then resetting the internal series back to its minimal
274
+ usage:
275
+
276
+ ```ruby
277
+ Fibonaccia.terms = 100000 # internal series = 100,000 terms
278
+ my_copy = Fibonaccia.series # plus a copy, also of 100,000 terms
279
+ Fibonaccia.reset # now just your copy,
280
+ # plus 3 terms in the internal series
281
+ ```
282
+
283
+ ## <a name="Licence_and_Copyright">Licence and Copyright</a>
284
+
285
+ `Fibonaccia` is copyright © 2015 by Ken Coar, and is made available
286
+ under the terms of the Apache Licence 2.0:
287
+
288
+ ```
289
+ Copyright © 2015 Ken Coar
290
+
291
+ Licensed under the Apache License, Version 2.0 (the "License");
292
+ you may not use this file except in compliance with the License.
293
+ You may obtain a copy of the License at
294
+
295
+ http://www.apache.org/licenses/LICENSE-2.0
296
+
297
+ Unless required by applicable law or agreed to in writing, software
298
+ distributed under the License is distributed on an "AS IS" BASIS,
299
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
300
+ See the License for the specific language governing permissions and
301
+ limitations under the License.
302
+ ```
303
+
304
+ Your distribution should include a copy of the `LICENCE.txt` file.