Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: rename PDF/ePUB filename to valid one automatically #11198

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion readthedocs/projects/tasks/builds.py
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