Skip to content

Commit

Permalink
Merge pull request #2573 from melissa-kun-li/fix-sphinx-upload-docs
Browse files Browse the repository at this point in the history
Fix error uploading Sphinx doc with upload_docs. Fixes #1060
  • Loading branch information
jaraco committed Feb 20, 2021
2 parents c121d28 + ba68d13 commit d31f7f0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.d/2573.change.rst
@@ -0,0 +1,2 @@
Fixed error in uploading a Sphinx doc with the :code:`upload_docs` command. An html builder will be used.
Note: :code:`upload_docs` is deprecated for PyPi, but is supported for other sites -- by :user:`melissa-kun-li`
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -58,6 +58,7 @@ testing =
pip>=19.1 # For proper file:// URLs support.
jaraco.envs
pytest-xdist
sphinx

docs =
# Keep these in sync with docs/requirements.txt
Expand Down
8 changes: 4 additions & 4 deletions setuptools/command/upload_docs.py
Expand Up @@ -2,7 +2,7 @@
"""upload_docs
Implements a Distutils 'upload_docs' subcommand (upload documentation to
PyPI's pythonhosted.org).
sites other than PyPi such as devpi).
"""

from base64 import standard_b64encode
Expand Down Expand Up @@ -31,7 +31,7 @@ class upload_docs(upload):
# supported by Warehouse (and won't be).
DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi/'

description = 'Upload documentation to PyPI'
description = 'Upload documentation to sites other than PyPi such as devpi'

user_options = [
('repository=', 'r',
Expand Down Expand Up @@ -59,15 +59,15 @@ def finalize_options(self):
if self.upload_dir is None:
if self.has_sphinx():
build_sphinx = self.get_finalized_command('build_sphinx')
self.target_dir = build_sphinx.builder_target_dir
self.target_dir = dict(build_sphinx.builder_target_dirs)['html']
else:
build = self.get_finalized_command('build')
self.target_dir = os.path.join(build.build_base, 'docs')
else:
self.ensure_dirname('upload_dir')
self.target_dir = self.upload_dir
if 'pypi.python.org' in self.repository:
log.warn("Upload_docs command is deprecated. Use RTD instead.")
log.warn("Upload_docs command is deprecated for PyPi. Use RTD instead.")
self.announce('Using upload directory %s' % self.target_dir)

def create_zipfile(self, filename):
Expand Down
1 change: 1 addition & 0 deletions setuptools/tests/requirements.txt
Expand Up @@ -11,3 +11,4 @@ paver; python_version>="3.6"
futures; python_version=="2.7"
pip>=19.1 # For proper file:// URLs support.
jaraco.envs
sphinx
41 changes: 41 additions & 0 deletions setuptools/tests/test_sphinx_upload_docs.py
@@ -0,0 +1,41 @@
import pytest
import os

from setuptools.command.upload_docs import upload_docs
from setuptools.dist import Distribution


@pytest.fixture
def sphinx_doc_sample_project(tmpdir_cwd):
# setup.py
with open('setup.py', 'wt') as f:
f.write('from setuptools import setup; setup()\n')

os.makedirs('build/docs')

# A test conf.py for Sphinx
with open('build/docs/conf.py', 'w') as f:
f.write("project = 'test'")

# A test index.rst for Sphinx
with open('build/docs/index.rst', 'w') as f:
f.write(".. toctree::\
:maxdepth: 2\
:caption: Contents:")


@pytest.mark.usefixtures('sphinx_doc_sample_project')
class TestSphinxUploadDocs:
def test_sphinx_doc(self):
params = dict(
name='foo',
packages=['test'],
)
dist = Distribution(params)

cmd = upload_docs(dist)

cmd.initialize_options()
assert cmd.upload_dir is None
assert cmd.has_sphinx() is True
cmd.finalize_options()

0 comments on commit d31f7f0

Please sign in to comment.