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

Basic example doesn't work #1969

Open
ZackPlauche opened this issue Oct 25, 2023 · 9 comments
Open

Basic example doesn't work #1969

ZackPlauche opened this issue Oct 25, 2023 · 9 comments
Labels
question User questions

Comments

@ZackPlauche
Copy link

ZackPlauche commented Oct 25, 2023

  • Python version: 3.11.5
  • Operating System: Windows

Description:

I tried running pipx cookiecutter gh:audreyfeldroy/cookiecutter-pypackage and got error:

pipx: error: argument command: invalid choice: 'cookiecutter' (choose from 'install', 'uninject', 'inject', 'upgrade', 'upgrade-all', 'uninstall', 'uninstall-all', 'reinstall', 'reinstall-all', 'list', 'run', 'runpip', 'ensurepath', 'environment', 'completions')

This is after pip install pipx and pip install cookiecutter, straight from the very first part of the docs 🤷‍♂️

@JamesParrott
Copy link

You have already installed cookiecutter in some venv, or even globally with pip install cookiecutter.
You do not need to install cookiecutter again in its own special venv using pipx, which is what pipx install cookiecutter would do.
Activate the venv you installed it in if you did so. Then try cookiecutter gh:audreyfeldroy/cookiecutter-pypackage

@ZackPlauche
Copy link
Author

You have already installed cookiecutter in some venv, or even globally with pip install cookiecutter.
You do not need to install cookiecutter again in its own special venv using pipx, which is what pipx install cookiecutter would do.
Activate the venv you installed it in if you did so. Then try cookiecutter gh:audreyfeldroy/cookiecutter-pypackage

Ah! Ok, got it. I didn't see the normal cookiecutter only keyword in the docs instructions. Sorry! This issue is closed haha.

@ZackPlauche
Copy link
Author

ZackPlauche commented Nov 1, 2023

Actually, now with a basic project it still doesn't seem to be working.

I made the cookiecutter.json file:

// cookiecutter.json
{
  "repo_name": "reponame",
  "drf": true,
}

Directory structure

template/
  cookiecutter.json
  {{ cookiecutter.repo_name }}/
    {{ cookiecutter.repo_name }}.html
template.zip

Inside the {{ cookiecutter.repo_name }}.html file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  {% if cookiecutter.drf %}
    DRF
  {% endif %}
  
</body>
</html>

When I run cookiecutter template.zip or cookiecutter C:\Users\username\Desktop\project\template.zip,

I receive the error:

C:\Users\zackp\Desktop\cookiecutter>cookiecutter template.zip
A valid repository for "template.zip" could not be found in the following locations:
C:\Users\zackp\AppData\Local\Temp\tmpkxf18ke5\template/{{ cookiecutter.repo_name }}

C:\Users\zackp\Desktop\cookiecutter>

@ericof ericof added the question User questions label Nov 1, 2023
@JamesParrott
Copy link

You've definitely got it installed correctly now at least - so well done!

From personal experience, not only is it its default mode, but I felt like cookiecutter really really wanted me to fill in the options interactively. It was hard to get it to do otherwise.

It does have the capability of taking the inputs from a file (I'm not promsing json) instead of interactively, but you need to use a specific command line option or two to get it to do so.

@JamesParrott
Copy link

For starters I used a yaml file of the form:

{
  'default_context':
    {
      'repo_name': ...
      'drf': ... 
    },
}

@JamesParrott
Copy link

JamesParrott commented Nov 1, 2023

Then although I've not tried it from a .zip file, I've been able to render directly from a repo on github (like cookiecutter_django) using:

cookiecutter --no-input --config-file path_to_yaml_file.yaml gh:github_user/github_cookiecutter_template_repo_name

Cookiecutter does cache the template, which is a great feature for experimentation. But again, I recall that's easier to choose interactively, than to set from a CLI flag.

@JamesParrott
Copy link

JamesParrott commented Nov 1, 2023

If you're still having no joy, you'll have to rename the folder yourself, but try pipx install jinja2-cli ;-).
After that, on a Posix shell:

`jinja2 '{{ cookiecutter.repo_name }}.html' cookiecutter.json --format=JSON > reponame.html

ought to render that html template from your json file, without too much extra effort.

@ZackPlauche
Copy link
Author

I just really thought a lot of this stuff might be somewhere in the normal intro docs 😅 The intro docs example literally shows a zip file.

I'm happy to do it without 😅 is there not a way to do it locally and with just a normal json file?

@JamesParrott
Copy link

JamesParrott commented Nov 2, 2023

Indeed - I would've thought so too. I'm not an expert in the project, but it is incredibly popular. I think it's just intended for a different application and user base.

Maybe someone else can help you with zip files.

All JSON is valid YAML by the way. But I recall wondering why it all had to go behind the default_context key, and not finding an alternative. I think that's just the way it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question User questions
Projects
None yet
Development

No branches or pull requests

3 participants