kauffinger/pyman

A skeleton repository for my packages

Fund package maintenance!
kauffinger

v0.0.2 2024-12-22 14:25 UTC

This package is auto-updated.

Last update: 2024-12-22 14:27:43 UTC


README

Latest Version on Packagist Linting Tests Total Downloads

Pyman is a PHP package that simplifies the management of Python dependencies in PHP applications. It's designed to help you seamlessly integrate Python scripts and libraries into your PHP projects by handling virtual environment setup and dependency management.

Features

  • Automatic Python virtual environment creation
  • Python dependency management via requirements.txt
  • Easy integration with Laravel's Process handling
  • Robust error handling for common Python-related issues

Requirements

  • PHP 8.3+
  • Python 3.x
  • pip3

Installation

You can install the package via composer:

composer require kauffinger/pyman

Usage

use Kauffinger\Pyman\PythonEnvironmentManager;
use Illuminate\Process\Factory;

// Initialize the manager with a base path for your Python environment
$manager = new PythonEnvironmentManager('/path/to/python/environment', new Factory());

// Set up the environment (creates venv and installs dependencies)
try {
    $manager->setup();
} catch (PymanException $e) {
    // Handle any setup errors
    echo $e->getMessage();
}

Requirements File

Create a requirements.txt file in your specified Python environment directory:

requests==2.31.0
# Add other Python dependencies as needed

Error Handling

The package throws PymanException in the following cases:

  • Python3 or pip3 is not installed
  • Failed to create the Python directory
  • Missing requirements.txt file
  • Failed to install Python dependencies
  • Failed to create virtual environment

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.