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

sile-typesetter / sile / 14684598788

26 Apr 2025 07:55PM UTC coverage: 29.023% (-36.3%) from 65.328%
14684598788

push

github

alerque
test(fonts): Update test to work on new ICU instead of old

5840 of 20122 relevant lines covered (29.02%)

379.34 hits per line

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

40.0
/core/use.lua
1
local function suggest_luarocks (module)
2
   local guessed_module_name = module:gsub(".*%.", "") .. ".sile"
×
3
   return ([[
×
4

5
      If the expected module is a 3rd party extension you may need to install
6
      it using LuaRocks. The details of how to do this are highly dependent on
7
      your system and preferred installation method, but as an example
8
      installing a 3rd party SILE module to a project-local tree where might
9
      look like this:
10

11
        luarocks --lua-version %s --tree lua_modules install %s
12

13
      This will install the LuaRock(s) to your project. Note this takes
14
      advantage of the fact that SILE checks for modules in the path
15
      'lua_modules' relative to the current input file by default. SILE also
16
      automatically checks the default system Lua path by default, so using
17
      `--global` will also work.
18

19
      In the event you use a different path to the LuaRocks tree, you must also
20
      set an environment variable to teach SILE about how to find the tree
21
      *before* it runs. This can be aided by asking LuaRocks to come up with a
22
      path and evaling the result in the shell before running SILE. This only
23
      needs to be done once in each shell, (obviously substituting 'path' for
24
      your actual path):
25

26
        eval $(luarocks --lua-version %s --tree path)
27

28
      Thereafter running `sile` as normal in the same shell should work as
29
      expected. This code can be used in your shell's initialization script
30
      to avoid having to do it manually in each new shell. This is true for
31
      user home directory installations using `--local` or any specific values
32
      for `--tree` other than 'lua_modules'.
33

34
      As an anternative to setting up environment variables when using a
35
      non-default tree location, you can use the `--luarocks-tree` option to
36
      add path(s) at runtime. This is simpler to type, but must be used on each
37
      and every invocation. The value for tree should be the same as used when
38
      installing the LuaRock(s), or an appropriate full path to the location
39
      used by `--local` (generally "$HOME/.luarocks"):
40

41
        sile --luarocks-tree path %s
42

43
    ]]):format(SILE.lua_version, guessed_module_name, SILE.lua_version, pl.stringx.join(" ", _G.arg or {}))
×
44
end
45

46
local function use (module, options, reload)
47
   local status, pack
48
   if type(module) == "string" then
8✔
49
      if module:match("/") then
8✔
50
         SU.warn(([[
×
51
            Module names should not include platform-specific path separators
52

53
            Using slashes like '/' or '\' in a module name looks like a path segment. This
54
            may appear to work in some cases, but breaks cross platform compatibility.
55
            Even on the platform with the matching separator, this can lead to packages
56
            getting loaded more than once because Lua will cache one each of the different
57
            formats. Please use '.' separators which are automatically translated to the
58
            correct platform one. For example a correct use statement would be:
59

60
              \use[module=%s] instead of \use[module=%s].
61
         ]]):format(module:gsub("/", "."), module))
×
62
      end
63
      status, pack = pcall(require, module)
8✔
64
      if not status then
8✔
65
         SU.error(
×
66
            ("Unable to use '%s':\n%s%s"):format(
×
67
               module,
68
               SILE.traceback and ("    Lua " .. pack) or "",
×
69
               suggest_luarocks(module)
×
70
            )
71
         )
72
      end
73
   elseif type(module) == "table" then
×
74
      pack = module
×
75
   end
76
   local name = pack._name
8✔
77
   local class = SILE.documentState.documentClass
8✔
78
   if not pack.type then
8✔
79
      SU.error("Modules must declare their type")
×
80
   elseif pack.type == "class" then
8✔
81
      SILE.classes[name] = pack
×
82
      if class then
×
83
         SU.error("Cannot load a class after one is already instantiated")
×
84
      end
85
      SILE.scratch.class_from_uses = pack
×
86
   elseif pack.type == "inputter" then
8✔
87
      SILE.inputters[name] = pack
×
88
      SILE.inputter = pack(options)
×
89
   elseif pack.type == "outputter" then
8✔
90
      SILE.outputters[name] = pack
×
91
      SILE.outputter = pack(options)
×
92
   elseif pack.type == "shaper" then
8✔
93
      SILE.shapers[name] = pack
×
94
      SILE.shaper = pack(options)
×
95
   elseif pack.type == "typesetter" then
8✔
96
      SILE.typesetters[name] = pack
×
97
      SILE.typesetter = pack(options)
×
98
   elseif pack.type == "pagebuilder" then
8✔
99
      SILE.pagebuilders[name] = pack
×
100
      SILE.pagebuilder = pack(options)
×
101
   elseif pack.type == "package" then
8✔
102
      SILE.packages[pack._name] = pack
8✔
103
      if class then
8✔
104
         class:loadPackage(pack, options, reload)
16✔
105
      else
106
         table.insert(SILE.input.preambles, { pack = pack, options = options })
×
107
      end
108
   end
109
end
110

111
return use
13✔
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