<commit_before><?php
/**
 * Library installation and packaging script.
 *
 * This is based on python.distutils setup scripts.
 */
require_once 'serial/version.php';


// The packages-specific configuration array.

$PACKAGE_CONFIG = array(
    "name" => "serial",
    "version" => SERIAL_VERSION,
);



// Execute the script.

$_DEBUG = false;  // should be command-line setting
$_COMMANDS = array('test' => 'TestCommand', 'archive' => 'ArchiveCommand');

try {
    if ($argc == 1) {
        echo 'usage: setup.php cmd'.PHP_EOL;
        exit(1);
    }
    exit(main($PACKAGE_CONFIG, $argv)); 
}
catch (Exception $ex) {
    if ($_DEBUG) {
        throw $ex;  // force a stack trace
    }
    echo $ex->getMessage().PHP_EOL;
    exit(1);
}


/** 
 * Script controller.
 *
 */
function main($config, $argv)
{
    // Configuration values and command-line options are blended together into
    // a single array with command-line options taking precedence in the case
    // of duplicates.
    global $_COMMANDS;
    foreach (array_slice($argv, 1) as $cmdname) {
        if (!($cmdclass = @$_COMMANDS[$cmdname])) {
            $message = "unknown command name: {$cmdname}";
            throw new InvalidArgumentException($message);
        }
        $command = new $cmdclass();
        if (($status = $command($config)) != 0) {
            $message = "command failed: {$cmdname} ({$status})";
            throw new RuntimeException($message);
        }        
    }
    return 0;
}


abstract class Command
{
    /** 
     * Return an array of options that this command is interested in.
     * 
     */
    public function register_options()
    {
        return array();
    }
    
    /**
     * Execute the command.
     *
     * The command should return zero on success or any nonzero value on
     * failure.
     */
    abstract public function __invoke($config);
}


/**
 * Execute the test suite for this package.
 *
 */
class TestCommand extends Command
{
    /**
     * Execute the command.
     *
     * A nonzero value is returned if the test suite fails.
     */
    public function __invoke($config)
    {
        system('php -f test/run_tests.php', $status);
        return $status;
    }
}


/**
 * Create a PHP Archive (.phar) file for this package.
 *
 */
class ArchiveCommand extends Command<commit_msg>renamed 'archive' command to 'dist' in setup.php<commit_after><?php
/**
 * Library installation and packaging script.
 *
 * This is based on python.distutils setup scripts.
 */
require_once 'serial/version.php';


// The package-specific configuration array.

$PACKAGE_CONFIG = array(
    "name" => "serial",
    "version" => SERIAL_VERSION,
);



// Execute the script.

$_DEBUG = false;  // should be command-line setting
$_COMMANDS = array('test' => 'TestCommand', 'dist' => 'DistCommand');

try {
    if ($argc == 1) {
        echo 'usage: setup.php cmd'.PHP_EOL;
        exit(1);
    }
    exit(main($PACKAGE_CONFIG, $argv)); 
}
catch (Exception $ex) {
    if ($_DEBUG) {
        throw $ex;  // force a stack trace
    }
    echo $ex->getMessage().PHP_EOL;
    exit(1);
}


/** 
 * Script controller.
 *
 */
function main($config, $argv)
{
    // Configuration values and command-line options are blended together into
    // a single array with command-line options taking precedence in the case
    // of duplicates.
    global $_COMMANDS;
    foreach (array_slice($argv, 1) as $cmdname) {
        if (!($cmdclass = @$_COMMANDS[$cmdname])) {
            $message = "unknown command name: {$cmdname}";
            throw new InvalidArgumentException($message);
        }
        $command = new $cmdclass();
        if (($status = $command($config)) != 0) {
            $message = "command failed: {$cmdname} ({$status})";
            throw new RuntimeException($message);
        }        
    }
    return 0;
}


abstract class Command
{
    /** 
     * Return an array of options that this command is interested in.
     * 
     */
    public function register_options()
    {
        return array();
    }
    
    /**
     * Execute the command.
     *
     * The command should return zero on success or any nonzero value on
     * failure.
     */
    abstract public function __invoke($config);
}


/**
 * Execute the test suite for this package.
 *
 */
class TestCommand extends Command
{
    /**
     * Execute the command.
     *
     * A nonzero value is returned if the test suite fails.
     */
    public function __invoke($config)
    {
        system('php -f test/run_tests.php', $status);
        return $status;
    }
}


/**
 * Create a PHP Archive (.phar) file for distribution.
 *
 */
class DistCommand extends Command
{'fraction_non_alphanumeric': 0.1297447994853099, 'fraction_numerical': 0.0025734505683036673, 'mean_word_length': 2.352983465132998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1582784', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1350, 'n_words': 426}