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

context 2.0 - Advanced features #1566

Closed
wants to merge 75 commits into from

Conversation

louisdegaste
Copy link

This is a continuation of eruber's PR #1008 to implement a new cookiecutter context format with the following features:

  • Use of JSON Schema to define the requirements of cookiecutter.json (also works with cookiecutter.yml)
  • New Variables structure with:
    • Different types: string, boolean, yes_no, int, float, uuid, json
    • Regex validation: checks if a prompt entry matches a user defined regex expression and asks again on failure
    • Skipping options: if a certain value has been entered, skip to the next or to a specific question
    • Variable description: extended description in verbose mode
    • Hidden input prompt: to enter sensitive information like access tokens
  • Versioning for the schema to facilitate future changes
  • Requirements in cookiecutter.json (python version, cookiecutter version)
    This implementation is compatible with the old cookiecutter context format (we call it schema 1.0).
    It contains a single breaking change: If we have a field named "version" in cookiecutter.json, it will be interpreted as the schema version if it corresponds to an existing schema version number. Because schema 1.0 had no pre-defined structure, it is impossible to avoid this kind of collision, but the issue should be quite rare in practice.
Sample cookiecutter.yml
version: '2.0'

requires:
  cookiecutter: '2.0.0'
  python: '>=3.8'

template:
  name: awesome-template
  version: '0.1'
  description: this is the best cookiecutter template ever, you should totally use it
  authors:
    - Jane Doe <jane@example.org>
    - John Doe <jane@example.org>
  license: Apache 2.0
  keywords:
    - awesome
    - python
  url: https://github.com/...
  variables:
    - name: full_name
      default: Jane Doe
      prompt: What's your name?
      description: Please enter your full name. It will be displayed in the README file
        and used for the PyPI package definition.
      type: string
    - name: email
      default: jane@example.org
      prompt: What's your email?
      description: Please enter an email address for the meta information in setup.py.
      type: string
    - name: project_name
      default: my-project
      prompt: What's the project name?
      description: Please enter a name for your project.
      type: string
    - name: module_name
      default: "{{ cookiecutter.project_name | slugify | replace('-','_') }}"
      prompt: Please enter a name for your base python module
      type: string
      validation: "^[_a-zA-Z][_a-zA-Z0-9]+$"
    - name: license
      default: MIT
      prompt: Please choose a license!
      description: Cookiecutter will add an according LICENSE file for you and set the
        according classifier in setup.py.
      type: string
      choices:
        - MIT
        - BSD-3
        - GNU GPL v3.0
        - Apache Software License 2.0
        - Mozilla Public License 2.0

klamann and others added 30 commits April 23, 2021 16:42
also, validate it with the jsonschema lib and write a simple test
…skip_to are only specified for variables of type yes_no
@simobasso
Copy link
Member

simobasso commented May 29, 2021

Hey @louisdegaste @klamann 👋 !

Thanks for the huge work!

This pr contains many side effects, and the review is quite impractical; what do you think to split into small feature branches?

Thanks 🙏

@klamann
Copy link

klamann commented May 30, 2021

Hi @simobasso, glad to hear that you're interested in accepting this change. This PR has a long history and I know it's huge, which makes it a pain to review, but I find it difficult to split it up in meaningful ways. We could extract certain parts like the json schema definition, but they wouldn't interact with any other parts of cookiecutter. Everything else we add would be built on top of another PR, so it wouldn't be possible to review them independently.

Do you have a suggestion how we could divide and conquer this thing?

@louisdegaste
Copy link
Author

louisdegaste commented Jun 1, 2021

Hello @simobasso :) That's great to see that you're interested in the PR ! as @klamann said, the implementation is quite interdependent which will make any division break the code. Yet we could go for the following split:

  • JSON schema: all features used to validate and version the cookicutter.json schema
  • Void Context V2: The implementation of the classes and runflow of the context V2 but without fancy features (other than variables)
  • V2 features: the V2 context populated with features enabled by the new context ( e.g. Regex validation, skip if, etc.)

That would spread a bit the workload although the second branch will probably remain the bigger chunk.

What du you think about it ?

@louisdegaste louisdegaste changed the title Cookiecutter context 2.0 context 2.0 - Advanced features Jun 7, 2021
@louisdegaste
Copy link
Author

I created the PRs #1572 for the JSON schema and #1571 for the classes and renamed this one to split the implementation in 3 PRs which should be (hopefully) even enough :)

@chriszhuada
Copy link

Hi there, any updates on when this PR will be merged?

@kurtmckee
Copy link
Member

I'm closing this PR due to its size. It will not be possible to effectively review it.

@kurtmckee kurtmckee closed this Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New cookiecutter.json format and more for cookiecutter 2.0
6 participants