Skip to content

Fahien/dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dev

A Python framework for managing development tasks across projects.

  • Organizes commands by project namespace
  • Provides automatic command-line argument parsing based on function annotations
  • Supports tab completion for commands and arguments
  • Includes colorized logging output
  • Makes it easy to extend with new projects and commands

Installation

Prerequisites:

  • Python 3.x
  • argcomplete package for command completion

Setup

  1. Clone the repository in your dev-main directory or add it as a git submodule:

    git clone https://github.com/fahien/dev.git
    
    # or
    git submodule add https://github.com/fahien/dev.git
  2. Create a virtual environment (optional but recommended):

    python -m venv .venv
    source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`
  3. Install the required packages:

    pip install -r requirements.txt
  4. Enable global completion:

    activate-global-python-argcomplete --user
  5. Add to your shell configuration:

    For Bash or Zsh (Linux/macOS):

    # Root directory for all projects (required)
    export WORKSPACE_PATH="/path/to/your/workspace"
    DEV_PATH="$WORKSPACE_PATH/dev-main"
    DEV_MAIN_PATH="$DEV_PATH/main.py"
    DEV_VENV_BIN_PATH="$DEV_PATH/.venv/bin"
    eval "$($DEV_VENV_BIN_PATH/register-python-argcomplete $DEV_MAIN_PATH)"
    alias dev="$DEV_VENV_BIN_PATH/python3 $DEV_MAIN_PATH"

    For Windows PowerShell:

    Add the following to your PowerShell profile (e.g., Microsoft.PowerShell_profile.ps1):

    function Python-Dev-Gfxr {
        $pythonExe = Join-Path $env:LUNARG_WORKSPACE_PATH 'dev-gfxr/.venv/Scripts/python.exe'
        $mainPy = Join-Path $env:LUNARG_WORKSPACE_PATH 'dev-gfxr/main.py'
        & $pythonExe $mainPy $args
    }
    New-Alias lunarg Python-Dev-Gfxr
    
    register-python-argcomplete.exe --shell powershell lunarg | Out-String | Invoke-Expression

Usage

Run commands with the following structure:

dev <project-name> <command> [arguments]

Example:

dev myproject build --config release

Project Structure

  • __init__.py - Sets up imports
  • config.py - Handles command-line parsing
  • log.py - Implements colored logging
  • project.py - Defines the base Project class
  • util.py - Provides utility functions

Creating New Projects

  1. Create a new Python file in the dev-main/projects directory
  2. Define a class that extends Project from the projects module
  3. Add methods decorated with @command for each method that you want to be exposed to the CLI

Example:

from enum import Enum
from project import Project, command, BuildType
import util

class MyProject(Project):
    def __init__(self):
        Project.__init__(self, "myproject")  # This sets the project name for CLI

    @command
    def build(self, config: BuildType = BuildType.DEBUG):
        """Build the project with specified configuration."""
        util.run(["make", f"CONFIG={config}"], cwd=self.project_path)

    @command
    def clean(self):
        """Clean build artifacts."""
        util.run(["make", "clean"], cwd=self.project_path)

Features

  • Commands can use type annotations to define the values expected through the CLI:

    @command
    def deploy(self, target: str, verbose: bool = False):
        """Deploy to specified target."""
        # Implementation here

    Will yield:

    $ dev myproject deploy --help
    usage: dev myproject deploy [-h] [--verbose VERBOSE] target
    
    Deploy to specified target.
    
    positional arguments:
      target                str
    
    optional arguments:
      -h, --help           show this help message and exit
      --verbose VERBOSE    bool (default: False)
  • Enum types are automatically converted to command-line choices via the __str__ method:

    class Platform(Enum):
        LINUX = "linux"
        MACOS = "macos"
        WINDOWS = "windows"
    
        def __str__(self):
            return self.value
    
    @command
    def build_for(self, platform: Platform):
        """Build for specific platform."""
        # Implementation

    Will yield:

    $ dev myproject build_for --help
    usage: dev myproject build_for [-h] {linux,macos,windows}
    
    Build for specific platform.
    
    positional arguments:
      {linux,macos,windows}
    
    optional arguments:
      -h, --help            show this help message and exit
  • Default values for optional arguments:

    @command
    def build(self, config: BuildType = BuildType.DEBUG):
        """Build the project with specified configuration."""
        util.run(["make", f"CONFIG={config}"], cwd=self.project_path)

    Will yield:

    $ dev myproject build --help
    usage: dev myproject build [-h] [--config {debug,release}]
    
    Build the project with specified configuration.
    
    optional arguments:
      -h, --help            show this help message and exit
      --config {debug,release}
                            None (default: debug)
  • Use the built-in colored logging:

    import logging
    
    logging.info("Starting build process...")
    logging.warning("Configuration file not found")
    logging.error("Build failed")

License

Dual licensed under either

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Development environment

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages