Skip to content

Commit

Permalink
Build: rename PDF/ePUB filename to valid one automatically
Browse files Browse the repository at this point in the history
Currently, we _require_ the user to save the PDF or ePUB file with a pretty
specific filename: `{project.slug}-{version.slug}.{extension}`. This has caused
a lot of confusions to users.

Since we only support 1 file for PDF/ePUB for now, we can rename this file to
the valid filename automatically.

Closes #10873
  • Loading branch information
humitos committed Mar 8, 2024
1 parent 4770af1 commit fd209e1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
rebuilding documentation.
"""
import os
import shutil
import signal
import socket
import subprocess
Expand Down Expand Up @@ -606,7 +607,8 @@ def get_valid_artifact_types(self):
# These output format does not support multiple files yet.
# In case multiple files are found, the upload for this format is not performed.
if artifact_type in ARTIFACT_TYPES_WITHOUT_MULTIPLE_FILES_SUPPORT:
artifact_format_files = len(os.listdir(artifact_directory))
list_dir = os.listdir(artifact_directory)
artifact_format_files = len(list_dir)
if artifact_format_files > 1:
log.error(
"Multiple files are not supported for this format. "
Expand All @@ -627,6 +629,15 @@ def get_valid_artifact_types(self):
},
)

# TODO: improve this renaming :)
if artifact_format_files == 1:
filename = list_dir[0]
_, extension = filename.rsplit(".")
shutil.mv(
list_dir[0],
f"{self.data.project.slug}-{self.data.version.slug}.{extension}",
)

# If all the conditions were met, the artifact is valid
valid_artifacts.append(artifact_type)

Expand Down

0 comments on commit fd209e1

Please sign in to comment.