ndr_import 9.0.3 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2237d88e9dee0141fe297fd2eb0d2e76f5434e9bb791fb667505193f30263014
4
- data.tar.gz: 52746c16790c3da92e64ac14ed7d77786a41c5457ddc0b8190f52d4414e4c6d7
3
+ metadata.gz: aaf3c826acb51f4d579fb956e9606b5b86e120f3bd561db762d72081f27a1098
4
+ data.tar.gz: 2b11ddf7dc9b748b4a1ac9cc91b47c47b99677e4bde990c44d1ec20e76efbfc0
5
5
  SHA512:
6
- metadata.gz: 8b8793a45dea035b2abf04a44c20d2ec4fc90bcfef9c5dec4415fab26abdba2ff218b7d2996a165f3447f86046dfd558bfb363e21221f147fec3db9c7c83668c
7
- data.tar.gz: eedb044185f1bc7e843e91e634fdc8b88cae9c026344d92e3cdc1046979873d843d476c7a0f7ebfb3c631901b47c9109b6826696124c56b07082ba4a6842af9c
6
+ metadata.gz: 3faaf744255693f04425b6e5ed1ec7198e912d2854b3f482a39d9bc53fe3859ed3bb6ef7855cdfd03959042a530f3a2f528239548676c7159c9029d69b6c160d
7
+ data.tar.gz: 1aa9d1895d7f874499823c4b87f1874e025b376f239030f3baf40bab5f5ed3ed09f80721205e271446893a9070652df3f26fceb48b59a9eb86ac121fdbfd92c6
@@ -0,0 +1,2 @@
1
+ # Admins should have oversight of the version:
2
+ lib/ndr_import/version.rb @publichealthengland/ndr-admins
@@ -0,0 +1,23 @@
1
+ name: Lint
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ rubocop:
7
+ name: RuboCop
8
+
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ with:
14
+ fetch-depth: 0 # fetch everything
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 3.0
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run RuboCop against BASE..HEAD changes
22
+ run: bundle exec rake rubocop:diff origin/${GITHUB_BASE_REF#*/}
23
+
@@ -0,0 +1,72 @@
1
+ name: Test
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ ruby-version:
11
+ - 2.6
12
+ - 2.7
13
+ - 3.0
14
+ gemfile:
15
+ - gemfiles/Gemfile.rails52
16
+ - gemfiles/Gemfile.rails60
17
+
18
+ name: Ruby ${{ matrix.ruby-version }} / Bundle ${{ matrix.gemfile }}
19
+
20
+ runs-on: ubuntu-latest
21
+
22
+ env:
23
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
24
+
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby-version }}
31
+ - name: Install dependencies
32
+ run: bundle install
33
+ - name: Run tests
34
+ run: bundle exec rake
35
+
36
+ # A utility job upon which Branch Protection can depend,
37
+ # thus remaining agnostic of the matrix.
38
+ test_matrix:
39
+ if: ${{ always() }}
40
+ runs-on: ubuntu-latest
41
+ name: Matrix
42
+ needs: test
43
+ steps:
44
+ - name: Check build matrix status
45
+ if: ${{ needs.test.result != 'success' }}
46
+ run: exit 1
47
+
48
+ notify:
49
+ # Run only on master, but regardless of whether tests past:
50
+ if: ${{ always() && github.ref == 'refs/heads/master' }}
51
+
52
+ needs: test_matrix
53
+
54
+ runs-on: ubuntu-latest
55
+
56
+ steps:
57
+ - uses: 8398a7/action-slack@v3
58
+ with:
59
+ status: custom
60
+ fields: workflow,commit,author
61
+ custom_payload: |
62
+ {
63
+ channel: 'C7FQWGDHP',
64
+ username: 'CI – ' + '${{ github.repository }}'.split('/')[1],
65
+ icon_emoji: ':hammer_and_wrench:',
66
+ attachments: [{
67
+ color: '${{ needs.test_matrix.result }}' === 'success' ? 'good' : '${{ needs.test_matrix.result }}' === 'failure' ? 'danger' : 'warning',
68
+ text: `${process.env.AS_WORKFLOW} against \`${{ github.ref }}\` (${process.env.AS_COMMIT}) for ${{ github.actor }} resulted in *${{ needs.test_matrix.result }}*.`
69
+ }]
70
+ }
71
+ env:
72
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  ## [Unreleased]
2
2
  *no unreleased changes*
