Skip to content

ColinConwell/CocoPack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CocoPack

Programmatic toolkits for Python, R, and shell scripting. CocoPack (inspired by R's Hmisc package) provides a somewhat random collection of utilities to streamline development workflows that I (a computational cognitive scientist) tend to use in many of my projects.

Caveat Emptor: The core functionality of this codebase is (largely) human-built and (entirely) human-tested. However, much of the documentation and supporting infrastructure (e.g. installation instructions) has been generated with ample help from Claude AI. Please use with caution.

Functionality Status:

  • Python
  • Shell
  • R Pack

Documentation and source code for the R package may be found at colinconwell.github.io/Coco-Pack-R

Quick-Start

Python Package

pip install cocopack

R Package

if (!require(pacman)) {install.packages("pacman")}
pacman::p_load_gh("colinconwell/Coco-Pack-R")

Shell Commands

pip install "cocopack[shell]"

Shell scripts are installed automatically, but if needed, you can reinstall the shell script wrappers with:

cocopack-install

Python + Shell

Install everything:

pip install "cocopack[shell]"

After installation, shell commands are available in two formats:

# Use shell commands directly
path-cleanup --remove-duplicates --apply
color-wrap RED "This text will be red!"

# Or use through the cocopack namespace
cocopack ezshell path_cleanup --remove-duplicates --apply
cocopack colorcode

Python Package Only

Install just the Python utilities:

pip install cocopack

This also installs both direct and namespaced shell commands, but doesn't emphasize the shell functionality.

Uninstallation

Remove everything:

# First, clean up shell script wrappers
cocopack uninstall-scripts

# Then uninstall the Python package
pip uninstall cocopack

This will remove both Python and shell components. You should also remove any references to cocopack commands from your .bashrc or .zshrc.

Note: When you run pip uninstall cocopack, the package will attempt to automatically clean up shell script wrappers, but it's recommended to run the explicit uninstall command first to ensure all wrappers are properly removed.

R Package (CocoPack-R)

Standalone Package:

The cocopack R package is available at CocoPack-R.

You can install this package by running the following command:

if (!require(pacman)) {install.packages("pacman")}
pacman::p_load_gh("colinconwell/CocoPack-R")

Common Workflows

Dev Environment Setup

  1. Set up your shell environment:
# Add to .bashrc or .zshrc
eval "$(cocopack prompt)"  # Load prompt utilities
eval "$(cocopack ezshell)"  # Load shell utilities

# Configure custom prompt
PS1='$(conda_prompt green) %F{cyan}%n@%m%f $(custom_path) %# '
  1. Configure Jupyter environment:
from cocopack.notebook import stylizer, magics

# Apply IDE-specific styling
stylizer.auto_style()

# Enable auto-reload for development
magics.set_autoreload('complete')

Path Management

# Clean up PATH environment variable
path_cleanup --remove-duplicates --remove-empties --apply

Other Notes & Details

Installation Options Explained
  1. Standard Installation (pip install cocopack):

    • Installs the Python package with all commands available
    • Both namespaced commands (e.g., cocopack colorcode RED "text") and direct commands (e.g., color-wrap RED "text") are available
  2. Shell Installation (pip install "cocopack[shell]"):

    • Same as standard installation but emphasizes shell functionality
    • All commands are available in both namespaced and direct forms

Presentation & Figure Support

The Python package includes presentation to image/PDF conversion functionality via the figure_ops module:

  • Unified interface for both PowerPoint and Keynote presentations:

    • Automatically detects file type (.key, .ppt, .pptx)
    • Platform-specific implementations for optimal results
  • Platform-specific exports:

    • macOS: Uses AppleScript for both Keynote and PowerPoint
    • Windows: Uses COM interface (via pywin32) for PowerPoint
    • Linux/Other: Uses LibreOffice CLI with python-pptx as fallback
  • Image processing tools:

    • Cropping whitespace around images
    • Adding customizable margins
    • Converting to high-quality PDFs

Example usage:

from cocopack.figure_ops import slides_to_images, convert_images_to_pdf

# Convert any presentation to PNGs and crop whitespace
slides_to_images('presentation.pptx', 'output_folder', crop_images=True)

# Convert to PDFs
convert_images_to_pdf('output_folder')

Note: Keynote is available exclusively on macOS. Windows users will need to install pywin32 separately if they want to use the Windows-specific COM automation:

pip install pywin32

About

Programmatic toolkits for python, R, and shellscript (terminal).

Resources

License

Stars

Watchers

Forks

Packages

No packages published