<commit_before>"""Handy utility functions."""

import collections
import contextlib
import functools
import logging
import os
import platform
import shlex
import shutil
import string as string_module      # string is used as a variable name
import subprocess
import sys
import threading
import tkinter
from tkinter import ttk
import traceback

import porcupine

log = logging.getLogger(__name__)


# nsis installs a python to e.g. C:\Users\Akuli\AppData\Local\Porcupine\Python
# TODO: document this
_running_in_nsis = (
    platform.system() == 'Windows' and
    os.path.dirname(sys.executable).lower().endswith(r'\porcupine\python'))


if platform.system() == 'Windows':
    running_pythonw = True
    if sys.stdout is None and sys.stderr is None:
        # running in pythonw.exe so there's no console window, print still
        # works because it checks if sys.stdout is None
        running_pythonw = True
    elif (_running_in_nsis and
          sys.stdout is sys.stderr and
          isinstance(sys.stdout.name, str) and   # not sure if it can be None
          os.path.dirname(sys.stdout.name) == os.environ['APPDATA']):
        # pynsist generates a script that does this:
        #
        #   sys.stdout = sys.stderr = open(blablabla, 'w', **kw)
        #
        # where blablabla is a file directly in %APPDATA%... that's dumb and
        # non-standard imo, and not suitable for porcupine because porcupine
        # takes care of that itself, so... let's undo what it just did
        #
        # TODO: actually take care of the stuff by adding a custom
        #       sys.excepthook, rn exceptions are ignored!
        # TODO: it's possible to write a custom startup script, do that? there
        #       are docs somewhere
        sys.stdout.close()
        os.remove(sys.stdout.name)
        sys.stdout = None
        sys.stderr = None<commit_msg>because verbose is better than implicit.... or somethino<commit_after>"""Handy utility functions."""

import collections
import contextlib
import functools
import logging
import os
import platform
import shlex
import shutil
import string as string_module      # string is used as a variable name
import subprocess
import sys
import threading
import tkinter
from tkinter import ttk
import traceback

import porcupine

log = logging.getLogger(__name__)


# nsis installs a python to e.g. C:\Users\Akuli\AppData\Local\Porcupine\Python
# TODO: document this
_installed_with_pynsist = (
    platform.system() == 'Windows' and
    os.path.dirname(sys.executable).lower().endswith(r'\porcupine\python'))


if platform.system() == 'Windows':
    running_pythonw = True
    if sys.stdout is None and sys.stderr is None:
        # running in pythonw.exe so there's no console window, print still
        # works because it checks if sys.stdout is None
        running_pythonw = True
    elif (_installed_with_pynsist and
          sys.stdout is sys.stderr and
          isinstance(sys.stdout.name, str) and   # not sure if it can be None
          os.path.dirname(sys.stdout.name) == os.environ['APPDATA']):
        # pynsist generates a script that does this:
        #
        #   sys.stdout = sys.stderr = open(blablabla, 'w', **kw)
        #
        # where blablabla is a file directly in %APPDATA%... that's dumb and
        # non-standard imo, and not suitable for porcupine because porcupine
        # takes care of that itself, so... let's undo what it just did
        #
        # TODO: actually take care of the stuff by adding a custom
        #       sys.excepthook, rn exceptions are ignored!
        # TODO: it's possible to write a custom startup script, do that? there
        #       are docs somewhere
        sys.stdout.close()
        os.remove(sys.stdout.name)
        sys.stdout = None
        sys.stderr = None
{'fraction_non_alphanumeric': 0.08230018464785017, 'fraction_numerical': 0.0, 'mean_word_length': 2.7176470588235295, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306368', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1074, 'n_words': 398}