Skip to main content

Python module inlining library

Project description

InlineImporter

InlineImporter is a library for python projects that uses the PEP 302 import protocol to inline libraries into a script.

Why?

Because we can.

But in all seriousness, this came out from spending days managing adhoc scripts that shared a lot of functionality. For ease of development, it would have been nice to extract the common pieces to a common library, but that would have meant distributing a whole directory and managing import paths on the destination systems versus a single self-contained file.

How it works

PEP 302 defined a protocol for managing module imports. The protocol defines two components: Finders and Loaders. The Finder is responsible for, unsurprisingly, finding modules. If a Finder finds a module, i.e. knows which loader can load a module, it returns a ModuleSpec. This ModuleSpec gives details on some parameters of the module, such as filename and package, and states which Loader can load the module. The Loader is, as you've guessed it, responsible for loading modules into the environment. It does so by first creating a module object, which the python machinery places into the sys.modules dictionary, then executing the module code. An object that can both Find and Load is called an Importer.

InlineImporter works by placing the source code of modules in a dictionary, keyed by module name. The finder searche the dictionary for a key matching the given module name. If found, it returns a ModuleSpec with itself listed as the loader. The loader simply compiles the inlined source code to python bytecode, and executes it as the normal python loader does.

Usage

Include inline-importer in your development dependencies. inline-importer is not a runtime dependency, but a build-time dependency instead.

Build your final script using TDB and distribute the output of that instead.

Your users will not require inline-importer. However, if you have dependencies on other modules, your users will have to install those.

What's next

While the importer is built, the rest of the machinery isn't.

  • Importer with PoC.
  • Script to collect all the modules to be inlined and build the dictionary.
  • Script that can combine the importer and the modules.
  • Support for inlining distributed python libraries.
  • Support for pre-compiled bytecode.

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

inline-importer-0.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

inline_importer-0.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file inline-importer-0.0.1.tar.gz.

File metadata

  • Download URL: inline-importer-0.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

File hashes

Hashes for inline-importer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 56cbc6363ee85d41be7974bc4b18cdd533230c2675e16b1cf23b6eefdddb36db
MD5 a18f9351dfd5e914bce96f3070b4c5b2
BLAKE2b-256 86c395b8ce24b260cfdf1c199db1a4837e0844296d548b125e7b42b421befdef

See more details on using hashes here.

File details

Details for the file inline_importer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: inline_importer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

File hashes

Hashes for inline_importer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73fa854555fa614fbdc69936962039fcd11711f01c3283f5a7c9b1ee992d5ed4
MD5 f89557fa7f092b646b416baa9476aa99
BLAKE2b-256 c628ebdae27fa18e8a8226e98c822cfe2a94fb4f376578712222a650bc9764d9

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