pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Allow `pixi init` to start with an template.

Open ruben-arts opened this issue 1 year ago β€’ 29 comments

Problem description

As a user I would like to start a project with a template. This might be helpful for tutorials.

This is also nice of developers that ship their code to customers with the intent for them to use pixi.

My design proposal would be that pixi init can except a --template option which can hold either a name for the default templates that the prefix-dev org proposes, or it can except urls to git repositories.

pixi init --template python
pixi init --template rust
pixi init --template https://github.com/prefix-dev/pixi-python-template

ruben-arts avatar Feb 07 '24 14:02 ruben-arts

This would be great! I was going to be implementing this within the {pixi} R package, but if you'll implement it within pixi I'd be happy to help develop a good template for R here!

roaldarbol avatar Feb 23 '24 10:02 roaldarbol

perhaps instead of reinventing the wheel we could use https://github.com/cookiecutter/cookiecutter (which you can install with pixi of course πŸ˜‰ )

baszalmstra avatar Mar 04 '24 14:03 baszalmstra

Or copier. Copier has the advantage that you can update your projects if a new version of the template was released. We use it extensively at our company and it works great.

pavelzw avatar Mar 04 '24 14:03 pavelzw

Current idea is to automatically global install copier and then invoke that. If this feature would become more important we could look at integrating the templating into the rust code.

ruben-arts avatar Mar 12 '24 08:03 ruben-arts

In copier you can define arbitrary tasks afterwards. In these tasks you might have additional dependencies to copier itself. Maybe checking for an optional pixi.toml+pixi.lock in the template repo could make sense?

pavelzw avatar Mar 13 '24 07:03 pavelzw

What would be the benefit of having a global install of copier? Can't we just run pixi runx copier copy ... once #624 is implemented?

pavelzw avatar Mar 14 '24 15:03 pavelzw

Yes even better!

baszalmstra avatar Mar 14 '24 16:03 baszalmstra

What's the status on this issue? If https://github.com/prefix-dev/pixi/pull/1442 gets merged, does that also mean this issue could be solved?

roaldarbol avatar Jun 26 '24 10:06 roaldarbol

Then somebody would need to create a template (i wanted to do that anyway at some point) and then we could link it in the docs for example.

pavelzw avatar Jun 26 '24 11:06 pavelzw

Coolio, I can make a basic one for R next week. ☺️

roaldarbol avatar Jun 26 '24 12:06 roaldarbol

Have made a template we can use to test. It's the first time I've made a template, so just let me know or make a PR if anything needs to be changed. :) https://github.com/roaldarbol/r-template/

roaldarbol avatar Jun 27 '24 23:06 roaldarbol

Yeah @roaldarbol, I think you are right. Could you give the exec branch a go maybe :)?

tdejager avatar Jun 28 '24 07:06 tdejager

I might find time to test it over the weekend, but can't promise it. The only thing that I found was an issue with the template is pulling github user.name and email. pixi has some functions for that, but I don't know how we would incorporate them with copier.

Re the user-facing implementation - If it works with exec, would we just make an extra argument (--template) that then instead calls pixi exec copier copy path/to/template current-folder? (So if I were to call pixi init --template r or pixi init --template gh:roaldarbol/r-template)

roaldarbol avatar Jun 28 '24 10:06 roaldarbol

i would suggest just writing something like the following in your readme


To initialize your repository, please run

pixi exec copier copy --trust https://github.com/roaldarbol/r-template.git .

pavelzw avatar Jun 28 '24 10:06 pavelzw

Added a README with some suggested ways of using it - which will of course be dependent on how this issue is implemented in the end. :-)

roaldarbol avatar Jun 28 '24 14:06 roaldarbol

Update on this: just tried out the solution

pixi exec copier copy --trust https://github.com/roaldarbol/r-template.git .

and it seems to have worked, creating an .Rproj file and everything!

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

See commit above the previous comment for details..

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

After that I tried

pixi install

But alas I got " WARN Not installing dependency on current platform: (linux-64) as it is not part of this project's supported platforms." and R seems to have not been installed. Any ideas how to fix this @roaldarbol ?

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

Hi @robinlovelace-ate! Great to see someone try it out! Yeah, I've realised this, I'll patch in the coming days - for now, in pixi.toml, you'll just need to change platforms = ["osx-64"] to platforms = ["linux-64"] (as I assume you're on a Linux computer 😊).

roaldarbol avatar Jul 09 '24 10:07 roaldarbol

Just realised that at the same time, patched and things now happening: image

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

Next question: how do I get R repl? I tried R but got "command not found".

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

pixi install
βœ” The default environment has been installed.
root@codespaces-837842:/workspaces/netgen# R
bash: R: command not found

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

Currently working on the Python template, hopefully it's done soon.

pavelzw avatar Jul 09 '24 10:07 pavelzw

pixi shell
R

works πŸŽ‰

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

How can I make that shell env load by default?

robinlovelace-ate avatar Jul 09 '24 10:07 robinlovelace-ate

@robinlovelace-ate I've made an issue for the platform question here: https://github.com/roaldarbol/r-template/issues/2 You can ask more questions on that repo, I think it's probably a better place - but happy to try helping out!

Yup, you'll need to either make a pixi shell first, or run pixi run R.

roaldarbol avatar Jul 09 '24 10:07 roaldarbol

@pavelzw Let's chat a bit on Discord about the templates, I'd be really interested to ensure feature parity between the templates!

roaldarbol avatar Jul 09 '24 10:07 roaldarbol

The R template now works for VS Code too.

roaldarbol avatar Jul 09 '24 13:07 roaldarbol

our template for open source python projects that are managed with pixi: https://github.com/Quantco/copier-template-python-open-source

Still wip and not tested much yet, though. Adding automatic docs generation is on my roadmap

pavelzw avatar Jul 12 '24 13:07 pavelzw

With all the copier and cookiecutter templates coming in i would like to let those tools take over this request for now. Closing as stale and not the focus for now.

ruben-arts avatar Sep 17 '24 14:09 ruben-arts