Skip to main content

A tool to compile Python files to shared objects using Cython.

Project description

Neverland Tools

A collection of tools for development.

Installation

pip install neverland-tools

neverland-compile

Overview

neverland-compile is a tool designed to compile Python files into C extensions using Cython. This can help improve the performance of your Python code. The script supports parallel compilation to speed up the process, and it allows you to ignore certain files or directories, copy specific Python files without compiling them, and specify the output directory and Python language version.

Command-Line Arguments

  1. -i, --ignore: List of files or directories to ignore during compilation.

    • Type: List of strings
    • Default: [] (empty list)
    • Example: -i file_to_ignore.py dir_to_ignore
  2. -d, --dir: The directory where the compiled files will be stored.

    • Type: String
    • Default: dist
    • Example: -d output_directory
  3. -v, --version: The Python language level to use for the compilation.

    • Type: Integer
    • Default: 3
    • Example: -v 2 for Python 2.x compatibility
  4. -c, --copy_py: List of Python files to copy without compiling.

    • Type: List of strings
    • Default: [] (empty list)
    • Example: -c script1.py script2.py
  5. -p, --parallel: Number of parallel workers to use for compilation.

    • Type: Integer
    • Default: Number of CPU cores available
    • Example: -p 4 to use 4 parallel workers

Example Usage

Basic Compilation

To compile all Python files in the current directory and store the compiled files in the dist directory:

neverland-compile

Ignoring Specific Files

To ignore specific files or directories during compilation:

neverland-compile -i file_to_ignore.py dir_to_ignore

Specifying Output Directory

To specify a custom output directory for the compiled files:

neverland-compile -d output_directory

Specifying Python Version

To specify the Python language level for the compilation:

neverland-compile -v 2

Copying Specific Python Files Without Compiling

To copy specific Python files without compiling them:

neverland-compile -c script1.py script2.py

Using Parallel Compilation

To use a specific number of parallel workers:

neverland-compile -p 4

Script Breakdown

  1. Argument Parsing: The parse_args function uses argparse to handle command-line arguments.
  2. File Listing: The ls function recursively lists all files in the directory.
  3. Migration File Check: The is_migration_file function checks if a file is a Django migration file.
  4. Copying Ignored Files: The copy_ignore function copies files that should be ignored during compilation.
  5. Compilation: The compile_module function compiles a single module using Cython.
  6. Build Process: The build function handles the overall build process, including parallel compilation and cleanup.
  7. Main Function: The main function is the entry point of the script, which parses arguments and calls the build function.

Conclusion

neverland-compile is a versatile tool for compiling Python files into C extensions. By using the provided command-line arguments, you can customize the compilation process to suit your needs, whether it's ignoring specific files, copying certain Python files, or leveraging parallel processing to speed up the compilation.

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

neverland_tools-0.1.dev7.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

neverland_tools-0.1.dev7-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file neverland_tools-0.1.dev7.tar.gz.

File metadata

  • Download URL: neverland_tools-0.1.dev7.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for neverland_tools-0.1.dev7.tar.gz
Algorithm Hash digest
SHA256 39ee5bdca459e7b948a1d44bacb262d018050900479f285cdc839b003fdd246b
MD5 7fd714c7cd3928447d52bf7ceda5186e
BLAKE2b-256 8b18730e533e58c4b35b29ec8a5c1c70d1b299a27e4f2026a30f365bd633616d

See more details on using hashes here.

File details

Details for the file neverland_tools-0.1.dev7-py3-none-any.whl.

File metadata

File hashes

Hashes for neverland_tools-0.1.dev7-py3-none-any.whl
Algorithm Hash digest
SHA256 16bfae1c4d1ed6f579ce803aa902d23259c6dc5a34f8b4cccf2f59a496e9b038
MD5 6e24296b87081716dec2618fabeecb33
BLAKE2b-256 cc93003a68e1015dc5f017ba09903bd30851cabc2149b89a540daac127d1b29e

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