Skip to content

Commit

Permalink
Adds configuration of wider url behaviours in cookiecutter (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair authored Dec 4, 2024
2 parents e3789bc + 39e29a9 commit d7e01fd
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
17 changes: 16 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"author_name": "",
"author_email": "",
"project_url": "",
"github_repo": "",
"sourcecode_url": "{{ 'https://github.com/' + cookiecutter.github_repo if cookiecutter.github_repo else '' }}",
"download_url": "https://pypi.org/project/{{ cookiecutter.package_name }}",
"documentation_url": "",
"changelog_url": "",
"issue_tracker_url": "{{ 'https://github.com/' + cookiecutter.github_repo + '/issues/' if cookiecutter.github_repo else '' }}",
"license": [
"BSD 3-Clause",
"GNU GPL v3+",
Expand All @@ -30,5 +36,14 @@
"docs/_templates",
"docs/_static",
".github/workflows/sub_package_update.yml"
]
],
"__prompts__" : {
"project_url": "Primary website for the project, leave blank for Sunpy Homepage",
"github_repo": "user/repo format GitHub repository. Leave blank if project is not on GitHub.",
"sourcecode_url": "URL for source code, i.e. https://github.com/...",
"download_url": "PyPI address for the project, optional",
"documentation_url": "Documentation URL, optional",
"changelog_url": "URL to the changelog, optional",
"issue_tracker_url": "URL to the issue tracker, optional"
}
}
25 changes: 23 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def cookiejar_no_examples(request):

@pytest.fixture(params=["bake_examples_compiled",
"bake_examples",
"bake_examples_compiled_dev_version"])
"bake_examples_compiled_dev_version",
"bake_examples_url_extensions"])
def cookiejar_examples(request):
"""
Templates rendered with the examples
Expand Down Expand Up @@ -93,7 +94,27 @@ def bake_examples_compiled_dev_version(cookies):
"author_name": "test",
"include_cruft_update_github_workflow": "y",
"use_extended_ruff_linting": "y",
})
"download_url": "https://github.com/sunpy/sunpy/archive/master.zip",
"issue_tracker_url": "https://github.com/sunpy/sunpy/issues",
})
return _handle_cookiecutter_errors(result)


@pytest.fixture
def bake_examples_url_extensions(cookies):
"""
setting url parameters
"""
result = cookies.bake(extra_context={
"author_name": "test",
"include_example_code": "y",
"project_url": "https://sunpy.org",
"github_repo": "sunpy/sunpy",
"download_url": "https://github.com/sunpy/sunpy/archive/master.zip",
"documentation_url": "https://sunpy.org/docs",
"changelog_url": "https://sunpy.org/changelog",
"issue_tracker_url": "https://github.com/sunpy/sunpy/issues"
})
return _handle_cookiecutter_errors(result)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
["bake_default",
"bake_examples",
"bake_examples_compiled",
"bake_examples_compiled_dev_version"])
"bake_examples_compiled_dev_version",
"bake_examples_url_extensions"])
def test_render_template(request, bake_name, pytestconfig):
bake = request.getfixturevalue(bake_name)
cached_dir = pytestconfig.getoption("--cookie-location")
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Main CI Workflow {% set default_python = '3.12' -%}
# Main CI Workflow {%- set default_python = '3.12' %}
name: CI

on:
Expand Down
21 changes: 19 additions & 2 deletions {{ cookiecutter.package_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,26 @@ docs = [
"packaging",
]

{%- if cookiecutter.project_url %}
[project.urls]
repository = "{{ cookiecutter.project_url }}"
{%- if cookiecutter.project_url %}
Homepage = "{{ cookiecutter.project_url }}"
{%- else %}
Homepage = "https://sunpy.org"
{%- endif %}
{%- if cookiecutter.sourcecode_url %}
"Source Code" = "{{ cookiecutter.sourcecode_url }}"
{%- endif %}
{%- if cookiecutter.download_url %}
Download = "{{ cookiecutter.download_url }}"
{%- endif %}
{%- if cookiecutter.documentation_url %}
Documentation = "{{ cookiecutter.documentation_url }}"
{%- endif %}
{%- if cookiecutter.changelog_url %}
Changelog = "{{ cookiecutter.changelog_url }}"
{%- endif %}
{%- if cookiecutter.issue_tracker_url %}
"Issue Tracker" = "{{ cookiecutter.issue_tracker_url }}"
{%- endif %}

[tool.setuptools]
Expand Down

0 comments on commit d7e01fd

Please sign in to comment.