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

sile-typesetter / sile / 14284237390

05 Apr 2025 05:33PM UTC coverage: 63.158% (+31.8%) from 31.375%
14284237390

push

github

web-flow
Merge pull request #2248 from alerque/class-warfare

Normalize module layout across all module types

257 of 350 new or added lines in 14 files covered. (73.43%)

71 existing lines in 11 files now uncovered.

13670 of 21644 relevant lines covered (63.16%)

3070.68 hits per line

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

44.44
/core/use.lua
1
local function suggest_luarocks (module)
NEW
2
   local guessed_module_name = module:gsub(".*%.", "") .. ".sile"
×
NEW
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

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

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