Writing copyright information in python code
Asked Answered
K

4

47

What is the standard way of writing "copyright information" in python code? Should it be inside docstring or in block comments? I could not find it in PEPs.

Kofu answered 12/1, 2010 at 12:30 Comment(4)
"Standard"? Who would specify such a standard? ISO? IEEE? ANSI? How provides standards for this kind of thing? Copyright is a very localized thing, so what level of standardization are you looking for? US? EU? China?Sewoll
I think the 'standard' here means 'common practice'Guertin
@Kimvais: Interesting read on the question. I wonder what the Author actually meant.Sewoll
I thought the question was written clearly enough, especially since the poster mentioned they expected to find this information in the PEP so its implied they are looking for style guidelines.Electorate
C
44

Some projects use module variables like __license__, as in:

__author__ = "Software Authors Name"
__copyright__ = "Copyright (C) 2004 Author Name"
__license__ = "Public Domain"
__version__ = "1.0"

Seems like a pretty clean solution to me (unless you overdo it and dump epic texts into these variables), but only __version__ seems to be in widespread use, as it is mentioned in PEP 8.

Cryptograph answered 12/1, 2010 at 14:27 Comment(2)
Pretty clean, but in most of the organizations, while redistributing a software, copyright is a lot of text. Though I wonder why it is not included in PEP.Kofu
As a note for future visitors, this system of ad-hoc module variables has been replaced by standardized distribution metadata. See PEP 621, and Declaring project metadata and importlib.metadata from the Python docs.Embolectomy
G
16
# Comment in the beginning of the file

At least python built-in modules do this. (found out by doing grep 'Copyright' /usr/lib64/python2.4/*.py)

Guertin answered 12/1, 2010 at 12:33 Comment(1)
@Kofu was asking for 'the standard way of writing "copyright information"' not whether it necessary to write the information. That's why I think my downvote is justified, while yours looks like a spiteful revenge.Guertin
I
8

We follow the recommendations found (somewhere) on the Software Freedom Law Center's site. Here is an example of a simple GPL'ed file.

Infusive answered 12/1, 2010 at 13:11 Comment(3)
Looks like there are no guidelines specified for it anywhere in python docs or PEPs, but the above notation is widely used and accepted. Thanks!Kofu
Its kinda frowned upon to give links without explanation on SO. Perhaps explain what the example is. In this case, a copyright notice and full license was included at the top of the file using comments (not doc strings).Electorate
The "somewhere" looks to be hereButyl
U
3

As I know, there is currently no standard way. Each company/organization will have their own template to doc the copyright information. If this is your personal project, then just feel free to doc it in the way you feel most comforable. Adding a LICENSE file is a very common way for projects with many source files. Even in Python, there is currently no standard on the structure of docstrings.

Python provides a lot of freedom, so just let it be dude ;)

Underwing answered 12/1, 2010 at 13:12 Comment(1)
I get that many may do this differently... but the point of including a license is to avoid legal matters down the road... I don't think just let it be is good advice to give on such things :/Electorate

© 2022 - 2024 — McMap. All rights reserved.