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

Add prompt for main python version #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"project_name": "example-project",
"project_slug": "{{cookiecutter.project_name|lower|replace('-', '_')}}",
"project_description": "This is a template repository for Python projects that use uv for their dependency management.",
"main_python_version": ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
"include_github_actions": ["y", "n"],
"publish_to_pypi": ["y", "n"],
"deptry": ["y", "n"],
Expand Down
10 changes: 7 additions & 3 deletions cookiecutter_uv/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import os
import sys
from pathlib import Path


def main() -> None:
cwd = os.path.dirname(__file__)
package_dir = os.path.abspath(os.path.join(cwd, ".."))
os.system(f"cookiecutter {package_dir}") # noqa: S605 | No injection, retrieving path in OS
package_dir = Path(__file__).parent.parent.absolute()
try:
os.system(f"cookiecutter {package_dir}") # noqa: S605 | No injection, retrieving path in OS
except KeyboardInterrupt:
sys.exit(0)
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uv.git
```

For an explanation of the prompt arguments, see
[Prompt Arguments](../prompt_arguments).
[Prompt Arguments](./prompt_arguments.md).

## Step 3: Set up your Github repository

Expand Down
12 changes: 6 additions & 6 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env python
from __future__ import annotations

import os
import shutil
from pathlib import Path

PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
PROJECT_DIRECTORY = Path.cwd().resolve()


def remove_file(filepath: str) -> None:
os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
def remove_file(__path: str) -> None:
(PROJECT_DIRECTORY / __path).unlink(missing_ok=True)


def remove_dir(filepath: str) -> None:
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, filepath))
def remove_dir(__path: str) -> None:
shutil.rmtree(PROJECT_DIRECTORY / __path, ignore_errors=True)


if __name__ == "__main__":
Expand Down
11 changes: 11 additions & 0 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@
)
# Exit to cancel project
sys.exit(1)

# Update python version matrix
"""
{% set python_version_matrix = [] %}
{% for ver in range(
cookiecutter.main_python_version|replace("3.", "")|int, 14
) %}
{% set _ = python_version_matrix.append("3." ~ ver) %}
{% endfor %}
{{ cookiecutter.update({"_python_version_matrix": python_version_matrix}) }}
"""
33 changes: 32 additions & 1 deletion tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shlex
import subprocess

from tests.utils import file_contains_text, is_valid_yaml, run_within_dir
from utils import file_contains_text, is_valid_yaml, run_within_dir


def test_bake_project(cookies):
Expand Down Expand Up @@ -143,3 +143,34 @@ def test_remove_release_workflow(cookies, tmp_path):
result = cookies.bake(extra_context={"publish_to_pypi": "n", "mkdocs": "n"})
assert result.exit_code == 0
assert not os.path.isfile(f"{result.project_path}/.github/workflows/on-release-main.yml")


def test_main_python_version_prompt(cookies, tmp_path):
with run_within_dir(tmp_path):
result = cookies.bake(extra_context={"main_python_version": "3.10"})

assert result.exit_code == 0

main_yml_file = f"{result.project_path}/.github/workflows/main.yml"
assert os.path.isfile(main_yml_file)
assert not file_contains_text(main_yml_file, "3.8")
assert not file_contains_text(main_yml_file, "3.9")
assert file_contains_text(main_yml_file, "3.10")
assert file_contains_text(main_yml_file, "3.11")
assert file_contains_text(main_yml_file, "3.12")

tox_ini_file = f"{result.project_path}/tox.ini"
assert os.path.isfile(tox_ini_file)
assert not file_contains_text(tox_ini_file, "3.8: py38")
assert not file_contains_text(tox_ini_file, "3.9: py39")
assert file_contains_text(tox_ini_file, "3.10: py310")
assert file_contains_text(tox_ini_file, "3.11: py311")
assert file_contains_text(tox_ini_file, "3.12: py312")

pyproject_toml_file = f"{result.project_path}/pyproject.toml"
assert os.path.isfile(pyproject_toml_file)
assert file_contains_text(pyproject_toml_file, ">=3.10,<4.0")
assert file_contains_text(pyproject_toml_file, "Programming Language :: Python :: 3.10")
assert file_contains_text(pyproject_toml_file, "Programming Language :: Python :: 3.11")
assert file_contains_text(pyproject_toml_file, "Programming Language :: Python :: 3.12")
assert file_contains_text(pyproject_toml_file, "Programming Language :: Python :: 3.13")
119 changes: 1 addition & 118 deletions uv.lock

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion {{cookiecutter.project_name}}/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
max_line_length = 120
max_line_length = 100

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,rst,ini}]
indent_style = space
indent_size = 4

[*.json]
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

[default.conf]
indent_style = space
indent_size = 2
10 changes: 6 additions & 4 deletions {{cookiecutter.project_name}}/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Main
name: CI

on:
push:
Expand Down Expand Up @@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: {{ cookiecutter._python_version_matrix }}
Copy link
Owner

Choose a reason for hiding this comment

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

I just tried it by selecting main_python_version 3.13, and I ended up with only 3.13? IMO we should still test for all current Python versions that are not EOL.

fail-fast: false
defaults:
run:
Expand All @@ -50,9 +50,11 @@ jobs:
run: uv run mypy

{% if cookiecutter.codecov == "y" %}
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.12
Copy link
Owner

Choose a reason for hiding this comment

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

shouldn't this be changed to the main python version?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, let me update it.

uses: codecov/codecov-action@v4
if: {% raw %}${{ matrix.python-version == '3.11' }}{% endraw %}
if: {% raw %}${{ matrix.python-version == '3.12' }}{% endraw %}
Copy link
Owner

Choose a reason for hiding this comment

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

shouldn't this be changed to the main python version?

env:
CODECOV_TOKEN: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %}
{%- endif %}

{%- if cookiecutter.mkdocs == "y" %}
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Install uv
FROM python:3.12-slim
FROM python:{{cookiecutter.main_python_version}}-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Change the working directory to the `app` directory
Expand Down
27 changes: 21 additions & 6 deletions {{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# {{cookiecutter.project_name}}

[![Release](https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
[![Build status](https://img.shields.io/github/actions/workflow/status/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/main.yml?branch=main)](https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/branch/main/graph/badge.svg)](https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
[![Commit activity](https://img.shields.io/github/commit-activity/m/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/commit-activity/m/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
[![License](https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
<p align="center">{{cookiecutter.project_description}}</p>

---

<p align="center">
<a href="https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}" alt="{{cookiecutter.project_name}} version">
</a>
<a href="https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml">
<img src="https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml/badge.svg" alt="{{cookiecutter.project_name}} CI status">
</a>
<a href="https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/branch/main/graph/badge.svg" alt="{{cookiecutter.project_name}} codecov">
</a>
<a href="https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}" alt="{{cookiecutter.project_name}} license">
</a>
</p>

{{cookiecutter.project_description}}

- **Github repository**: <https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/>
{% if cookiecutter.mkdocs == 'y' -%}

- **Documentation** <https://{{cookiecutter.author_github_handle}}.github.io/{{cookiecutter.project_name}}/>
{% endif %}

## Getting started with your project

Expand Down
22 changes: 17 additions & 5 deletions {{cookiecutter.project_name}}/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# {{cookiecutter.project_name}}

[![Release](https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
[![Build status](https://img.shields.io/github/actions/workflow/status/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/main.yml?branch=main)](https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml?query=branch%3Amain)
[![Commit activity](https://img.shields.io/github/commit-activity/m/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/commit-activity/m/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
[![License](https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})](https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}})
<p align="center">{{cookiecutter.project_description}}</p>

{{cookiecutter.project_description}}
---

<p align="center">
<a href="https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://img.shields.io/github/v/release/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}" alt="{{cookiecutter.project_name}} version">
</a>
<a href="https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml">
<img src="https://github.com/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/actions/workflows/main.yml/badge.svg" alt="{{cookiecutter.project_name}} CI status">
</a>
<a href="https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://codecov.io/gh/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}/branch/main/graph/badge.svg" alt="{{cookiecutter.project_name}} codecov">
</a>
<a href="https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}">
<img src="https://img.shields.io/github/license/{{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}" alt="{{cookiecutter.project_name}} license">
</a>
</p>
117 changes: 109 additions & 8 deletions {{cookiecutter.project_name}}/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ site_description: {{cookiecutter.project_description}}
site_author: {{cookiecutter.author}}
edit_uri: edit/main/docs/
repo_name: {{cookiecutter.author_github_handle}}/{{cookiecutter.project_name}}
copyright: Maintained by <a href="https://{{cookiecutter.author_github_handle}}.com">{{cookiecutter.author_github_handle}}</a>.
copyright: Maintained by <a href="https://github.com/{{cookiecutter.author_github_handle}}">{{cookiecutter.author}}</a>.

nav:
- Home: index.md
- Modules: modules.md
- API Reference:
- {{cookiecutter.project_slug}}.foo: api_reference/index.md
plugins:
- search
- mkdocstrings:
Expand All @@ -18,8 +19,51 @@ plugins:
paths: [{{cookiecutter.project_slug}}]
theme:
name: material
feature:
tabs: true
icon:
repo: fontawesome/brands/github
edit: material/pencil
view: material/eye
theme:
admonition:
note: octicons/tag-16
abstract: octicons/checklist-16
info: octicons/info-16
tip: octicons/squirrel-16
success: octicons/check-16
question: octicons/question-16
warning: octicons/alert-16
failure: octicons/x-circle-16
danger: octicons/zap-16
bug: octicons/bug-16
example: octicons/beaker-16
quote: octicons/quote-16
features:
- announce.dismiss
- content.action.edit
- content.action.view
- content.code.annotate
- content.code.copy
- content.code.select
- content.tabs.link
- content.tooltips
- header.autohide
- navigation.expand
- navigation.footer
- navigation.indexes
- navigation.instant
- navigation.instant.prefetch
- navigation.instant.progress
- navigation.prune
- navigation.sections
- navigation.tabs
# - navigation.tabs.sticky
- navigation.top
- navigation.tracking
- search.highlight
- search.share
- search.suggest
- toc.follow
# - toc.integrate
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
Expand All @@ -28,15 +72,72 @@ theme:
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
- scheme: slate
primary: black
accent: deep orange
toggle:
icon: material/brightness-4
name: Switch to light mode
icon:
repo: fontawesome/brands/github
font:
text: Roboto
code: Roboto Mono
# Extensions
markdown_extensions:
- abbr
- admonition
- pymdownx.details
- attr_list
- def_list
- footnotes
- md_in_html
- toc:
permalink: true
- pymdownx.arithmatex:
generic: true
- pymdownx.betterem:
smart_enable: all
- pymdownx.caret
- pymdownx.details
- pymdownx.emoji:
emoji_generator: !!python/name:material.extensions.emoji.to_svg
emoji_index: !!python/name:material.extensions.emoji.twemoji
- pymdownx.highlight:
pygments_style: monokai
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.keys
- pymdownx.magiclink:
normalize_issue_symbols: true
repo_url_shorthand: true
user: {{cookiecutter.author_github_handle}}
repo: {{cookiecutter.project_name}}
- pymdownx.mark
- pymdownx.smartsymbols
- pymdownx.snippets:
auto_append:
- includes/mkdocs.md
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format
- pymdownx.tabbed:
alternate_style: true
combine_header_slug: true
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.arithmatex:
generic: true

extra_javascript:
- javascripts/katex.js
- https://unpkg.com/katex@0/dist/katex.min.js
- https://unpkg.com/katex@0/dist/contrib/auto-render.min.js

extra_css:
- https://unpkg.com/katex@0/dist/katex.min.css

extra:
social:
Expand Down
Loading