<commit_before>"""Github Action Build

This file is used to build and distribute the safety binary on Github actions.
Take a look at the corresponding main.yml as well.

"""
import os
import subprocess
import sys
from collections import OrderedDict


class environment:

    WIN = "win"
    LINUX = "linux"
    MACOS = "macos"

    def __init__(self):
        os_mapping = {
            "windows-latest": self.WIN,
            "ubuntu-latest": self.LINUX,
            "macos-latest": self.MACOS
        }
        self.os = os_mapping[os.getenv("BINARY_OS")]

    @property
    def python(self):
        for arch, python in self.PYTHON_BINARIES[self.os].items():
            yield arch, python

    PYTHON_BINARIES = {
        WIN: {
            64: "C:\\Python39-x64\\python.exe",
            32: "C:\\Python39\\python.exe",
        },

        # Order is important. If the 32 bit release gets built first,
        # you'll run into permission problems due to docker clobbering
        # up the current working directory.
        LINUX: OrderedDict([
            (64, "python3"),
            (32,
             f"docker run --platform linux/386 -t "
             f"-v {os.getcwd()}:/app 32-bit-linux "
             f"python3"),
        ]),

        MACOS: {
            64: "python3",
        }
    }

    def run(self, command):
        """Runs the given command via subprocess.check_output.

        Exits with -1 if the command wasn't successfull.
<commit_msg>Fixes on WIN binaries generation<commit_after>"""Github Action Build

This file is used to build and distribute the safety binary on Github actions.
Take a look at the corresponding main.yml as well.

"""
import os
import subprocess
import sys
from collections import OrderedDict


class environment:

    WIN = "win"
    LINUX = "linux"
    MACOS = "macos"

    def __init__(self):
        os_mapping = {
            "windows-latest": self.WIN,
            "ubuntu-latest": self.LINUX,
            "macos-latest": self.MACOS
        }
        self.os = os_mapping[os.getenv("BINARY_OS")]

    @property
    def python(self):
        for arch, python in self.PYTHON_BINARIES[self.os].items():
            yield arch, python

    WIN_BASE_PATH = "C:\\hostedtoolcache\\windows\\Python\\3.10.7"

    PYTHON_BINARIES = {
        WIN: {
            64: f"{WIN_BASE_PATH}\\x64\\python.exe",  # setup-python default
            32: f"{WIN_BASE_PATH}\\x86\\python.exe"
        },

        # Order is important. If the 32 bit release gets built first,
        # you'll run into permission problems due to docker clobbering
        # up the current working directory.
        LINUX: OrderedDict([
            (64, "python3"),
            (32,
             f"docker run --platform linux/386 -t "
             f"-v {os.getcwd()}:/app 32-bit-linux "
             f"python3"),
        ]),

        MACOS: {
            64: "python3",
        }
    }

    def run(self, command):
        """Runs the given command via subprocess.check_output.

        Exits with -1 if the command wasn't successfull.

{'fraction_non_alphanumeric': 0.1089238845144357, 'fraction_numerical': 0.01837270341207349, 'mean_word_length': 1.9289145052833814, 'pattern_counts': {'":': 6, '<': 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': '284853', 'n_tokens_mistral': 983, 'n_tokens_neox': 901, 'n_words': 270}