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
-
-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
-
-d, --dir: The directory where the compiled files will be stored.- Type: String
- Default:
dist - Example:
-d output_directory
-
-v, --version: The Python language level to use for the compilation.- Type: Integer
- Default:
3 - Example:
-v 2for Python 2.x compatibility
-
-c, --copy_py: List of Python files to copy without compiling.- Type: List of strings
- Default:
[](empty list) - Example:
-c script1.py script2.py
-
-p, --parallel: Number of parallel workers to use for compilation.- Type: Integer
- Default: Number of CPU cores available
- Example:
-p 4to 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
- Argument Parsing: The
parse_argsfunction usesargparseto handle command-line arguments. - File Listing: The
lsfunction recursively lists all files in the directory. - Migration File Check: The
is_migration_filefunction checks if a file is a Django migration file. - Copying Ignored Files: The
copy_ignorefunction copies files that should be ignored during compilation. - Compilation: The
compile_modulefunction compiles a single module using Cython. - Build Process: The
buildfunction handles the overall build process, including parallel compilation and cleanup. - Main Function: The
mainfunction 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for neverland_tools-0.1.dev7-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 16bfae1c4d1ed6f579ce803aa902d23259c6dc5a34f8b4cccf2f59a496e9b038 |
|
| MD5 | 6e24296b87081716dec2618fabeecb33 |
|
| BLAKE2b-256 | cc93003a68e1015dc5f017ba09903bd30851cabc2149b89a540daac127d1b29e |