diff options
author | laixintao <laixintaoo@gmail.com> | 2020-11-25 19:15:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 19:15:15 +0800 |
commit | ae7be2a1aeea064cfb2935b4b870be55bacde7d0 (patch) | |
tree | 539f54a44bdfd78b4772989c3a7ebfb713c0c747 | |
parent | f5968e2fb6ca81bb4f036d94b04e6d7576783fbf (diff) | |
parent | 39b183551d340fada8e4c9a25ad5c0adf2f0b171 (diff) |
Merge pull request #364 from macdavid313/pyoxidizer-0.10.3
use PyOxidizer 0.10.3
-rw-r--r-- | .github/workflows/release.yaml | 2 | ||||
-rw-r--r-- | pyoxidizer.template.bzl | 236 |
2 files changed, 196 insertions, 42 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dc34f58..4ea613d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -118,7 +118,7 @@ jobs: # pyoxidizer doesn't know the wheel path, and it doesn't support passing env vars export WHEEL_PATH=`ls ./dist/iredis*.whl` envsubst '$WHEEL_PATH' < pyoxidizer.template.bzl > pyoxidizer.bzl - cargo install pyoxidizer --vers 0.6.0 + cargo install pyoxidizer --vers 0.10.3 pyoxidizer build --release install cd ./build/x86*/release/install tar -zcf ../../../iredis.tar.gz lib/ iredis diff --git a/pyoxidizer.template.bzl b/pyoxidizer.template.bzl index 612ecde..349ba3e 100644 --- a/pyoxidizer.template.bzl +++ b/pyoxidizer.template.bzl @@ -12,52 +12,210 @@ def make_dist(): # This function creates a Python executable and installs it in a destination # directory. def make_exe(dist): - # This variable defines the configuration of the - # embedded Python interpreter. - python_config = PythonInterpreterConfig( - run_eval="from iredis.entry import main; main()", - # Allows the executable to load deps from this folder - sys_paths=["$ORIGIN/lib"] - ) + # This function creates a `PythonPackagingPolicy` instance, which + # influences how executables are built and how resources are added to + # the executable. You can customize the default behavior by assigning + # to attributes and calling functions. + policy = dist.make_python_packaging_policy() + + # Enable support for non-classified "file" resources to be added to + # resource collections. + # policy.allow_files = True + + # Control support for loading Python extensions and other shared libraries + # from memory. This is only supported on Windows and is ignored on other + # platforms. + # policy.low_in_memory_shared_library_loading = True + + # Control whether to generate Python bytecode at various optimization + # levels. The default optimization level used by Python is 0. + # policy.bytecode_optimize_level_zero = True + # policy.bytecode_optimize_level_one = True + policy.bytecode_optimize_level_two = True + + # Package all available Python extensions in the distribution. + policy.extension_module_filter = "all" + + # Package the minimum set of Python extensions in the distribution needed + # to run a Python interpreter. Various functionality from the Python + # standard library won't work with this setting! But it can be used to + # reduce the size of generated executables by omitting unused extensions. + # policy.extension_module_filter = "minimal" + + # Package Python extensions in the distribution not having additional + # library dependencies. This will exclude working support for SSL, + # compression formats, and other functionality. + # policy.extension_module_filter = "no-libraries" + + # Package Python extensions in the distribution not having a dependency on + # GPL licensed software. + # policy.extension_module_filter = "no-gpl" + + # Controls whether the file scanner attempts to classify files and emit + # resource-specific values. + # policy.file_scanner_classify_files = True + + # Controls whether `File` instances are emitted by the file scanner. + # policy.file_scanner_emit_files = False + + # Controls the `add_include` attribute of "classified" resources + # (`PythonModuleSource`, `PythonPackageResource`, etc). + # policy.include_classified_resources = True + + # Toggle whether Python module source code for modules in the Python + # distribution's standard library are included. + policy.include_distribution_sources = True + + # Toggle whether Python package resource files for the Python standard + # library are included. + policy.include_distribution_resources = False + + # Controls the `add_include` attribute of `File` resources. + policy.include_file_resources = False + + # Controls the `add_include` attribute of `PythonModuleSource` not in + # the standard library. + # policy.include_non_distribution_sources = True + + # Toggle whether files associated with tests are included. + policy.include_test = False + + # Resources are loaded from "in-memory" or "filesystem-relative" paths. + # The locations to attempt to add resources to are defined by the + # `resources_location` and `resources_location_fallback` attributes. + # The former is the first/primary location to try and the latter is + # an optional fallback. + + # Use in-memory location for adding resources by default. + # policy.resources_location = "in-memory" + + # Use filesystem-relative location for adding resources by default. + policy.resources_location = "filesystem-relative:lib" + + # Attempt to add resources relative to the built binary when + # `resources_location` fails. + # policy.resources_location_fallback = "filesystem-relative:prefix" + + # Clear out a fallback resource location. + # policy.resources_location_fallback = None + + # Define a preferred Python extension module variant in the Python distribution + # to use. + # policy.set_preferred_extension_module_variant("foo", "bar") + + # Configure policy values to classify files as typed resources. + # (This is the default.) + # policy.set_resource_handling_mode("classify") + + # Configure policy values to handle files as files and not attempt + # to classify files as specific types. + # policy.set_resource_handling_mode("files") + + # This variable defines the configuration of the embedded Python + # interpreter. By default, the interpreter will run a Python REPL + # using settings that are appropriate for an "isolated" run-time + # environment. + # + # The configuration of the embedded Python interpreter can be modified + # by setting attributes on the instance. Some of these are + # documented below. + python_config = dist.make_python_interpreter_config() + + # Make the embedded interpreter behave like a `python` process. + # python_config.config_profile = "python" + + # Set initial value for `sys.path`. If the string `$ORIGIN` exists in + # a value, it will be expanded to the directory of the built executable. + python_config.module_search_paths = ["$ORIGIN/lib"] + + # Use jemalloc as Python's memory allocator + # python_config.raw_allocator = "jemalloc" + + # Use the system allocator as Python's memory allocator. + python_config.raw_allocator = "system" + + # Control whether `oxidized_importer` is the first importer on + # `sys.meta_path`. + # python_config.oxidized_importer = False + + # Enable the standard path-based importer which attempts to load + # modules from the filesystem. + # python_config.filesystem_importer = True + + # Set `sys.frozen = True` + # python_config.sys_frozen = True + + # Set `sys.meipass` + # python_config.sys_meipass = True + + # Write files containing loaded modules to the directory specified + # by the given environment variable. + # python_config.write_modules_directory_env = "/tmp/oxidized/loaded_modules" + + # Evaluate a string as Python code when the interpreter starts. + python_config.run_command = "from iredis.entry import main; main()" + + # Run a Python module as __main__ when the interpreter starts. + # python_config.run_module = "<module>" + + # Run a Python file when the interpreter starts. + # python_config.run_filename = "/path/to/file" # Produce a PythonExecutable from a Python distribution, embedded # resources, and other options. The returned object represents the # standalone executable that will be built. exe = dist.to_python_executable( name="iredis", + + # If no argument passed, the default `PythonPackagingPolicy` for the + # distribution is used. + packaging_policy=policy, + + # If no argument passed, the default `PythonInterpreterConfig` is used. config=python_config, - # Embed all extension modules, making this a fully-featured Python. - extension_module_filter='all', + ) - # Only package the minimal set of extension modules needed to initialize - # a Python interpreter. Many common packages in Python's standard - # library won't work with this setting. - #extension_module_filter='minimal', + # Install tcl/tk support files to a specified directory so the `tkinter` Python + # module works. + # exe.tcl_files_path = "lib" - # Only package extension modules that don't require linking against - # non-Python libraries. e.g. will exclude support for OpenSSL, SQLite3, - # other features that require external libraries. - #extension_module_filter='no-libraries', + # Make the executable a console application on Windows. + # exe.windows_subsystem = "console" - # Only package extension modules that don't link against GPL licensed - # libraries. - #extension_module_filter='no-gpl', + # Make the executable a non-console application on Windows. + # exe.windows_subsystem = "windows" - # Include Python module sources. This isn't strictly required and it does - # make binary sizes larger. But having the sources can be useful for - # activities such as debugging. - include_sources=True, + # Invoke `pip download` to install a single package using wheel archives + # obtained via `pip download`. `pip_download()` returns objects representing + # collected files inside Python wheels. `add_python_resources()` adds these + # objects to the binary, with a load location as defined by the packaging + # policy's resource location attributes. + #exe.add_python_resources(exe.pip_download(["pyflakes==2.2.0"])) + + # Invoke `pip install` with our Python distribution to install a single package. + # `pip_install()` returns objects representing installed files. + # `add_python_resources()` adds these objects to the binary, with a load + # location as defined by the packaging policy's resource location + # attributes. + exe.add_python_resources(exe.pip_install(["$WHEEL_PATH"])) + + # Invoke `pip install` using a requirements file and add the collected resources + # to our binary. + #exe.add_python_resources(exe.pip_install(["-r", "requirements.txt"])) - # Whether to include non-module resource data/files. - include_resources=False, - # Do not include functionality for testing Python itself. - include_test=False, - ) + + # 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_python_resources(exe.read_package_root( + # path="/src/mypackage", + # packages=["foo", "bar"], + #)) # Discover Python files from a virtualenv and add them to our embedded # context. - #exe.add_python_resources(dist.read_virtualenv(path="/path/to/venv")) + #exe.add_python_resources(exe.read_virtualenv(path="/path/to/venv")) # Filter all resources collected so far through a filter of names # in a file. @@ -67,27 +225,23 @@ def make_exe(dist): # referenced by other consumers of this target. return exe -def make_embedded_data(exe): - return exe.to_embedded_data() +def make_embedded_resources(exe): + return exe.to_embedded_resources() -def make_install(dist, exe): +def make_install(exe): # Create an object that represents our installed application file layout. files = FileManifest() # Add the generated executable to our install layout in the root directory. files.add_python_resource(".", exe) - # Include pip dependencies alongside the executable - # WHEEL_PATH will be replaced with envsubst because pyoxidizer doesn't support env vars - files.add_python_resources("lib", dist.pip_install(["$WHEEL_PATH"])) - return files # Tell PyOxidizer about the build targets defined above. register_target("dist", make_dist) -register_target("exe", make_exe, depends=["dist"], default=True) -register_target("embedded", make_embedded_data, depends=["exe"], default_build_script=True) -register_target("install", make_install, depends=["dist", "exe"]) +register_target("exe", make_exe, depends=["dist"]) +register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True) +register_target("install", make_install, depends=["exe"], default=True) # Resolve whatever targets the invoker of this configuration file is requesting # be resolved. @@ -98,5 +252,5 @@ resolve_targets() # Everything below this is typically managed by PyOxidizer and doesn't need # to be updated by people. -PYOXIDIZER_VERSION = "0.6.0" +PYOXIDIZER_VERSION = "0.10.3" PYOXIDIZER_COMMIT = "" |