Skip to content

Commit

Permalink
Build single executable with PyOxidizer
Browse files Browse the repository at this point in the history
PyOxidizer cannot use importlib.resources, which is what certifi uses for
determining the path of the included CA bundle, so we need a workaround for
this.
  • Loading branch information
kissgyorgy committed Jun 11, 2020
1 parent 3487cbe commit 34b7c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 10 additions & 0 deletions cfdns.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/usr/bin/env python3
import os
import pickle
import ipaddress
from pathlib import Path
from collections import namedtuple
import click
import certifi

# Workaround for certifi resource location doesn't work with PyOxidizer.
# See: https://github.com/psf/requests/blob/v2.23.0/requests/utils.py#L40
# and: https://github.com/indygreg/PyOxidizer/issues/237
certifi.where = lambda: os.environ.get(
"REQUESTS_CA_BUNDLE", "/etc/ssl/certs/ca-certificates.crt"
)

import requests
import CloudFlare

Expand Down
14 changes: 6 additions & 8 deletions pyoxidizer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def make_exe(dist):
# verbose=0,
# write_modules_directory_env=None,
# run_eval=None,
# run_module=None,
run_module="cfdns",
# run_noop=False,
# run_repl=True,
)
Expand Down Expand Up @@ -100,17 +100,15 @@ def make_exe(dist):

# Invoke `pip install` using a requirements file and add the collected resources
# to our binary.
#exe.add_in_memory_python_resources(dist.pip_install(["-r", "requirements.txt"]))


exe.add_in_memory_python_resources(dist.pip_install(["-r", "requirements.txt"]))

# Read Python files from a local directory and add them to our embedded
# context, taking just the resources belonging to the `foo` and `bar`
# Python packages.
#exe.add_in_memory_python_resources(dist.read_package_root(
# path="/src/mypackage",
# packages=["foo", "bar"],
#))
exe.add_in_memory_python_resources(dist.read_package_root(
path=".",
packages=["cfdns"],
))

# Discover Python files from a virtualenv and add them to our embedded
# context.
Expand Down

0 comments on commit 34b7c5c

Please sign in to comment.