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

Fix error uploading Sphinx doc with upload_docs. Fixes #1060 #2573

Merged
merged 4 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/2573.change.rst
Original file line number Diff line number Diff line change
@@ -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`
melissa-kun-li marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
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
7 changes: 5 additions & 2 deletions setuptools/command/upload_docs.py
Original file line number Diff line number Diff line change
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).
melissa-kun-li marked this conversation as resolved.
Show resolved Hide resolved
"""

from base64 import standard_b64encode
Expand Down Expand Up @@ -59,7 +59,10 @@ 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
for (builder, builder_dir) in build_sphinx.builder_target_dirs:
if builder == "html":
self.target_dir = builder_dir
break
jaraco marked this conversation as resolved.
Show resolved Hide resolved
else:
build = self.get_finalized_command('build')
self.target_dir = os.path.join(build.build_base, 'docs')
Expand Down
1 change: 1 addition & 0 deletions setuptools/tests/requirements.txt
Original file line number Diff line number Diff line change
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
42 changes: 42 additions & 0 deletions setuptools/tests/test_sphinx_upload_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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')
@pytest.mark.usefixtures('user_override')
melissa-kun-li marked this conversation as resolved.
Show resolved Hide resolved
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()