Skip to main content

Compiles Python to an exe

Project description

python-compile

Compile python apps to linux executables

Linting

MacOS_Tests Ubuntu_Tests Win_Tests

This project will use docker to compile your one file python app into a binary that's runnable on many linux systems. Work in progress remains for building windows apps via the docker system.

To develop software, run . ./activate.sh

Example

python-compile --os debian --input demo_http_server.py --requirements requirements.txt

demo_http_server.py

from http.server import CGIHTTPRequestHandler, SimpleHTTPRequestHandler, ThreadingHTTPServer
import socket
import argparse
import os

from http.server import test

if __name__ == '__main__':
    import argparse
    import contextlib

    parser = argparse.ArgumentParser()
    parser.add_argument('--cgi', action='store_true',
                        help='run as CGI server')
    parser.add_argument('--bind', '-b', metavar='ADDRESS',
                        help='specify alternate bind address '
                             '(default: all interfaces)')
    parser.add_argument('--directory', '-d', default=os.getcwd(),
                        help='specify alternate directory '
                             '(default: current directory)')
    parser.add_argument('port', action='store', default=8000, type=int,
                        nargs='?',
                        help='specify alternate port (default: 8000)')
    args = parser.parse_args()
    if args.cgi:
        handler_class = CGIHTTPRequestHandler
    else:
        handler_class = SimpleHTTPRequestHandler

    # ensure dual-stack is not disabled; ref #38907
    class DualStackServer(ThreadingHTTPServer):

        def server_bind(self):
            # suppress exception when protocol is IPv4
            with contextlib.suppress(Exception):
                self.socket.setsockopt(
                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            return super().server_bind()

        def finish_request(self, request, client_address):
            self.RequestHandlerClass(request, client_address, self,
                                     directory=args.directory)

    test(
        HandlerClass=handler_class,
        ServerClass=DualStackServer,
        port=args.port,
        bind=args.bind,
    )

Windows

This environment requires you to use git-bash.

Linting

Run ./lint.sh to find linting errors using pylint, flake8 and mypy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-compile-1.0.2.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_compile-1.0.2-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python-compile-1.0.2.tar.gz.

File metadata

  • Download URL: python-compile-1.0.2.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for python-compile-1.0.2.tar.gz
Algorithm Hash digest
SHA256 fe515d62d1b20f9043155bc8b27214ea3688ce10d23e20e7b972c105f85fbcfb
MD5 b6591636e7ffdc0e857a2f18e587dd66
BLAKE2b-256 e21d114adf9830d1fd3b3e7d8f9ad80c6db895b07e666a5ac9fc56497188ed59

See more details on using hashes here.

File details

Details for the file python_compile-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_compile-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5572f25ad0ba4a3a4f012b35b3ab03ff26db212b41f379de1c0dc8920c4e92ea
MD5 3ba2b7fba85b99bb2b877db6e3203c7e
BLAKE2b-256 84c383051c91af38d5b37c929b8752d412881b4aa14a3eea44c93fe1705e7fa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page