<commit_before>#!/usr/bin/env python3
"""Builder for the C-extension of python-camellia.
"""

from distutils.ccompiler import new_compiler

from cffi import FFI
from setuptools import Distribution

import os

HERE = os.path.dirname(__file__)

SOURCE_FILE = "camellia.c"
HEADER_FILE = "camellia.h"

ABSOLUTE_SOURCE_FILE = os.path.join(HERE, SOURCE_FILE)
ABSOLUTE_HEADER_FILE = os.path.join(HERE, HEADER_FILE)

with open(ABSOLUTE_HEADER_FILE) as f:
    header = f.read()

with open(ABSOLUTE_SOURCE_FILE) as f:
    source = f.read()


def extra_link_args():
    dist = Distribution()
    dist.parse_config_files()
    dist.parse_command_line()
    build = dist.get_command_obj('build')
    build.ensure_finalized()
    if new_compiler(compiler=build.compiler).compiler_type == 'msvc':
        return ["/NXCOMPAT", "/DYNAMICBASE"]
    else:
        return []


ffi = FFI()
ffi.cdef(header)
ffi.set_source("camellia._camellia", source,
               include_dirs=[HERE], extra_link_args=extra_link_args())
<commit_msg>Catch errors if command line cannot be parsed (setup.py --help)<commit_after>#!/usr/bin/env python3
"""Builder for the C-extension of python-camellia.
"""

from distutils.ccompiler import new_compiler
from distutils.errors import DistutilsArgError

from cffi import FFI
from setuptools import Distribution

import os


HERE = os.path.dirname(__file__)

SOURCE_FILE = "camellia.c"
HEADER_FILE = "camellia.h"

ABSOLUTE_SOURCE_FILE = os.path.join(HERE, SOURCE_FILE)
ABSOLUTE_HEADER_FILE = os.path.join(HERE, HEADER_FILE)

with open(ABSOLUTE_HEADER_FILE) as f:
    header = f.read()

with open(ABSOLUTE_SOURCE_FILE) as f:
    source = f.read()


def extra_link_args():
    dist = Distribution()
    dist.parse_config_files()
    try:
        dist.parse_command_line()
    except (TypeError, DistutilsArgError):  # Happens with setup.py --help
        pass

    build = dist.get_command_obj('build')
    build.ensure_finalized()
    if new_compiler(compiler=build.compiler).compiler_type == 'msvc':
        return ["/NXCOMPAT", "/DYNAMICBASE"]
    else:
        return []


ffi = FFI()
ffi.cdef(header)
ffi.set_source("camellia._camellia", source,
               include_dirs=[HERE], extra_link_args=extra_link_args())

{'fraction_non_alphanumeric': 0.11087144089732529, 'fraction_numerical': 0.0008628127696289905, 'mean_word_length': 3.4255725190839694, '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': '2633247', 'n_tokens_mistral': 842, 'n_tokens_neox': 792, 'n_words': 163}