<commit_before>from __future__ import (division, print_function, absolute_import,
                        unicode_literals)

import os
import glob

from conda import config

from obvci.conda_tools.build import upload
from obvci.conda_tools.build_directory import Builder

from prepare_packages import RECIPE_FOLDER, BINSTAR_CHANNEL, BDIST_CONDA_FOLDER


def main():
    # Get our binstar client from the Builder to get BINSTAR_TOKEN obfuscation
    # in windows builds.
    builder = Builder(RECIPE_FOLDER, BINSTAR_CHANNEL, 'main')
    conda_builds_dir = os.path.join(config.default_prefix,
                                    'conda-bld', config.subdir)
    built_packages = glob.glob(os.path.join(conda_builds_dir, '*.tar.bz2'))
    for package in built_packages:
        _, package_file = os.path.split(package)
        name = package_file.split('-')[0]

        if name in bdists:
            # Need to upload this one...
            # First grab the metadata from the package, which requires
            # opening the file.

            # Not going to lie: after fighting with conda for 90 minutes to
            # construct a proper MetaData object from a built package, I give
            # up.

            # Instead, create an object with one method, dist, which returns
            # the build string and be done with it.
            class MetaData(object):
                def __init__(self, dist_info):
                    self._dist_info = dist_info

                def dist(self):
                    return self._dist_info

            meta = MetaData(package_file.split('.tar.bz2')[0])

            # Upload it
            upload(builder.binstar_cli, meta, BINSTAR_CHANNEL)


if __name__ == '__main__':
    main()
<commit_msg>Properly handle exceptions if bdist directory doesn't exist<commit_after>from __future__ import (division, print_function, absolute_import,
                        unicode_literals)

import os
import glob

from conda import config

from obvci.conda_tools.build import upload
from obvci.conda_tools.build_directory import Builder

from prepare_packages import RECIPE_FOLDER, BINSTAR_CHANNEL, BDIST_CONDA_FOLDER


def main():
    # Get our binstar client from the Builder to get BINSTAR_TOKEN obfuscation
    # in windows builds.
    builder = Builder(RECIPE_FOLDER, BINSTAR_CHANNEL, 'main')
    try:
        bdists = os.listdir(BDIST_CONDA_FOLDER)
    except (OSError, WindowsError):
        # Nothing to upload.
        return

    conda_builds_dir = os.path.join(config.default_prefix,
                                    'conda-bld', config.subdir)
    built_packages = glob.glob(os.path.join(conda_builds_dir, '*.tar.bz2'))
    for package in built_packages:
        _, package_file = os.path.split(package)
        name = package_file.split('-')[0]

        if name in bdists:
            # Need to upload this one...
            # First grab the metadata from the package, which requires
            # opening the file.

            # Not going to lie: after fighting with conda for 90 minutes to
            # construct a proper MetaData object from a built package, I give
            # up.

            # Instead, create an object with one method, dist, which returns
            # the build string and be done with it.
            class MetaData(object):
                def __init__(self, dist_info):
                    self._dist_info = dist_info

                def dist(self):
                    return self._dist_info

            meta = MetaData(package_file.split('.tar.bz2')[0])

            # Upload it
            upload(builder.binstar_cli, meta, BINSTAR_CHANNEL)


if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.07302452316076294, 'fraction_numerical': 0.0032697547683923707, 'mean_word_length': 2.2230026338893767, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3291140', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1021, 'n_words': 315}