Skip to content

Commit 08135b0

Browse files
delucchi-cmuhombit
andauthored
Install sphinx from docs/requirements. (#436)
* Install sphinx from docs/requirements. * Apply suggestions from code review Co-authored-by: Konstantin Malanchev <[email protected]> --------- Co-authored-by: Konstantin Malanchev <[email protected]>
1 parent 93b2459 commit 08135b0

File tree

6 files changed

+66
-48
lines changed

6 files changed

+66
-48
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
# -- sphinx-copybutton configuration ----------------------------------------
3333
## sets up the expected prompt text from console blocks, and excludes it from
3434
## the text that goes into the clipboard.
35-
copybutton_exclude = '.linenos, .gp'
35+
copybutton_exclude = ".linenos, .gp"
3636
copybutton_prompt_text = ">> "
3737

3838
## lets us suppress the copy button on select code blocks.
3939
copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre"
4040

4141
# -- Options for autosectionlabel -------------------------------------------------
4242

43-
autosectionlabel_prefix_document=True
43+
autosectionlabel_prefix_document = True
4444

4545
# -- Options for HTML output -------------------------------------------------
4646
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

python-project-template/.initialize_new_project.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ python -m pip install -e . > /dev/null
4444

4545
echo "Installing developer dependencies in local environment"
4646
python -m pip install -e .'[dev]' > /dev/null
47+
if [ -f docs/requirements.txt ]; then python -m pip install -r docs/requirements.txt; fi
4748

4849
echo "Installing pre-commit"
4950
pre-commit install > /dev/null

python-project-template/.setup_dev.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ python -m pip install -e . > /dev/null
3232

3333
echo "Installing developer dependencies in local environment"
3434
python -m pip install -e .'[dev]' > /dev/null
35+
if [ -f docs/requirements.txt ]; then python -m pip install -r docs/requirements.txt; fi
3536

3637
echo "Installing pre-commit"
3738
pre-commit install > /dev/null

python-project-template/pyproject.toml.jinja

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ classifiers = [
2020
dynamic = ["version"]
2121
requires-python = ">={{ python_versions[0] }}"
2222
dependencies = [
23-
{%- if include_notebooks %}
24-
"ipykernel", # Support for Jupyter notebooks
25-
{%- endif %}
2623
]
2724

2825
[project.urls]
@@ -31,36 +28,23 @@ dependencies = [
3128
# On a mac, install optional dependencies with `pip install '.[dev]'` (include the single quotes)
3229
[project.optional-dependencies]
3330
dev = [
34-
"pytest",
35-
"pytest-cov", # Used to report total code coverage
36-
"pre-commit", # Used to run checks before finalizing a git commit
37-
{%- if include_docs %}
38-
"sphinx", # Used to automatically generate documentation
39-
"sphinx-rtd-theme", # Used to render documentation
40-
"sphinx-autoapi", # Used to automatically generate api documentation
41-
{%- endif %}
42-
{%- if 'pylint' in enforce_style %}
43-
"pylint", # Used for static linting of files
31+
{%- if include_benchmarks %}
32+
"asv==0.6.1", # Used to compute performance benchmarks
4433
{%- endif %}
4534
{%- if 'black' in enforce_style %}
4635
"black", # Used for static linting of files
4736
{%- endif %}
48-
{%- if 'ruff_lint' in enforce_style or 'ruff_format' in enforce_style %}
49-
"ruff", # Used for static linting of files
50-
{%- endif %}
5137
{%- if mypy_type_checking != 'none' %}
5238
"mypy", # Used for static type checking of files
5339
{%- endif %}
54-
{%- if include_notebooks %}
55-
# if you add dependencies here while experimenting in a notebook and you
56-
# want that notebook to render in your documentation, please add the
57-
# dependencies to ./docs/requirements.txt as well.
58-
"nbconvert", # Needed for pre-commit check to clear output from Python notebooks
59-
"nbsphinx", # Used to integrate Python notebooks into Sphinx documentation
60-
"ipython", # Also used in building notebooks into Sphinx
40+
"pre-commit", # Used to run checks before finalizing a git commit
41+
{%- if 'pylint' in enforce_style %}
42+
"pylint", # Used for static linting of files
6143
{%- endif %}
62-
{%- if include_benchmarks %}
63-
"asv==0.6.1", # Used to compute performance benchmarks
44+
"pytest",
45+
"pytest-cov", # Used to report total code coverage
46+
{%- if 'ruff_lint' in enforce_style or 'ruff_format' in enforce_style %}
47+
"ruff", # Used for static linting of files
6448
{%- endif %}
6549
]
6650

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
sphinx
2-
sphinx-rtd-theme
3-
sphinx-autoapi
4-
sphinx-copybutton
51
{%- if include_notebooks %}
6-
nbsphinx
2+
ipykernel
73
ipython
8-
jupytext
94
jupyter
5+
jupytext
6+
nbconvert
7+
nbsphinx
108
{%- endif %}
9+
sphinx
10+
sphinx-autoapi
11+
sphinx-copybutton
12+
sphinx-rtd-theme

tests/test_package_creation.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ def successfully_created_project(result):
99
return result.exit_code == 0 and result.exception is None and result.project_dir.is_dir()
1010

1111

12+
def contains_required_files(result):
13+
required_files = [
14+
".copier-answers.yml",
15+
".git_archival.txt",
16+
".gitattributes",
17+
".gitignore",
18+
".pre-commit-config.yaml",
19+
".setup_dev.sh",
20+
"LICENSE",
21+
"pyproject.toml",
22+
"README.md",
23+
]
24+
all_found = True
25+
for file in required_files:
26+
if not (result.project_dir / file).is_file():
27+
all_found = False
28+
print("Required file not generated:", file)
29+
return all_found
30+
31+
1232
def directory_structure_is_correct(result, package_name="example_package"):
1333
"""Test to ensure that the default directory structure ws created correctly"""
1434
return (result.project_dir / f"src/{package_name}").is_dir() and (
@@ -65,14 +85,24 @@ def docs_build_successfully(result):
6585
virtual environment for the project.
6686
"""
6787

68-
sphinx_results = subprocess.run(
69-
["make", "html"],
70-
cwd=(result.project_dir / "docs"),
71-
)
88+
required_files = [
89+
".readthedocs.yml",
90+
]
91+
all_found = True
92+
for file in required_files:
93+
if not (result.project_dir / file).is_file():
94+
all_found = False
95+
print("Required file not generated:", file)
96+
return all_found
97+
98+
# sphinx_results = subprocess.run(
99+
# ["make", "html"],
100+
# cwd=(result.project_dir / "docs"),
101+
# )
102+
103+
# return sphinx_results.returncode == 0
72104

73-
return sphinx_results.returncode == 0
74105

75-
76106
def github_workflows_are_valid(result):
77107
"""Test to ensure that the GitHub workflows are valid"""
78108
workflows_results = subprocess.run(
@@ -95,14 +125,9 @@ def test_all_defaults(copie):
95125
result = copie.copy()
96126

97127
assert successfully_created_project(result)
98-
99128
assert directory_structure_is_correct(result)
100-
101129
assert not pylint_runs_successfully(result)
102-
103-
# make sure that some basic files were created
104-
assert (result.project_dir / "README.md").is_file()
105-
assert (result.project_dir / "pyproject.toml").is_file()
130+
assert contains_required_files(result)
106131

107132
# check to see if the README file was hydrated with copier answers.
108133
found_line = False
@@ -130,10 +155,9 @@ def test_use_black_and_no_example_modules(copie):
130155
result = copie.copy(extra_answers=extra_answers)
131156

132157
assert successfully_created_project(result)
133-
134158
assert directory_structure_is_correct(result)
135-
136159
assert pylint_runs_successfully(result)
160+
assert contains_required_files(result)
137161

138162
# make sure that the files that were not requested were not created
139163
assert not (result.project_dir / "src/example_package/example_module.py").is_file()
@@ -174,6 +198,7 @@ def test_code_style_combinations(copie, enforce_style):
174198
result = copie.copy(extra_answers=extra_answers)
175199
assert successfully_created_project(result)
176200
assert directory_structure_is_correct(result)
201+
assert contains_required_files(result)
177202
# black would still run successfully.
178203
assert black_runs_successfully(result)
179204

@@ -202,6 +227,7 @@ def test_smoke_test_notification(copie, notification):
202227
assert successfully_created_project(result)
203228
assert directory_structure_is_correct(result)
204229
assert black_runs_successfully(result)
230+
assert contains_required_files(result)
205231

206232

207233
@pytest.mark.parametrize(
@@ -226,6 +252,8 @@ def test_doc_combinations(copie, doc_answers):
226252
assert successfully_created_project(result)
227253
assert directory_structure_is_correct(result)
228254
assert black_runs_successfully(result)
255+
assert contains_required_files(result)
256+
assert docs_build_successfully(result)
229257
assert (result.project_dir / "docs").is_dir()
230258

231259

@@ -251,9 +279,10 @@ def test_doc_combinations_no_docs(copie, doc_answers):
251279
assert successfully_created_project(result)
252280
assert directory_structure_is_correct(result)
253281
assert black_runs_successfully(result)
282+
assert contains_required_files(result)
254283
assert not (result.project_dir / "docs").is_dir()
255284

256-
285+
257286
def test_github_workflows_schema(copie):
258287
"""Confirm the current GitHub workflows have valid schemas."""
259288
extra_answers = {
@@ -263,3 +292,4 @@ def test_github_workflows_schema(copie):
263292
result = copie.copy(extra_answers=extra_answers)
264293
initialize_git_project(result)
265294
assert github_workflows_are_valid(result)
295+
assert contains_required_files(result)

0 commit comments

Comments
 (0)