poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Adding automatic fetch of license file when calling init command

Open quentinhaenn opened this issue 1 year ago • 3 comments

Issue Kind

Brand new capability

Description

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

I just started a python initializer project on my own and several colleagues told me your tool exist. After digging into it, it came out that Poetry is a wonderful tool for managing python project. However, I implemented a feature that load License content and fill the license file associated with the project. As I supposed a great part of project using poetry might either be open licensed or using a commonly used license, it would be great to implement this one in Poetry.

One may also think about another feature that woould be changing the license tag (eg from MIT to gpl-3.0) in pyproject.toml and using poetry update pulling the new license required.

Impact

I believe that this would be a great feature in Poetry as it pushed me to develop my own solution to create python projects from scratch using a simple CLI. I would love to see a --license' option to pass to poetry new` command, choosing the "MIT" license as default behavior and pulling the license body and adding it into the LICENSE file directly at project creation. Not a great gain of time but I certainly support it as comfort gain.

Workarounds

Not really a workaround but my own implementation of this feature is accessible on Pypi as pyproject-init and on GitHub

I know several other tools already exists on PyPi doing same but submitting it to Poetry seemed the thing to do.

Also, I'd like to contribute by implementing it by myself and submitting a PR but the legacy codebase is pretty huge and I am facing difficulties to navigate in.

I know this seems a very tiny improvement but I'd really like to see it in a great tool like Poetry :smiley:

Please let me know if this feature may be of interest and if I can contribute in any way ! Thanks in advance :smile:

quentinhaenn avatar Mar 19 '24 15:03 quentinhaenn

There is already a --license option for poetry init and since #9088 also for poetry new (just in the main branch, not yet released). It just fills the metadata field with the given text.

choosing the "MIT" license as default

Not sure if it makes sense to have a default.

pulling the license body

Some things to consider:

  • license is more or less free text so this will not always be possible
  • This probably requires access to some website?
    • Downloading a file will slow down the command a bit. (Will it be significant?)
    • Poetry might be used in an environment without internet access. It probably should not fail and should not waste time by running into a timeout in this case.
  • It might not always be as simple as downloading one file. For example, for LGPL you need two:

If you are releasing your program under the Lesser GPL, you should also include the text version of the LGPL, usually in a file called COPYING.LESSER. Please note that, since the LGPL is a set of additional permissions on top of the GPL, it's crucial to include both licenses so users have all the materials they need to understand their rights.

from https://www.gnu.org/licenses/gpl-howto.html.en

All in all, I think this might be better suited in a plugin with a new command to download the license. But let's see if there are other opinions.

radoering avatar Mar 20 '24 16:03 radoering

Thanks for replying.

There is already a --license option for poetry init and since https://github.com/python-poetry/poetry/pull/9088 also for poetry new (just in the main branch, not yet released). It just fills the metadata field with the given text.

Yes, I figured it out before submitting the issue, I should have precised it. I mainly focused on the tiny gain of time of automatic filling the LICENSE file.

Not sure if it makes sense to have a default.

Great point of yours, I considered the MIT license as default on my usage as it is the "most permissive" in open source projects, but that might not be effectively the case.

This probably requires access to some website?

In the cases I considered, I only pull license body of licenses listed on choosealicense.com. Fortunately, GitHub API provide an URI that can be used for pulling licenses : https://api.github.com/licenses/" + license_type

Downloading a file will slow down the command a bit. (Will it be significant?)

This depends on internet connection I guess. In my case, the project is initialized within a second with license text pull.

Poetry might be used in an environment without internet access. It probably should not fail and should not waste time by running into a timeout in this case.

That case might be easily handle with requests.ConnectionError I guess. Plus, setting a timeout parameter at 0.005 sec works fine in my case and only handle connection time to the GitHub API i.e. downloading time of the license may be longer but if connection time is less than timeout, it works.

It might not always be as simple as downloading one file. For example, for LGPL you need two

I did not know about that particular case, thanks for sharing. Might not be that hard to handle with an if statement.

All in all, I think this might be better suited in a plugin with a new command to download the license.

I wondered the same, but cannot figured it out by myself.

I'll take a look about plugin dev too then.

Thanks for your time :smile:

quentinhaenn avatar Mar 20 '24 17:03 quentinhaenn

The gain of time probably is not sufficient vs the risk of mis-licencing someone's software. The safest is to have a blank licence field, or a proprietary licence as the default, and allow people to open up the licence.

robertlagrant avatar May 03 '24 09:05 robertlagrant