<commit_before>import click
from proscli.utils import default_cfg
import os
import os.path
import subprocess
import sys

import json

@click.group()
def upgrade_cli():
    pass


def get_upgrade_command():
    if getattr(sys, 'frozen', False):
        cmd = os.path.abspath(os.path.join(sys.executable, '..', '..', 'updater.exe'))
        if os.path.exists(cmd):
            return [cmd, '/silentall', '-nofreqcheck']
        else:
            return False
    else:
        try:
            from pip._vendor import pkg_resources
            results = [p for p in pkg_resources.working_set if p.project_name == 'pros-cli']
            if os.path.exists(os.path.join(results[0].location, '.git')):
                if subprocess.run('where git').returncode == 0:
                    return ['git', 'pull']
                elif subprocess.run('where bash').returncode == 0:
                    return ['bash', '-c', 'git pull']
                else:
                    return False
            if len(results) == 0 or not hasattr(results[0], 'location'):
                return False
            else:
                return ['pip', 'install', '-U', '-t', results[0].location, 'pros-cli']
        except Exception:
            return False


@upgrade_cli.command('upgrade', help='Provides a facility to run upgrade the PROS CLI')
@default_cfg
def upgrade(cfg):
    cmd = get_upgrade_command()
    if cmd is False:
        click.echo('Could not determine installation type.')
        sys.exit(1)
        return
    elif not cfg.machine_output:
        sys.exit(subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode
    else:
        for piece in cmd:
            click.echo(piece)
<commit_msg>upgrade will now detect if the installation is from git and update accordingly<commit_after>import click
from proscli.utils import default_cfg
import os
import os.path
import subprocess
import sys

import json

@click.group()
def upgrade_cli():
    pass


def get_upgrade_command():
    if getattr(sys, 'frozen', False):
        cmd = os.path.abspath(os.path.join(sys.executable, '..', '..', 'updater.exe'))
        if os.path.exists(cmd):
            return [cmd, '/silentall', '-nofreqcheck']
        else:
            return False
    else:
        try:
            from pip._vendor import pkg_resources
            results = [p for p in pkg_resources.working_set if p.project_name == 'pros-cli']
            if os.path.exists(os.path.join(results[0].location, '.git')):
                click.echo('Development environment detected.')
                with open(os.devnull) as devnull:
                    if subprocess.run('where git', stdout=devnull).returncode == 0:
                        click.echo('Using git.exe')
                        return ['git', '-C', results[0].location, 'pull']
                    else:
                        click.echo('No suitable Git executable found.')
                        return False
            if len(results) == 0 or not hasattr(results[0], 'location'):
                return False
            else:
                return ['pip', 'install', '-U', '-t', results[0].location, 'pros-cli']
        except Exception:
            return False


@upgrade_cli.command('upgrade', help='Provides a facility to run upgrade the PROS CLI')
@default_cfg
def upgrade(cfg):
    cmd = get_upgrade_command()
    if cmd is False:
        click.echo('Could not determine installation type.')
        sys.exit(1)
        return
    elif not cfg.machine_output:
        try:
            for line in execute(cmd):
                click.echo(line)
        except subprocess.CalledProcessError:
            click.echo('An error occurred. Aborting...')
            sys.exit(1)
        sys.exit()
    else:
        for piece in cmd:
            click.echo(piece)


def execute(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
    for stdout_line in iter(p.stdout.readline, ""):
        yield stdout_line

    p.stdout.close()
    r = p.wait()
    if r:
        raise subprocess.CalledProcessError(r, cmd)

{'fraction_non_alphanumeric': 0.11731569924075434, 'fraction_numerical': 0.0036737692872887582, 'mean_word_length': 2.040953090096798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4779756', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1149, 'n_words': 319}