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

Added all open source licenses (Fixes #2941) #3072

Closed

Conversation

Andrew-Chen-Wang
Copy link
Contributor

@Andrew-Chen-Wang Andrew-Chen-Wang commented Feb 27, 2021

Description

Use licenses that we see on GitHub when we create a new repo. Also included is automatic updating of the licenses from the aforementioned license repository created by GitHub. The cookiecutter.json file is also updated.

Checklist:

  • I've made sure that tests/test_cookiecutter_generation.py is updated accordingly (especially if adding or updating a template option)
  • I've updated the documentation or confirm that my change doesn't require any updates

Docs haven't been updated because honestly... I don't know if we want to show ALL of those licenses...

Rationale

Fixes #2941

Lots of open source licenses... too many to choose.

Makes it easier to maintain since we can just use GitHub actions to constantly update the files if necessary.

* Uses open source licenses (including the Jekyll format) from https://github.com/github/choosealicense.com/tree/gh-pages/_licenses
* Added license section in README.rst because some licenses want it to be explicit
* cookiecutter.json shows all licenses (including "Not open source") in lexicographical order except for "Not open source"
Signed-off-by: Andrew-Chen-Wang <[email protected]>
@Andrew-Chen-Wang
Copy link
Contributor Author

Oooo that's an... interesting error to deal with...

* The solution? Put it in some random txt file in the license folder and read it in. You can't use """""" or "" or '' without some kind of error. By reading in the text instead, we completely avoid this.

Signed-off-by: Andrew-Chen-Wang <[email protected]>
@Andrew-Chen-Wang
Copy link
Contributor Author

Something that can make sure commits decrease in the automatic workflow is to check if the license file already exists since licenses don't change due to their copyright reasons. That means we should only commit if there's a difference in cookiecutter.json (i.e. any new license).

Additionally, it might be better to also include the MIT license, Apache, etc. near the front like "Not open source" license is in cookiecutter.json.

@Andrew-Chen-Wang
Copy link
Contributor Author

Just realized we should instead make a pull request instead of committing directly in case of a new file since there would be square brackets.

* Deleted LICENSE and COPYING files
* Moved most utilized options to front of licenses in cookiecutter.json options.

Signed-off-by: Andrew-Chen-Wang <[email protected]>
Copy link
Contributor Author

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I missed a couple. I think that should be it from my initial generation (this was before I actually programmed the autoupdater)


3. All advertising materials mentioning features or use of this software must
display the following acknowledgement:
This product includes software developed by [project].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This product includes software developed by [project].
This product includes software developed by {{cookiecutter.project_name}}.

same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright [yyyy] [name of copyright owner]
Copyright {% now 'utc', '%Y' %} {{cookiecutter.author_name}}

Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we should instead make a pull request instead of committing directly in case of a new file since there would be square brackets.

We can reuse what we do to keep pre-commit hooks config up to date:

https://github.com/pydanny/cookiecutter-django/blob/master/.github/workflows/pre-commit-autoupdate.yml

It doesn't do anything in case of no changes.

@@ -324,6 +312,34 @@ def remove_storages_module():
os.remove(os.path.join("{{cookiecutter.project_slug}}", "utils", "storages.py"))


def handle_licenses():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to remove the Jekyll front matter? I'm wondering if wouldn't make more sense to do this work in the update_licenses.py scripts maybe?

We can afford to use more modern Python there, we control the Python version better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorta, we need the Jekyll formatting at first. Each file's name is not the same as the title. So in order to find the correct file, we loop through each file until we find one that has the Jekyll title of the exact license name from cookiecutter.json.

We could improve on this inefficient method though by having update_licenses.py update this Python file to have a dictionary that maps titles (the dict keys) to their files (the dict values). That way we can remove the need for the Jekyll headers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see...

Comment on lines +51 to +55
with open("cookiecutter.json") as f:
data = json.load(f)
data["open_source_license"] = titles
with open("cookiecutter.json", "wt") as f:
json.dump(data, f, indent=2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do away without the context manager with Pathlib's read_text() and write_text() APIs. Not a big deal, I find them a bit higher level.

Comment on lines +37 to +41
year = (re.compile(r"\[year]"), "{% now 'utc', '%Y' %}")
email = (re.compile(r"\[email]"), "{{ cookiecutter.email }}")
fullname = (re.compile(r"\[fullname]"), "{{ cookiecutter.author_name }}")
project = (re.compile(r"\[project]"), "{{ cookiecutter.project_name }}")
projecturl = (re.compile(r"\[projecturl]"), "{{ cookiecutter.domain_name }}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we could add a test to make sure we don't miss any new placeholder? Seems a bit tricky to make the difference between a placeholder and a genuine [...] though. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I wanted the pull request initially... In the Jekyll headers for all these files, there are directions that specify what to replace though! The directions say something like "replace [year] with etc." if I'm not mistaken. So after replacing everything, if we still match a regex of \[.*?\] (which matches to anything with square brackets including if there are multiple square brackets like [asdf] [asf] will be two matches).

Side note: I think we don't really need to care about Appendix directions (like that found in Apache 2.0 where they say to add the boilerplate code with year and name. With us putting it in already, I think the developer will understand. Additionally, license years don't have to be updated so there's that...)

"Apache Software License 2.0",
"Not open source"
],
"open_source_license": ["Not open source", "MIT License", "BSD 3-Clause \"New\" or \"Revised\" License", "GNU General Public License v3.0", "Apache License 2.0", "\"Do What The F*ck You Want To Public License\"", "Academic Free License v3.0", "Artistic License 2.0", "BSD 2-Clause \"Simplified\" License", "BSD 3-Clause Clear License", "BSD 4-Clause \"Original\" or \"Old\" License", "BSD Zero Clause License", "Boost Software License 1.0", "CeCILL Free Software License Agreement v2.1", "Creative Commons Attribution 4.0 International", "Creative Commons Attribution Share Alike 4.0 International", "Creative Commons Zero v1.0 Universal", "Eclipse Public License 1.0", "Eclipse Public License 2.0", "Educational Community License v2.0", "European Union Public License 1.1", "European Union Public License 1.2", "GNU Affero General Public License v3.0", "GNU General Public License v2.0", "GNU Lesser General Public License v2.1", "GNU Lesser General Public License v3.0", "ISC License", "LaTeX Project Public License v1.3c", "Microsoft Public License", "Microsoft Reciprocal License", "Mozilla Public License 2.0", "ODC Open Database License v1.0", "Open Software License 3.0", "PostgreSQL License", "SIL Open Font License 1.1", "The Unlicense", "Universal Permissive License v1.0", "University of Illinois/NCSA Open Source License", "Vim License", "zlib License"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the script has now indenting this properly, although this is not yet reflected here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly confused what you mean here? Are you saying that the GitHub workflow may not get the indentation correctly? Hopefully when the argument "indent=2" or 4 (can't remember) from json.dump works properly (preserving ordering as well). But I can't remember during my test run if all the arrays became... well aren't vertically spaced out like postgresql_version

Copy link
Member

@browniebroke browniebroke Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With indent=2, I would expect this part to wrap vertically, a bit like it used to, but it doesn't. I was trying to ask if it's because you generated this with an earlier version where indent was missing or if my expectation is just wrong.

(sorry looking back, my initial comment was poorly worded)

Comment on lines +4 to +6
# Every day at 2am
schedule:
- cron: "0 2 * * *"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to run this at another time that the chnagelog update.

@Andrew-Chen-Wang
Copy link
Contributor Author

Andrew-Chen-Wang commented Jul 27, 2021

@browniebroke I'll be creating a new PR at some point in the long distance future. Looks like I completely missed their (new?) API that includes the licenses: https://docs.github.com/en/rest/reference/licenses#get-a-license

@Andrew-Chen-Wang
Copy link
Contributor Author

#3982 would resolve this

@Andrew-Chen-Wang Andrew-Chen-Wang deleted the licenses branch December 12, 2022 01:44
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.

add AGPL
2 participants