s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.94k stars 171 forks source link

Installation assumes Poetry is preinstalled #153

Closed fmigneault closed 1 year ago

fmigneault commented 1 year ago

Creating a fresh new conda environment, with only pip install fastapi_template, it is possible to go through the whole menu setup steps of the CLI, but on the final step it crashes with the following log:

⭐ Placing resources nicely in your new project ⭐
Resources are happy to be where they are needed the most.
Git repository initialized.
Added files to index.
Traceback (most recent call last):
  File "/tmp/tmp1q42xavn.py", line 74, in <module>
    init_repo()
  File "/tmp/tmp1q42xavn.py", line 64, in init_repo
    subprocess.run(["poetry", "install", "-n"])
  File "/home/francis/dev/conda/envs/cookie-cutter/lib/python3.10/subprocess.py", line 503, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/home/francis/dev/conda/envs/cookie-cutter/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/francis/dev/conda/envs/cookie-cutter/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'

Simply running pip install poetry before fixes the problem.

The project should probably include poetry in its dependencies to automatically install it and avoid this issue, as it unexpectedly causes the user to have to restart the menu step process from scratch.

s3rius commented 1 year ago

Hi and thanks for creating the issue. In README the very first line says that git python and poetry must be installed.

But let me explain you the main reason why I don't include poetry as a dependency. That's because installing poetry from pip is not preferable method for installation. If people follow the docs and install poetry the way they suggest, installing poetry along with template may cause an issue, when you won't be able to tell which version of poetry is going to be used.

The second problem is versions. Poetry is not an actual dependency. We do not call it programmatically using API, we use it as a command. Like git. That's why I cannot say which version of poetry I must rely on.

That's why I decided not to include poetry in dependencies.

I hope that now you have a clear understanding why I did this exact decision. Maybe it's not clear enough, so I must update README and add additional step before the installation.

fmigneault commented 1 year ago

I see. I understand the reasoning. Thanks for the explanation.

Maybe it would be worth adding a pre-check that poetry can be resolved before starting the template creation process and warn the user that this dependency should be installed. I was mostly surprised to see the full menu work all the way until final submission, and fail.

s3rius commented 1 year ago

Fair point. Yes, that's a good option. Will add this in the next release.

s3rius commented 1 year ago

Released in 4.1.1.