Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ The rules for this file:
- Oliver Beckstein \<@orbeckst\>

**2024**
- Lawson Woods \<@ljwoods2\>
- Lawson Woods \<@ljwoods2\>

**2024**
- Estefania Barreto-Ojeda \<@ojeda-e\>
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The rules for this file:
- RMeli
- orbeckst
- ljwoods2
- ojeda-e

### Added
<!-- New added features -->
Expand All @@ -42,6 +43,7 @@ The rules for this file:

### Fixed
<!-- Bug fixes -->
- Build docs by fixing `repo_name` cookiecutter cli (Issue #157, PR #158)
- Updated mambaforge version in `readthedocs.yaml` (Issue #132, PR #133)
- Switched deprecated pkg_resources to use importlib (PR #122, Issue #121)
- Fixed pypi_check with lowercase (PR #118, Issue #112)
Expand Down
12 changes: 8 additions & 4 deletions docs/scripts/generate_cookiecutter_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
GENERATED_PATH = COOKIECUTTER_PATH / "docs" / "source" / "generated"


def repo_name_from_project_name(project_name: str) -> str:
"""Same reference name as in ``repo_name`` default in ``cookiecutter.json``."""
return project_name.lower().replace(" ", "_").replace("-", "_")


def flatten_dict(dct, key=tuple()):
"""Turn a nested dict into a flat dict, with keys as tuples."""
for k, v in dct.items():
Expand Down Expand Up @@ -78,15 +83,16 @@ def label_files(self, output) -> str:
class ExampleRepositoryDocumentation:

def __init__(self):
self.repo_name = "example-repository"
self.project_name = "My Project Name"
self.repo_name = repo_name_from_project_name(self.project_name)
self.package_name = "package_name"
self.example_repo_path = GENERATED_PATH / self.repo_name
self.cookiecutter_cli_log = GENERATED_PATH / "cookiecutter_cli.log"
self.cookie_tree = GENERATED_PATH / "cookie_tree.txt"

def generate_cli_output(self) -> str:
inputs = [
"My Project Name", # project_name
self.project_name, # project_name
self.repo_name, # repo_name
self.package_name, # package_name
"A package to do MD analysis", # description
Expand All @@ -97,8 +103,6 @@ def generate_cli_output(self) -> str:
"", # dependency_source
"", # include_ReadTheDocs
"MyAnalysisClass", # template_analysis_class
""
""
]

with tempfile.TemporaryDirectory() as tmpdir:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ["_build", "Thumbs.db",
".DS_Store", "generated/example-repository/*"]
".DS_Store", "generated/project_name/*"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The :ref:`options-label` section below provides more details on these options,
default values (if applicable), what they mean, and what they affect.

Running the cookiecutter will the above responses will generate the following
output skeleton, (as well as initialise a git repository `example-repository`,
output skeleton, (as well as initialise a git repository `project_name`,
make an initial commit, and add a "0.0.0" tag to set the initial version):

.. literalinclude:: generated/cookie_tree.txt
Expand Down
27 changes: 27 additions & 0 deletions tests/test_generate_cookiecutter_cli.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be overkilling it with this. IMO when in doubt, better add a test.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Tests for docs/scripts/generate_cookiecutter_cli helpers."""

import pathlib
import sys

import pytest

_DOCS_SCRIPTS = pathlib.Path(__file__).resolve().parents[1] / "docs" / "scripts"
sys.path.insert(0, str(_DOCS_SCRIPTS))

from generate_cookiecutter_cli import repo_name_from_project_name # noqa: E402


@pytest.mark.parametrize(
("project_name", "expected_repo_name"),
[
("A Project Name", "a_project_name"),
("same_name_as_project", "same_name_as_project"),
("Test-Project Name", "test_project_name"),
],
)
def test_repo_name_from_project_name_matches_cookiecutter_default(
project_name: str,
expected_repo_name: str,
) -> None:
"""Mirrors ``repo_name`` in cookiecutter.json (slug from ``project_name``)."""
assert repo_name_from_project_name(project_name) == expected_repo_name