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

sile-typesetter / sile / 14727381542

29 Apr 2025 06:54AM UTC coverage: 32.062% (+0.3%) from 31.768%
14727381542

push

github

alerque
chore(shapers): Remove workarounds for HB versions we haven't supported in ages

6464 of 20161 relevant lines covered (32.06%)

2446.39 hits per line

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

60.0
/core/require.lua
1
local function require_ (dependency, pathprefix, deprecation_ack)
2
   if pathprefix and not deprecation_ack then
97✔
3
      local notice = string.format(
×
4
         [[
×
5
  Please don't use the path prefix mechanism; it was intended to provide
6
  alternate paths to override core components but never worked well and is
7
  causing portability problems. Just use Lua idiomatic module loading:
8
      SILE.require("%s", "%s") → SILE.require("%s.%s")]],
9
         dependency,
10
         pathprefix,
11
         pathprefix,
12
         dependency
13
      )
14
      SU.deprecated("SILE.require", "SILE.require", "0.13.0", nil, notice)
×
15
   end
16
   dependency = dependency:gsub(".lua$", "")
97✔
17
   local status, lib
18
   if pathprefix then
97✔
19
      -- Note this is not a *path*, it is a module identifier:
20
      -- https://github.com/sile-typesetter/sile/issues/1861
21
      status, lib = pcall(require, pl.stringx.join(".", { pathprefix, dependency }))
194✔
22
   end
23
   if not status then
97✔
24
      local prefixederror = lib
×
25
      status, lib = pcall(require, dependency)
×
26
      if not status then
×
27
         SU.error(
×
28
            ("Unable to find module '%s'%s"):format(
×
29
               dependency,
30
               SILE.traceback and ((pathprefix and "\n  " .. prefixederror or "") .. "\n  " .. lib) or ""
×
31
            )
32
         )
33
      end
34
   end
35
   local class = SILE.documentState.documentClass
97✔
36
   if not class and not deprecation_ack then
97✔
37
      SU.warn(string.format(
×
38
         [[
×
39
            SILE.require() is only supported in documents, packages, or class init
40

41
            It will not function fully before the class is instantiated. Please just use
42
            the Lua require() function directly:
43

44
              SILE.require("%s") → require("%s")
45
         ]],
46
         dependency,
47
         dependency
48
      ))
49
   end
50
   if type(lib) == "table" and class then
97✔
51
      if lib.type == "package" then
×
52
         lib(class)
×
53
      else
54
         class:initPackage(lib)
×
55
      end
56
   end
57
   return lib
97✔
58
end
59

60
local function resolveFile (filename, pathprefix)
61
   local candidates = {}
100✔
62
   -- Start with the raw file name as given prefixed with a path if requested
63
   if pathprefix then
100✔
64
      candidates[#candidates + 1] = pl.path.join(pathprefix, "?")
×
65
   end
66
   -- Also check the raw file name without a path
67
   candidates[#candidates + 1] = "?"
100✔
68
   -- Iterate through the directory of the master file, the SILE_PATH variable, and the current directory
69
   -- Check for prefixed paths first, then the plain path in that fails
70
   if SILE.masterDir then
100✔
71
      for path in SU.gtoke(SILE.masterDir .. ";" .. tostring(os.getenv("SILE_PATH")), ";") do
900✔
72
         if path.string and path.string ~= "nil" then
700✔
73
            if pathprefix then
400✔
74
               candidates[#candidates + 1] = pl.path.join(path.string, pathprefix, "?")
×
75
            end
76
            candidates[#candidates + 1] = pl.path.join(path.string, "?")
800✔
77
         end
78
      end
79
   end
80
   -- Return the first candidate that exists, also checking the .sil suffix
81
   local path = table.concat(candidates, ";")
100✔
82
   local resolved, err = package.searchpath(filename, path, "/")
100✔
83
   if resolved then
100✔
84
      if SILE.makeDeps then
100✔
85
         SILE.makeDeps:add(resolved)
100✔
86
      end
87
   elseif SU.debugging("paths") then
×
88
      SU.debug("paths", ("Unable to find file '%s': %s"):format(filename, err))
×
89
   end
90
   return resolved
100✔
91
end
92

93
return {
195✔
94
   require = require_,
195✔
95
   resolveFile = resolveFile,
195✔
96
}
195✔
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

© 2025 Coveralls, Inc