Können Sie eine eigenständige ausführbare Datei in ein Python -Paket mit pyproject.toml einfügen?Python

Python-Programme
Anonymous
 Können Sie eine eigenständige ausführbare Datei in ein Python -Paket mit pyproject.toml einfügen?

Post by Anonymous »

Blick auf die Python-Verpackung mit PYProject.toml frage ich mich, ob es möglich ist, eine eigenständige ausführbare Datei (mit #!/usr/bin/env python in der ersten Zeile) zum PYProject.toml -Decorts-Wickel und dem entsprechenden ATO-GLENATED-automatischen ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ATO-ADALONE hinzuzufügen. Verstehe ich richtig, dass PYProject.toml nur die [project.scripts] Einstiegspunktdefinitionen unterstützt, um ausführbare Funktionen zu definieren?
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
wobei my_executable.py die +x Berechtigungen für die Ausführung hat und Code wie folgt enthält:

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
mit PYProject.toml :

Code: Select all

...
[project.scripts]
my-executable = "my_packet.my_executable:main"
wobei my_executable.py :
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())

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post