Skip to content

Commit 19b2ef5

Browse files
authored
Merge pull request #4878 from kprussing/feature/latex-scanner-requirepackage
Add RequirePackage to the scanned macros for recursive LaTeX scanning
2 parents b3d8b33 + c7d5453 commit 19b2ef5

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
7878
- Fix typos in preface, Chapter 6, Chapter 9 and Chapter 10 of User Guide
7979
- Fix broken links in Chapter 1 of User Guide
8080

81+
From Keith F. Prussing:
82+
- Add RequiredPackage to the LaTeX scanner for recursive scanning of
83+
custom LaTeX packages.
8184

8285
From Mats Wichmann:
8386
- Introduce some unit tests for the file locking utility routines

RELEASE.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ long function signature lines, and some linting-inspired cleanups.
102102
- zip tool now uses zipfile module's "from_file" method to populate ZipInfo
103103
records, rather than doing manually.
104104

105-
105+
- Add RequiredPackage to the LaTeX scanner for recursive scanning of custom
106+
LaTeX packages.
106107

107108
PACKAGING
108109
---------

SCons/Scanner/LaTeX.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class LaTeX(ScannerBase):
165165
'addsectionbib': 'BIBINPUTS',
166166
'makeindex': 'INDEXSTYLE',
167167
'usepackage': 'TEXINPUTS',
168+
'RequirePackage': 'TEXINPUTS',
168169
'usetheme': 'TEXINPUTS',
169170
'usecolortheme': 'TEXINPUTS',
170171
'usefonttheme': 'TEXINPUTS',
@@ -193,7 +194,8 @@ def __init__(self, name, suffixes, graphics_extensions, *args, **kwargs) -> None
193194
| addbibresource
194195
| addglobalbib
195196
| addsectionbib
196-
| usepackage
197+
| usepackage(?:\s*\[[^\]]+\])?
198+
| RequirePackage(?:\s*\[[^\]]+\])?
197199
| use(?:|color|font|inner|outer)theme(?:\s*\[[^\]]+\])?
198200
)
199201
\s*{([^}]*)} # first arg
@@ -276,7 +278,7 @@ def _latex_names(self, include_type, filename):
276278
base, ext = os.path.splitext( filename )
277279
if ext == "":
278280
return [filename + '.bib']
279-
if include_type == 'usepackage':
281+
if include_type in ('usepackage', 'RequirePackage'):
280282
base, ext = os.path.splitext( filename )
281283
if ext == "":
282284
return [filename + '.sty']
@@ -417,7 +419,7 @@ def scan_recurse(self, node, path=()):
417419
if n is None:
418420
# Do not bother with 'usepackage' warnings, as they most
419421
# likely refer to system-level files
420-
if inc_type != 'usepackage' or re.match("use(|color|font|inner|outer)theme", inc_type):
422+
if inc_type not in ('usepackage', 'RequirePackage') or re.match("use(|color|font|inner|outer)theme", inc_type):
421423
SCons.Warnings.warn(
422424
SCons.Warnings.DependencyWarning,
423425
"No dependency generated for file: %s "

SCons/Scanner/LaTeXTests.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@
101101

102102
test.write(['subdir2', 'inc3.tex'], "\\input{inc2}\n")
103103

104+
test.write('test7.latex',r"""
105+
\usepackage{scons}
106+
""")
107+
test.write('scons.sty',r"""
108+
\RequirePackage[option]{other}
109+
\RequirePackage{system}
110+
""")
111+
test.write('other.sty', "\n")
112+
104113
# define some helpers:
105114
# copied from CTest.py
106115
class DummyEnvironment(collections.UserDict):
@@ -200,7 +209,7 @@ def runTest(self) -> None:
200209
('color', 'font', 'inner', 'outer', '')]
201210
deps_match(self, deps, files)
202211

203-
class LaTeXScannerTestCase5(unittest.TestCase):
212+
class LaTeXScannerTestCase6(unittest.TestCase):
204213
def runTest(self) -> None:
205214
env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
206215
s = SCons.Scanner.LaTeX.LaTeXScanner()
@@ -217,5 +226,14 @@ def runTest(self) -> None:
217226
else:
218227
deps_match(self, deps, files)
219228

229+
class LaTeXScannerTestCase7(unittest.TestCase):
230+
def runTest(self) -> None:
231+
env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
232+
s = SCons.Scanner.LaTeX.LaTeXScanner()
233+
path = s.path(env)
234+
deps = s(env.File('test7.latex'), env, path)
235+
files = ["other.sty", "scons.sty"]
236+
deps_match(self, deps, files)
237+
220238
if __name__ == "__main__":
221239
unittest.main()

0 commit comments

Comments
 (0)