3
3
 
4
+ ## 9.1.0 / 2021-02-01
5
+ ### Added
6
+ * `CSVLibrary` is now deprecated.
7
+ * Handle xlsm files
8
+
9
+ ### Fixed
10
+ * Fix `CSVLibrary.foreach` on Ruby 3.0
11
+ * Updated jekyll bundle
12
+
4
13
  ## 9.0.3 / 2021-01-04
5
14
  ### Fixed
6
15
  * Address issue importing multiple files against the same table (#54)
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # NdrImport [![Build Status](https://travis-ci.org/PublicHealthEngland/ndr_import.svg?branch=master)](https://travis-ci.org/PublicHealthEngland/ndr_import) [![Gem Version](https://badge.fury.io/rb/ndr_import.svg)](https://badge.fury.io/rb/ndr_import) [![Documentation](https://img.shields.io/badge/ndr_import-docs-blue.svg)](https://www.rubydoc.info/gems/ndr_import)
2
-
1
+ # NdrImport [![Build Status](https://github.com/publichealthengland/ndr_import/workflows/Test/badge.svg)](https://github.com/publichealthengland/ndr_import/actions?query=workflow%3Atest) [![Gem Version](https://badge.fury.io/rb/ndr_import.svg)](https://rubygems.org/gems/ndr_import) [![Documentation](https://img.shields.io/badge/ndr_import-docs-blue.svg)](https://www.rubydoc.info/gems/ndr_import)
3
2
  This is the Public Health England (PHE) National Disease Registers (NDR) Import ETL ruby gem, providing:
4
3
 
5
4
  1. file import handlers for *extracting* data from delimited files (csv, pipe, tab, thorn), .xls(x) spreadsheets, .doc(x) word documents, PDF, PDF AcroForms, XML, 7-Zip and Zip files.
data/code_safety.yml CHANGED
@@ -1,5 +1,17 @@
1
1
  ---
2
2
  file safety:
3
+ ".github/CODEOWNERS":
4
+ comments:
5
+ reviewed_by: ollietulloch
6
+ safe_revision: b64ff21375dcde2b8fefe622ee9861f0fea21487
7
+ ".github/workflows/lint.yml":
8
+ comments:
9
+ reviewed_by: ollietulloch
10
+ safe_revision: b64ff21375dcde2b8fefe622ee9861f0fea21487
11
+ ".github/workflows/test.yml":
12
+ comments:
13
+ reviewed_by: ollietulloch
14
+ safe_revision: b64ff21375dcde2b8fefe622ee9861f0fea21487
3
15
  ".gitignore":
4
16
  comments: whole file re-reviewed
5
17
  reviewed_by: josh.pencheon
@@ -12,14 +24,10 @@ file safety:
12
24
  comments:
13
25
  reviewed_by: josh.pencheon
14
26
  safe_revision: b09e268ff9c8349b914aa1b7ba888e1d39f97e4a
15
- ".travis.yml":
16
- comments:
17
- reviewed_by: ollietulloch
18
- safe_revision: ed8513d290796b9cb9554c4ebe6e87ac21fbbeae
19
27
  CHANGELOG.md:
20
28
  comments:
21
29
  reviewed_by: ollietulloch
22
- safe_revision: 92d2d9d56f17c143709e25560d7620aaf147008f
30
+ safe_revision: d88ded7c260da37200610e4f0b204a4ea2e481f9
23
31
  CODE_OF_CONDUCT.md:
24
32
  comments:
25
33
  reviewed_by: timgentry
@@ -38,8 +46,8 @@ file safety:
38
46
  safe_revision: 5d185a0aeba6a9cd2ff5e59efadcaeec9be45d8b
39
47
  README.md:
40
48
  comments:
41
- reviewed_by: josh.pencheon
42
- safe_revision: 1bc459db8970dde36e9b240b6dd08cca629664e3
49
+ reviewed_by: ollietulloch
50
+ safe_revision: b64ff21375dcde2b8fefe622ee9861f0fea21487
43
51
  Rakefile:
44
52
  comments:
45
53
  reviewed_by: josh.pencheon
@@ -59,7 +67,7 @@ file safety:
59
67
  docs/Gemfile.lock:
60
68
  comments:
61
69
  reviewed_by: ollietulloch
62
- safe_revision: 6f274715bb341c3070190f04f67af9500b510580
70
+ safe_revision: ea0149c7739676463a252ffd9fbe4af238762b2b
63
71
  docs/_config.yml:
64
72
  comments:
65
73
  reviewed_by: josh.pencheon
@@ -147,7 +155,7 @@ file safety:
147
155
  lib/ndr_import/csv_library.rb:
148
156
  comments:
149
157
  reviewed_by: ollietulloch
150
- safe_revision: acc72173b81702d55fe3aff78054425609a4d339
158
+ safe_revision: 6b8668967dbd42d7893a0fa5f0aa1ec1c11227e1
151
159
  lib/ndr_import/file/acro_form.rb:
152
160
  comments:
153
161
  reviewed_by: josh.pencheon
@@ -170,8 +178,8 @@ file safety:
170
178
  safe_revision: 897f8b648d633368cf2001d17ab89c06a12d445b
171
179
  lib/ndr_import/file/excel.rb:
172
180
  comments:
173
- reviewed_by: josh.pencheon
174
- safe_revision: c3183e522bce50008df576ceb47fe4761ab8f966
181
+ reviewed_by: ollietulloch
182
+ safe_revision: 37482c79448bea80033f6f69d97584df330c9861
175
183
  lib/ndr_import/file/office_file_helper.rb:
176
184
  comments:
177
185
  reviewed_by: josh.pencheon
@@ -215,7 +223,7 @@ file safety:
215
223
  lib/ndr_import/helpers/file/delimited.rb:
216
224
  comments:
217
225
  reviewed_by: ollietulloch
218
- safe_revision: acc72173b81702d55fe3aff78054425609a4d339
226
+ safe_revision: 4a5cc1d362c632fc1f9242c69982fbce33557e17
219
227
  lib/ndr_import/helpers/file/excel.rb:
220
228
  comments:
221
229
  reviewed_by: joshpencheon
@@ -292,7 +300,7 @@ file safety:
292
300
  lib/ndr_import/universal_importer_helper.rb:
293
301
  comments:
294
302
  reviewed_by: ollietulloch
295
- safe_revision: 830de0f8cb139c5f61525652b424423935cfc7ac
303
+ safe_revision: ee2e74e4ceda4ff48cbda6872a6bdf0874212c21
296
304
  lib/ndr_import/unmapped_data_error.rb:
297
305
  comments:
298
306
  reviewed_by: josh.pencheon
@@ -300,7 +308,7 @@ file safety:
300
308
  lib/ndr_import/version.rb:
301
309
  comments: another check?
302
310
  reviewed_by: ollietulloch
303
- safe_revision: 92d2d9d56f17c143709e25560d7620aaf147008f
311
+ safe_revision: d88ded7c260da37200610e4f0b204a4ea2e481f9
304
312
  lib/ndr_import/xml/table.rb:
305
313
  comments:
306
314
  reviewed_by: josh.pencheon
@@ -309,6 +317,10 @@ file safety:
309
317
  comments:
310
318
  reviewed_by: josh.pencheon
311
319
  safe_revision: 95e6ee9997d06471fe6f2f169c3c701471086371
320
+ test/csv_library_test.rb:
321
+ comments:
322
+ reviewed_by: ollietulloch
323
+ safe_revision: 6b8668967dbd42d7893a0fa5f0aa1ec1c11227e1
312
324
  test/file/acro_form_test.rb:
313
325
  comments:
314
326
  reviewed_by: josh.pencheon
@@ -327,16 +339,16 @@ file safety:
327
339
  safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
328
340
  test/file/excel_test.rb:
329
341
  comments:
330
- reviewed_by: josh.pencheon
331
- safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
342
+ reviewed_by: ollietulloch
343
+ safe_revision: 85a080deaa93e4220ad1bf566f29cbdac9b31c0f
332
344
  test/file/pdf_test.rb:
333
345
  comments:
334
346
  reviewed_by: josh.pencheon
335
347
  safe_revision: cb24ed3ea8116730d07f74546cd6fed0738b171d
336
348
  test/file/registry_test.rb:
337
349
  comments:
338
- reviewed_by: josh.pencheon
339
- safe_revision: 5cd2cd0b3a1e254d30d4acc28c6731825a1f84f5
350
+ reviewed_by: ollietulloch
351
+ safe_revision: 85a080deaa93e4220ad1bf566f29cbdac9b31c0f
340
352
  test/file/seven_zip_test.rb:
341
353
  comments:
342
354
  reviewed_by: josh.pencheon
@@ -553,6 +565,10 @@ file safety:
553
565
  comments:
554
566
  reviewed_by: timgentry
555
567
  safe_revision: 8c30f89f0562ab120769c166d4e93ff839c055f7
568
+ test/resources/sample_xlsm.xlsm:
569
+ comments:
570
+ reviewed_by: ollietulloch
571
+ safe_revision: 85a080deaa93e4220ad1bf566f29cbdac9b31c0f
556
572
  test/resources/sample_xlsx.xlsx:
557
573
  comments:
558
574
  reviewed_by: timgentry
@@ -1,17 +1,27 @@
1
1
  # This file allows us to choose the CSV library we want to use.
2
2
 
3
3
  require 'csv'
4
+ require 'active_support/deprecation'
5
+
4
6
  # Using relevant core CSV library.
5
- CSVLibrary = CSV
7
+ class CSVLibrary < CSV; end
6
8
 
7
9
  class << CSVLibrary
8
10
  # Is the library we're using FasterCSV?
9
11
  def fastercsv?
12
+ deprecate('if you desparately want fastercsv, please use it explicitly')
10
13
  not self.const_defined?(:Reader)
11
14
  end
12
15
 
13
16
  # Ensure that we can pass "mode" straight through the underlying IO object
17
+ #
18
+ # Note: this could likely be refactored now, as upstream support for something
19
+ # very similar was added:
20
+ #
21
+ # https://github.com/ruby/csv/commit/b4edaf2cf1aa36f5c6264c07514b66739b87ceee
22
+ #
14
23
  def foreach(path, **options, &block)
24
+ deprecate('CSV#foreach exists, with an optional `mode` argument')
15
25
  return to_enum(__method__, path, **options) unless block
16
26
  open(path, options.delete(:mode) || 'r', **options) do |csv|
17
27
  csv.each(&block)
@@ -19,20 +29,32 @@ class << CSVLibrary
19
29
  end
20
30
 
21
31
  def write_csv_to_string(data)
32
+ deprecate('write_csv_to_string -> generate')
22
33
  self.generate do |csv|
23
34
  data.each { |line| csv << line }
24
35
  end
25
36
  end
26
37
 
27
38
  def write_csv_to_file(data, filepath, mode = 'w')
39
+ deprecate('write_csv_to_file -> open')
28
40
  self.open(filepath, mode) do |csv|
29
41
  data.each { |line| csv << line }
30
42
  end
31
43
  end
32
44
 
33
45
  def read_csv_from_file(filepath)
46
+ deprecate('read_csv_from_file -> read')
34
47
  self.read(filepath)
35
48
  end
49
+
50
+ private
51
+
52
+ def deprecate(additional_message = nil)
53
+ ActiveSupport::Deprecation.warn(<<~MESSAGE)
54
+ CSVLibrary is deprecated, and will be removed in a future version of ndr_import.
55
+ Please use standard functionality provided by Ruby's CSV library (#{additional_message}).
56
+ MESSAGE
57
+ end
36
58
  end
37
59
 
38
60
  # Forward port CSV::Cell, as it is sometimes
@@ -90,14 +90,14 @@ module NdrImport
90
90
  case SafeFile.extname(path).downcase
91
91
  when '.xls'
92
92
  Roo::Excel.new(SafeFile.safepath_to_string(path))
93
- when '.xlsx'
93
+ when '.xlsm', '.xlsx'
94
94
  if @options['file_password']
95
95
  Roo::Excelx.new(StringIO.new(decrypted_file_string(path, @options['file_password'])))
96
96
  else
97
97
  Roo::Excelx.new(SafeFile.safepath_to_string(path))
98
98
  end
99
99
  else
100
- fail "Received file path with unexpected extension #{SafeFile.extname(path)}"
100
+ raise "Received file path with unexpected extension #{SafeFile.extname(path)}"
101
101
  end
102
102
  rescue Ole::Storage::FormatError => e
103
103
  # TODO: Do we need to remove the new_file after using it?
@@ -105,16 +105,14 @@ module NdrImport
105
105
  # try to load the .xls file as an .xlsx file, useful for sources like USOM
106
106
  # roo check file extensions in file_type_check (GenericSpreadsheet),
107
107
  # so we create a duplicate file in xlsx extension
108
- if /(.*)\.xls$/.match(path)
109
- new_file_name = SafeFile.basename(path).gsub(/(.*)\.xls$/, '\1_amend.xlsx')
110
- new_file_path = SafeFile.dirname(path).join(new_file_name)
111
- copy_file(path, new_file_path)
108
+ raise e.message unless /(.*)\.xls$/.match(path)
112
109
 
113
- load_workbook(new_file_path)
114
- else
115
- raise e.message
116
- end
117
- rescue => e
110
+ new_file_name = SafeFile.basename(path).gsub(/(.*)\.xls$/, '\1_amend.xlsx')
111
+ new_file_path = SafeFile.dirname(path).join(new_file_name)
112
+ copy_file(path, new_file_path)
113
+
114
+ load_workbook(new_file_path)
115
+ rescue RuntimeError, ::Zip::Error => e
118
116
  raise ["Unable to read the file '#{path}'", e.message].join('; ')
119
117
  end
120
118
 
@@ -133,6 +131,6 @@ module NdrImport
133
131
  end
134
132
  end
135
133
 
136
- Registry.register(Excel, 'xls', 'xlsx')
134
+ Registry.register(Excel, 'xls', 'xlsm', 'xlsx')
137
135
  end
138
136
  end
@@ -32,11 +32,11 @@ module NdrImport
32
32
  return enum_for(:delimited_rows, path, col_sep, liberal) unless block_given?
33
33
 
34
34
  safe_path = SafeFile.safepath_to_string(path)
35
- encodings = determine_encodings!(safe_path, col_sep, liberal)
35
+ options = determine_encodings!(safe_path, col_sep, liberal)
36
36
 
37
- # By now, we know `encodings` should let us read the whole
37
+ # By now, we know `options` should let us read the whole
38
38
  # file succesfully; if there are problems, we should crash.
39
- CSVLibrary.foreach(safe_path, **encodings) do |line|
39
+ CSV.foreach(safe_path, options.delete(:mode), **options) do |line|
40
40
  yield line.map(&:to_s)
41
41
  end
42
42
  end
@@ -46,7 +46,7 @@ module NdrImport
46
46
  # Derive the source encoding by trying all supported encodings.
47
47
  # Returns first set of working options, or raises if none could be found.
48
48
  def determine_encodings!(safe_path, col_sep, liberal)
49
- # delimiter encoding => # FasterCSV encoding string
49
+ # delimiter encoding => # CSV encoding string
50
50
  supported_encodings = {
51
51
  'UTF-8' => 'r:bom|utf-8',
52
52
  'Windows-1252' => 'r:windows-1252:utf-8'
@@ -67,14 +67,13 @@ module NdrImport
67
67
  begin
68
68
  options = {
69
69
  col_sep: (col_sep || ',').force_encoding(delimiter_encoding),
70
- liberal_parsing: liberal,
71
- mode: access_mode
70
+ liberal_parsing: liberal
72
71
  }
73
72
 
74
73
  row_num = 0
75
74
  # Iterate through the file; if we reach the end, this encoding worked:
76
- CSVLibrary.foreach(safe_path, **options) { |_line| row_num += 1 }
77
- return options
75
+ CSV.foreach(safe_path, access_mode, **options) { |_line| row_num += 1 }
76
+ return options.merge(mode: access_mode)
78
77
  rescue ArgumentError => e
79
78
  next if e.message =~ /invalid byte sequence/ # This encoding didn't work
80
79
  raise(e)
@@ -27,7 +27,6 @@ module NdrImport
27
27
  end
28
28
 
29
29
  def table_enumerators(filename)
30
- table_enumerators = {}
31
30
  table_enumerators = Hash.new { |hash, key| hash[key] = TableEnumProxy.new }
32
31
 
33
32
  extract(filename).each do |table, rows|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  # This stores the current version of the NdrImport gem
3
3
  module NdrImport
4
- VERSION = '9.0.3'.freeze
4
+ VERSION = '9.1.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndr_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.3
4
+ version: 9.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NCRS Development Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -365,6 +365,9 @@ executables:
365
365
  extensions: []
366
366
  extra_rdoc_files: []
367
367
  files:
368
+ - ".github/CODEOWNERS"
369
+ - ".github/workflows/lint.yml"
370
+ - ".github/workflows/test.yml"
368
371
  - ".gitignore"
369
372
  - ".hound.yml"
370
373
  - ".rubocop.yml"