Ich habe nichts gegen die Einstiegspunkte. Es macht die Definition von Python Executables plattformunabhängig. Aber es ist nur ein merkwürdiger Aspekt von PYProject.toml .
Code: Select all
pyproject.toml
my_executable.py
my_packet/
__init__.py
my_module.py
Code: Select all
#!/usr/bin/env python
from my_packet.my_module import func
def main():
return func()
if __name__ == '__main__':
main()
< /code>
Für die Vollständigkeit, dasselbe auf Einstiegspunkte: < /p>
pyproject.toml
my_packet/
__init__.py
my_module.py
my_executable.py
Code: Select all
...
[project.scripts]
my-executable = "my_packet.my_executable:main"
ist
Code: Select all
from my_packet.my_module import func
def main():
return func()
# may not have if __name__ at all
# or contain not application code
# like some tests
< /code>
Dann wird die ausführbare Datei während der Installation generiert. Und es sieht so aus: < /p>
#!/home/.../my_venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from my_packet.my_executable import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())