### Environment File Example (.env) Source: https://github.com/nickstenning/honcho/blob/main/doc/using_procfiles.rst Demonstrates how to create a .env file to specify environment variables for Honcho processes. These variables are made available to all processes started by Honcho. ```shell $ cat >.env <: ``` -------------------------------- ### Run a Specific Tox Environment Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Example of how to run a specific tox test environment, such as for Python 3.9, using the '-e' flag. ```bash tox -e py39 ``` -------------------------------- ### Environment File (.env) Configuration Example Source: https://context7.com/nickstenning/honcho/llms.txt Shows the format of an .env file, which is used to define environment variables for all processes managed by Honcho. These variables can include database URLs, port numbers, and secret keys. ```env # .env - environment variables for all processes RACK_ENV=production DATABASE_URL=postgresql://localhost/mydb REDIS_URL=redis://localhost:6379/0 PORT=5000 SECRET_KEY=mysecretkey PYTHONUNBUFFERED=true ``` -------------------------------- ### Basic Procfile Structure Example Source: https://context7.com/nickstenning/honcho/llms.txt Defines the basic structure of a Procfile, where each line specifies a process type and its corresponding command. This format is used by Honcho to manage application processes. ```procfile # Procfile - each line defines a process type web: gunicorn -b "0.0.0.0:$PORT" -w 4 myapp:app worker: python worker.py --priority high,med,low worker_low: python worker.py --priority med,low redis: redis-server scheduler: python scheduler.py ``` -------------------------------- ### Honcho Invocation with Custom Options Source: https://github.com/nickstenning/honcho/blob/main/doc/using_procfiles.rst An example of how to invoke Honcho with custom options, such as specifying a different application root directory and Procfile name. This is useful when your project structure deviates from the defaults. ```shell $ honcho -d .. -f Procfile.dev start ``` -------------------------------- ### Display Honcho Version and Help using CLI Source: https://context7.com/nickstenning/honcho/llms.txt These commands display the version information of Honcho and provide help messages. 'honcho version' shows the installed version, while 'honcho help' provides general help or specific command help. ```bash # Show Honcho version honcho version # General help honcho help # Help for specific command honcho help start ``` -------------------------------- ### Python Plugin for Custom Honcho Exporter Source: https://github.com/nickstenning/honcho/blob/main/doc/export.rst Illustrates how to create a custom exporter plugin for Honcho using Python. This example defines a `SimpleExport` class that inherits from `honcho.export.base.BaseExport` and uses Jinja2 for templating. It includes methods to load templates and render them for each process. ```python import jinja2 from honcho.export.base import BaseExport class SimpleExport(BaseExport): def get_template_loader(self): return jinja2.PackageLoader(package_name=__package__, package_path='templates') def render(self, processes, context): tpl = get_template('run.sh') for p in processes: filename = 'run-{0}.sh'.format(p.name) ctx = context.copy() ctx['process'] = p script = tpl.render(ctx) ``` -------------------------------- ### Python API: Manager Class for Process Management Source: https://context7.com/nickstenning/honcho/llms.txt Demonstrates how to use the `Manager` class from the `honcho.manager` module to programmatically start and manage multiple processes. It allows adding processes with custom commands, environments, and working directories, and includes a custom printer for output. ```python import sys from honcho.manager import Manager from honcho.printer import Printer # Create a manager instance with custom printer printer = Printer(sys.stdout, colour=True, prefix=True) manager = Manager(printer=printer) # Add processes to the manager manager.add_process('web', 'python server.py', env={'PORT': '8000'}) manager.add_process('worker', 'python worker.py', quiet=False) manager.add_process('redis', 'redis-server', cwd='/var/lib/redis') # Start all processes and wait for completion manager.loop() # Exit with appropriate return code sys.exit(manager.returncode) ``` -------------------------------- ### Setting PYTHONUNBUFFERED for Unbuffered Output in Honcho Source: https://github.com/nickstenning/honcho/blob/main/doc/using_procfiles.rst This example demonstrates how to set the PYTHONUNBUFFERED environment variable within a Procfile to ensure that Python programs do not buffer their output when run through Honcho. This is crucial for seeing small amounts of output in real-time. No external dependencies are required beyond Python and Honcho. ```Procfile myprogram: PYTHONUNBUFFERED=true python myprogram.py ``` -------------------------------- ### Process Events from Queue Source: https://context7.com/nickstenning/honcho/llms.txt Processes messages from an event queue, handling 'start', 'line', and 'stop' message types. It prints information about process status and output lines. No external dependencies are explicitly shown for this snippet. ```python while not events.empty(): msg = events.get() if msg.type == 'start': print(f"Process started with PID: {msg.data['pid']}") elif msg.type == 'line': print(f"Output: {msg.data}") elif msg.type == 'stop': print(f"Process exited with code: {msg.data['returncode']}") ``` -------------------------------- ### Registering a Custom Honcho Exporter with Setuptools Source: https://github.com/nickstenning/honcho/blob/main/doc/export.rst Shows how to register a custom Honcho exporter plugin using the `entry_points` mechanism in a `setup.py` file. This allows Honcho to discover and utilize the custom exporter format. ```python from setuptools import setup setup( name='honcho_export_simple', ... entry_points={ 'honcho_exporters': [ 'simple=honcho_export_simple:SimpleExport', ], }, ) ``` -------------------------------- ### Honcho Command-Line Help Source: https://github.com/nickstenning/honcho/blob/main/doc/using_procfiles.rst Displays the available command-line arguments and tasks for the Honcho utility. It shows options for specifying environment files, application root directories, and Procfile paths. ```shell $ honcho --help usage: honcho [-h] [-e ENV] [-d DIR] [--no-colour] [--no-prefix] [-f FILE] [-v] {check,export,help,run,start,version} ... Manage Procfile-based applications optional arguments: -h, --help show this help message and exit -e ENV, --env ENV environment file[,file] (default: .env) -d DIR, --app-root DIR procfile directory (default: .) --no-colour disable coloured output --no-prefix disable logging prefix -f FILE, --procfile FILE procfile path (default: Procfile) -v, --version show program's version number and exit tasks: {check,export,help,run,start,version} check validate a Procfile export export a Procfile to another format help describe available tasks or one specific task run run a command using your application's environment start start the application (or a specific PROCESS) version display honcho version ``` -------------------------------- ### List Available Tox Environments Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Command to display a list of all available testing environments configured in tox. ```bash tox -l ``` -------------------------------- ### Merging Environment Files in Honcho Source: https://github.com/nickstenning/honcho/blob/main/doc/using_procfiles.rst Illustrates how Honcho can merge environment variables from multiple files specified with the -e option. This allows for a more organized way to manage different environment configurations. ```shell $ echo 'ANIMAL_1=giraffe' >.env.one $ echo 'ANIMAL_2=elephant' >.env.two $ honcho -e .env.one,.env.two run sh -c 'env | grep -i animal' ANIMAL_1=giraffe ANIMAL_2=elephant ``` -------------------------------- ### Run Tox with Pytest Arguments Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Demonstrates how to pass arguments to pytest through tox, such as using pytest's '-x' flag (stop after first error) with a specific interpreter like PyPy. ```bash tox -e pypy -- -x ``` -------------------------------- ### Clone Honcho Repository Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Instructions for cloning the Honcho repository to your local machine after forking it on GitHub. ```bash $ git clone git@github.com:your_name_here/honcho.git ``` -------------------------------- ### Run All Tox Environments Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Command to execute all defined test environments using tox, ensuring compatibility across different Python versions. ```bash tox ``` -------------------------------- ### Python API: Process Class for Single Process Execution Source: https://context7.com/nickstenning/honcho/llms.txt Illustrates the use of the `Process` class from the `honcho.process` module to run a single process with output capture. It allows configuring the command, name, color, quiet mode, environment variables, and handling process events. ```python import multiprocessing from honcho.process import Process # Create a queue for process events events = multiprocessing.Queue() # Create and configure a process proc = Process( cmd='python server.py', name='web', colour=32, # ANSI color code (green) quiet=False, env={'PORT': '5000', 'DEBUG': 'true'} ) # Run the process (blocks until process exits) proc.run(events=events, ignore_signals=True) ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Steps to stage, commit, and push your local changes to your GitHub fork. It includes adding all changes, committing with a descriptive message, and pushing the branch. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Env - Parse and Load Procfile Configurations (Python) Source: https://context7.com/nickstenning/honcho/llms.txt Parses and loads process configurations from a Procfile and .env files using the honcho.environ module. It handles environment variable expansion and process concurrency. Dependencies include honcho.environ. ```python from honcho.environ import Env, parse_procfile, parse, expand_processes # Create Env instance with configuration config = { 'app_root': '.', 'procfile': 'Procfile', 'port': '5000' } env = Env(config) # Load and parse Procfile procfile = env.load_procfile() for name, cmd in procfile.processes.items(): print(f"{name}: {cmd}") # Parse .env file content env_content = """ DATABASE_URL=postgresql://localhost/mydb REDIS_URL=redis://localhost:6379 DEBUG=true """ env_vars = parse(env_content) print(env_vars) # {'DATABASE_URL': '...', 'REDIS_URL': '...', 'DEBUG': 'true'} # Expand processes with concurrency processes = expand_processes( processes={'web': 'python server.py', 'worker': 'python worker.py'}, concurrency={'web': 2, 'worker': 3}, env={'SECRET_KEY': 'abc123'}, port=5000 ) # Results in 5 ProcessParams objects: # web.1 (PORT=5000), web.2 (PORT=5001) # worker.1 (PORT=5100), worker.2 (PORT=5101), worker.3 (PORT=5102) for p in processes: print(f"{p.name}: {p.cmd}") print(f" Environment: {p.env}") print(f" Quiet: {p.quiet}") ``` -------------------------------- ### Execute Command with Environment using Honcho CLI Source: https://context7.com/nickstenning/honcho/llms.txt This command runs an arbitrary command with the application environment loaded from .env files. It supports multiple environment files and custom application root directories. ```bash # Run arbitrary command with environment from .env honcho run python manage.py shell # Run with multiple env files (comma-separated) honcho -e .env,.env.local run rails console # Execute shell script with application config honcho run bash scripts/deploy.sh # Run with custom app root directory honcho -d /path/to/app run npm test ``` -------------------------------- ### Printer - Format and Display Process Output (Python) Source: https://context7.com/nickstenning/honcho/llms.txt Formats and displays process output using the honcho.printer module. It supports custom time formats, padding, coloring, and prefixes for messages. Dependencies include sys, datetime, and honcho.printer. ```python import sys import datetime from honcho.printer import Printer, Message # Create printer with custom formatting printer = Printer( output=sys.stdout, time_format="%H:%M:%S", width=10, # Width for process name padding colour=True, prefix=True ) # Create and write a message msg = Message( type='line', data=b'Server started on port 5000\n', time=datetime.datetime.now(), name='web', colour=32 # Green ANSI color code ) printer.write(msg) # Output format: "14:32:15 web | Server started on port 5000" # Write system message without color system_msg = Message( type='line', data='All processes started\n', time=datetime.datetime.now(), name='system', colour=None ) printer.write(system_msg) ``` -------------------------------- ### Custom Export - Create Process Management Configurations (Python) Source: https://context7.com/nickstenning/honcho/llms.txt Defines a custom export mechanism for generating process management configuration files, extending honcho.export.base.BaseExport. It uses Jinja2 templating for rendering configurations. Dependencies include honcho.export, jinja2, and honcho.environ. ```python from honcho.export.base import BaseExport, File from jinja2 import PackageLoader class CustomExport(BaseExport): def get_template_loader(self): return PackageLoader('mypackage', 'templates') def render(self, processes, context): """ Generate configuration files for process management. Args: processes: List of ProcessParams with name, cmd, env, quiet context: Dict with app, app_root, log, shell, user keys Yields: File objects with name, content, executable attributes """ template = self.get_template('myformat.conf') for process in processes: content = template.render( process=process, app=context['app'], user=context['user'], log_dir=context['log'] ) filename = f"{context['app']}-{process.name}.conf" yield File(name=filename, content=content, executable=False) # Use the custom exporter from honcho.environ import Env, expand_processes config = {'app_root': '.', 'procfile': 'Procfile', 'port': '5000'} env = Env(config) procfile = env.load_procfile() processes = expand_processes( procfile.processes, concurrency={'web': 2}, env={'DATABASE_URL': 'postgresql://localhost/db'}, port=5000 ) exporter = CustomExport() context = { 'app': 'myapp', 'app_root': '/opt/myapp', 'log': '/var/log/myapp', 'shell': '/bin/bash', 'user': 'appuser' } for file in exporter.render(processes, context): with open(f'/etc/myformat/{file.name}', 'w') as f: f.write(file.content) if file.executable: import os os.chmod(f'/etc/myformat/{file.name}', 0o755) ``` -------------------------------- ### Popen - Subprocess Wrapper for Process Execution (Python) Source: https://context7.com/nickstenning/honcho/llms.txt Wraps subprocess execution using honcho.process.Popen, allowing for management of child processes. It supports environment variables, working directories, and capturing output. Dependencies include honcho.process and subprocess. ```python from honcho.process import Popen import subprocess # Create a managed subprocess proc = Popen( 'python server.py', env={'PORT': '5000', 'DEBUG': 'true'}, cwd='/path/to/app', start_new_session=True ) # Read output line by line for line in iter(proc.stdout.readline, b''): print(line.decode('utf-8'), end='') # Wait for completion proc.stdout.close() proc.wait() print(f"Process exited with code: {proc.returncode}") ``` -------------------------------- ### Export Procfile to Process Management Formats using Honcho CLI Source: https://context7.com/nickstenning/honcho/llms.txt This command exports the Procfile configuration to various process management formats like systemd, supervisord, upstart, and runit. It supports custom application names, users, concurrency, ports, log directories, and custom templates. ```bash # Export to systemd honcho export -a myapp -u myuser systemd /etc/systemd/system # Export to supervisord with custom concurrency honcho export -c web=2,worker=4 -a myapp supervisord /etc/supervisor/conf.d # Export to upstart with port and log configuration honcho export -p 5000 -l /var/log/myapp -a myapp upstart /etc/init # Export to runit with custom shell honcho export -s /bin/bash -a myapp runit /etc/service # Use custom templates directory honcho export -t ./templates/supervisord -a myapp supervisord /etc/supervisor/conf.d ``` -------------------------------- ### Create a New Branch for Development Source: https://github.com/nickstenning/honcho/blob/main/CONTRIBUTING.rst Command to create a new Git branch for developing bug fixes or new features. ```bash git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Validate Procfile Syntax with Honcho CLI Source: https://context7.com/nickstenning/honcho/llms.txt This command checks the syntax of the Procfile. It can validate the default Procfile or a specific one, and provides output indicating if the Procfile is valid. ```bash # Check default Procfile honcho check # Validate specific Procfile honcho -f Procfile.production check # Expected output for valid Procfile: # Valid procfile detected (web, worker, redis) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.