• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 6876872636

15 Nov 2023 11:50AM UTC coverage: 68.751% (+6.5%) from 62.266%
6876872636

Pull #1904

github

web-flow
Merge pull request #1908 from alerque/reload-package
Pull Request #1904: Merge develop into master (commit to next release being breaking)

44 of 103 new or added lines in 14 files covered. (42.72%)

191 existing lines in 7 files now uncovered.

10699 of 15562 relevant lines covered (68.75%)

6786.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.85
/packages/base.lua
1
local package = pl.class()
73✔
2
package.type = "package"
73✔
3
package._name = "base"
73✔
4

5
package._initialized = false
73✔
6
package.class = nil
73✔
7

8
-- For shimming packages that used to have legacy exports
9
package.exports = {}
73✔
10

11
local function script_path ()
12
  local src = debug.getinfo(3, "S").source:sub(2)
448✔
13
  local base = src:match("(.*[/\\])")
448✔
14
  return base
448✔
15
end
16

17
local settingDeclarations = { }
73✔
18
local rawhandlerRegistrations = {}
73✔
19
local commandRegistrations = { }
73✔
20

21
function package:_init (_, reload)
73✔
22
  self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
448✔
23
  if not self.class then
448✔
24
    SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
×
25
  end
26
  self.basedir = script_path()
896✔
27
  -- Note string.format(%p) would be nicer than tostring() but only LuaJIT and Lua 5.4 support it
28
  local settingsDeclarator = tostring(self.declareSettings)
448✔
29
  if reload or not settingDeclarations[settingsDeclarator] then
448✔
30
    settingDeclarations[settingsDeclarator] = true
104✔
31
    self:declareSettings()
104✔
32
  end
33
  local rawhandlerRegistrator = tostring(self.registerRawHandlers)
448✔
34
  if reload or not rawhandlerRegistrations[rawhandlerRegistrator] then
448✔
35
    rawhandlerRegistrations[rawhandlerRegistrator] = true
76✔
36
    self:registerRawHandlers()
76✔
37
  end
38
  local commandRegistrator = tostring(self.registerCommands)
448✔
39
  if reload or not commandRegistrations[commandRegistrator] then
448✔
40
    commandRegistrations[commandRegistrator] = true
410✔
41
    self:registerCommands()
410✔
42
  end
43
end
44

45
function package:_post_init ()
73✔
46
  self._initialized = true
449✔
47
end
48

49
function package.declareSettings (_) end
146✔
50

51
function package.registerRawHandlers (_) end
146✔
52

53
function package:loadPackage (packname, options, reload)
73✔
54
  return self.class:loadPackage(packname, options, reload)
170✔
55
end
56

57
function package:reloadPackage (packname, options)
73✔
NEW
58
  return self.class:reloadPackage(packname, options)
×
59
end
60

61
function package.registerCommands (_) end
89✔
62

63
-- This gives us a hook to match commands with the packages that registered
64
-- them as opposed to core commands or class-provided commands
65
function package:registerCommand (name, func, help, pack)
73✔
66
  self.class:registerCommand(name, func, help, pack)
1,825✔
67
end
68
function package:registerRawHandler (format, callback)
73✔
69
  self.class:registerRawHandler(format, callback)
3✔
70
end
71

72
-- Using this rather than doing the work directly will give us a way to
73
-- un-export them if we ever need to unload modules and revert functions
74
function package:export (name, func)
73✔
75
  self.class[name] = func
457✔
76
end
77

78
-- Shims for two possible kinds of legacy exports: blind direct stuffing into
79
-- the class but not expecting to be called as a method AND the exports table
80
-- to package modules...
81

82
local _deprecate_class_funcs = [[
83
  Please explicitly use functions provided by packages by referencing
84
  them in the document class's list of loaded packages rather than the
85
  legacy solution that added non-method functions to the class.]]
73✔
86

87
local _deprecate_exports_table = [[
88
  Please explicitly use functions provided by packages by referencing
89
  them in the document class's list of loaded packages rather than the
90
  legacy solution of calling them from an exports table.]]
73✔
91

92
function package:deprecatedExport (name, func, noclass, notable)
73✔
93

94
  if not noclass then
478✔
95
    self.class[name] = function (...)
478✔
96
      -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
97
      local inputs = {...}
4✔
98
      -- local inputs = table.unpack({...}, 1, select("#", ...))
99
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "class" then
4✔
100
        table.insert(inputs, 1, self.class)
×
101
      end
102
      SU.deprecated(("class.%s"):format(name),
8✔
103
                    ("class.packages.%s:%s"):format(self._name, name),
4✔
104
                    "0.14.0", "0.16.0", _deprecate_class_funcs)
4✔
105
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
4✔
106
    end
107
  end
108

109
  if not notable then
478✔
110
    self.exports[name] = function (...)
478✔
111
      local inputs = {...}
×
112
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "package" then
×
113
        table.insert(inputs, 1, self)
×
114
      end
115
      SU.deprecated(("require('packages.%s').exports.%s"):format(self._name, name),
×
116
                    ("class.packages.%s:%s"):format(self._name, name),
×
117
                    "0.14.0", "0.16.0", _deprecate_exports_table)
×
118
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
×
119
    end
120
  end
121

122
end
123

124
return package
73✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc