Skip to content

Commit 40d6ff3

Browse files
committed
Add more advanced artefact file matching
Add file matching that accounts for project names that include spaces and is case insensitive. This is to match how latex and other builders generate their artefacts. Use only the project name from the build configuration rather than the configuration on each branch to account for when the project name has been changed to display differently.
1 parent c2903a9 commit 40d6ff3

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

sphinx_multiversion/main.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def main(argv=None):
288288
)
289289
metadata[gitref.name] = {
290290
"name": gitref.name,
291+
"project": current_config.project,
291292
"version": current_config.version,
292293
"release": current_config.release,
293294
"rst_prolog": current_config.rst_prolog,
@@ -408,7 +409,7 @@ def main(argv=None):
408409
artefact_dir = "{}/artefacts".format(data["outputdir"])
409410
os.makedirs(artefact_dir, exist_ok=True)
410411
filename = "{project}_docs-{version}".format(
411-
project=current_config.project,
412+
project=config.project.replace(" ", ""),
412413
version=version_name.replace("/", "-"),
413414
)
414415

@@ -425,22 +426,27 @@ def main(argv=None):
425426
else:
426427
# Find files matching project-name.extension, e.g.
427428
# example.pdf in the target build directory
428-
build_artefacts = glob.glob(
429-
"{build_dir}/**/{project}.{extension}".format(
430-
build_dir=target_build_dir,
431-
project=current_config.project,
432-
extension=download_format,
429+
candidate_files = glob.glob(
430+
"{build_dir}/**/*.{extension}".format(
431+
build_dir=target_build_dir, extension=download_format,
433432
),
434433
recursive=True,
435434
)
435+
build_file_pattern = "{project}.{extension}".format(
436+
project=config.project.replace(" ", ""),
437+
extension=download_format,
438+
)
439+
build_artefacts = [
440+
x
441+
for x in candidate_files
442+
if pathlib.Path(x.lower()).name == build_file_pattern.lower()
443+
]
436444
if len(build_artefacts) == 0:
437445
logger.warning(
438446
(
439-
"Build artefact {project}.{extension} "
440-
"not found."
447+
"Build artefact {project}" "not found."
441448
).format(
442-
project=current_config.project,
443-
extension=download_format,
449+
project=build_file_pattern.lower(),
444450
)
445451
)
446452
elif len(build_artefacts) > 1:

sphinx_multiversion/sphinx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def apathto(self, build_target_name, build_target):
160160
artefact_dir = "artefacts"
161161

162162
filename = "{project}_docs-{version}".format(
163-
project=self.app.config.project,
163+
project=self.app.config.project.replace(" ", ""),
164164
version=self.current_version_name.replace("/", "-"),
165165
)
166166

0 commit comments

Comments
 (0)