Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2025/06/19 08:39:27.157 (台灣標準時)

pyproject.toml でライセンスを指定する方法

Python のパッケージを作成するとき、 pyproject.toml というファイルを用 意せねばならぬでござる。 hatch というコマンドを使うと、 pyproject.toml の雛形を自動生成してくれるでござる。

まず、 hatch コマンドを使って、 pyproject.toml の雛形の内容を表示させ てみるでござる。


% hatch config show
mode = "local"                                                                  
project = ""                                                                    
shell = ""                                                                      
                                                                                
[dirs]                                                                          
project = []                                                                    
python = "isolated"                                                             
data = "/home/daisuke/.local/share/hatch"                                       
cache = "/home/daisuke/.cache/hatch"                                            
                                                                                
[dirs.env]                                                                      
                                                                                
[projects]                                                                      
                                                                                
[template]                                                                      
name = "daisuke"                                                                
email = "abc@def.ghi"                                                   
                                                                                
[template.licenses]                                                             
headers = true                                                                  
default = [                                                                     
    "MIT",                                                                      
]                                                                               
                                                                                
[template.plugins.default]                                                      
tests = true                                                                    
ci = false                                                                      
src-layout = true                                                               
                                                                                
[terminal.styles]                                                               
info = "bold"                                                                   
success = "bold cyan"                                                           
error = "bold red"                                                              
warning = "bold yellow"                                                         
waiting = "bold magenta"                                                        
debug = "bold"                                                                  
spinner = "simpleDotsScrolling"                                                 

自動生成された雛形のライセンスの部分は、 MIT ライセンスが指定されてい るでござる。

以下のコマンドを実行すると、雛形ファイルを生成する際に使われるファイル の場所がわかるようでござる。


% hatch config find
/home/daisuke/.config/hatch/config.toml

/home/daisuke/.config/hatch/config.toml ファイルの内容を見てみるでござ る。


% cat /home/daisuke/.config/hatch/config.toml
mode = "local"
project = ""
shell = ""

[dirs]
project = []
python = "isolated"
data = "/home/daisuke/.local/share/hatch"
cache = "/home/daisuke/.cache/hatch"

[dirs.env]

[projects]

[publish.index]
repo = "main"

[template]
name = "daisuke"                                                                
email = "abc@def.ghi"                                                   

[template.licenses]
headers = true
default = [
    "MIT",
]

[template.plugins.default]
tests = true
ci = false
src-layout = true

[terminal.styles]
info = "bold"
success = "bold cyan"
error = "bold red"
warning = "bold yellow"
waiting = "bold magenta"
debug = "bold"
spinner = "simpleDotsScrolling"

このファイルを編集すればよいようでござる。ライセンスについては、 SPDX license expression を使って指定しないといけないそうでござる。では、こ の SPDX license expression では、各ライセンスはどのように表記されるの か、というと、それは以下のページを参照すればよいようでござる。

例えば、 GPLv3 は、 "GPL-3.0-only" や "GPL-3.0-or-later" と書けばよいようでござる。

hatch コマンドを使って変更を加えることもできるようでござる。試してみる でござる。


% hatch config set template.name myname
New setting:
[template]
name = "myname"

変更が反映されたかどうか確認してみるでござる。


% hatch config show
mode = "local"                                                                  
project = ""                                                                    
shell = ""                                                                      
                                                                                
[dirs]                                                                          
project = []                                                                    
python = "isolated"                                                             
data = "/home/daisuke/.local/share/hatch"                                       
cache = "/home/daisuke/.cache/hatch"                                            
                                                                                
[dirs.env]                                                                      
                                                                                
[projects]                                                                      
                                                                                
[template]                                                                      
name = "myname"                                                                 
email = "abc@def.ghi"                                                   
                                                                                
[template.licenses]                                                             
headers = true                                                                  
default = [                                                                     
    "GPL-3.0-or-later",                                                         
]                                                                               
                                                                                
[template.plugins.default]                                                      
tests = true                                                                    
ci = false                                                                      
src-layout = true                                                               
                                                                                
[terminal.styles]                                                               
info = "bold"                                                                   
success = "bold cyan"                                                           
error = "bold red"                                                              
warning = "bold yellow"                                                         
waiting = "bold magenta"                                                        
debug = "bold"                                                                  
spinner = "simpleDotsScrolling"                                                 

ライセンスの部分を変更してみるでござる。


% hatch config set template.licenses.default "BSD-3-Clause"
Error parsing config:
template -> licenses -> default
  must be an array

失敗してしまったでござる。 array でなくてはいけない、ということなので、 以下を試してみたでござる。


% hatch config set template.licenses.default ["BSD-3-Clause"] 
hatch: No match.

これも失敗してしまったでござる。以下を試してみたでござる。


% hatch config set template.licenses.default "['BSD-3-Clause']"
New setting:
[template.licenses]
default = ["BSD-3-Clause"]

今度は成功したようでござる。確認してみるでござる。


% hatch config show
mode = "local"                                                                  
project = ""                                                                    
shell = ""                                                                      
                                                                                
[dirs]                                                                          
project = []                                                                    
python = "isolated"                                                             
data = "/home/daisuke/.local/share/hatch"                                       
cache = "/home/daisuke/.cache/hatch"                                            
                                                                                
[dirs.env]                                                                      
                                                                                
[projects]                                                                      
                                                                                
[template]                                                                      
name = "myname"                                                                 
email = "abc@def.ghi"                                                   
                                                                                
[template.licenses]                                                             
headers = true                                                                  
default = [                                                                     
    "BSD-3-Clause",                                                             
]                                                                               
                                                                                
[template.plugins.default]                                                      
tests = true                                                                    
ci = false                                                                      
src-layout = true                                                               
                                                                                
[terminal.styles]                                                               
info = "bold"                                                                   
success = "bold cyan"                                                           
error = "bold red"                                                              
warning = "bold yellow"                                                         
waiting = "bold magenta"                                                        
debug = "bold"                                                                  
spinner = "simpleDotsScrolling"                                                 

確かに BSD ライセンスに変更されているでござる。



Frequently accessed files

  1. Computer___Python/20220518_0.html
  2. Computer___Network/20230726_00.html
  3. Misc___Taiwan/20240207_00.html
  4. Computer___Network/20230516_00.html
  5. Computer___FreeBSD/20220621_0.html
  6. Computer___Network/20240130_00.html
  7. Computer___Network/20230508_00.html
  8. Computer___Python/20220715_0.html
  9. Computer___TeX/20231107_00.html
  10. Computer___NetBSD/20230119_00.html
  11. Food___Taiwan/20220429_0.html
  12. Computer___Network/20240416_00.html
  13. Computer___Network/20220413_1.html
  14. Computer___Python/20220410_0.html
  15. Misc___Japan/20240610_00.html
  16. Computer___Python/20221013_0.html
  17. Computer___TeX/20230726_01.html
  18. Computer___Python/20240101_00.html
  19. Computer___NetBSD/20220817_3.html
  20. Computer___Debian/20210223_1.html
  21. Computer___NetBSD/20220818_1.html
  22. Computer___NetBSD/20240101_02.html
  23. Computer___Python/20210124_0.html
  24. Computer___NetBSD/20220428_0.html
  25. Misc___Taiwan/20240819_00.html
  26. Science___Math/20220420_0.html
  27. Computer___TeX/20240414_00.html
  28. Computer___TeX/20230503_00.html
  29. Computer___NetBSD/20240101_03.html
  30. Science___Astronomy/20220503_0.html


HTML file generated by Kinoshita Daisuke.