<commit_before>from distutils.command.sdist import sdist
import logging
import os
import shutil
import subprocess
import sys

from setuptools import setup
from setuptools.extension import Extension

# Use Cython if available.
try:
    from Cython.Build import cythonize
except ImportError:
    cythonize = None


logging.basicConfig()
log = logging.getLogger()

# python -W all setup.py ...
if 'all' in sys.warnoptions:
    log.level = logging.DEBUG

def check_output(cmd):
    # since subprocess.check_output doesn't exist in 2.6
    # we wrap it here.
    try:
        out = subprocess.check_output(cmd)
        return out.decode('utf')
    except AttributeError:
        # For some reasone check_output doesn't exist
        # So fall back on Popen
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        out, err = p.communicate()
        return out

def copy_data_tree(datadir, destdir):
    try:
        shutil.rmtree(destdir)
    except OSError:
        pass
    shutil.copytree(datadir, destdir)

# Parse the version from the fiona module.
with open('fiona/__init__.py', 'r') as f:
    for line in f:
        if line.find("__version__") >= 0:
            version = line.split("=")[1].strip()
            version = version.strip('"')
            version = version.strip("'")
            break

# Fiona's auxiliary files are UTF-8 encoded and we'll specify this when
# reading with Python 3+
open_kwds = {}
if sys.version_info > (3,):
    open_kwds['encoding'] = 'utf-8'

with open('VERSION.txt', 'w', **open_kwds) as f:
    f.write(version)

with open('README.rst', **open_kwds) as f:
    readme = f.read()

with open('CREDITS.txt', **open_kwds) as f:
    credits = f.read()

with open('CHANGES.txt', **open_kwds) as f:
    changes = f.read()

# Set a flag for builds where the source directory is a repo checkout.
source_is_repo = os.path.exists("MANIFEST.in")


def copy_gdalapi_pyx(gdalversion):
    if gdalversion[0] == u'1':
        log.info("Building Fiona for gdal 1.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext1.pyx', 'fiona/ogrext.pyx')
    else:
        log.info("Building Fiona for gdal 2.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext2.pyx', 'fiona/ogrext.pyx')


def copy_gdalapi_c(gdalversion):
    if gdalversion[0] == u'1':
        log.info("Building Fiona for gdal 1.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext1.c', 'fiona/ogrext.c')
        print("Copied 'fiona/ogrext1.c' to'fiona/ogrext.c'")
    else:
        log.info("Building Fiona for gdal 2.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext2.c', 'fiona/ogrext.c')
        print("Copied 'fiona/ogrext2.c' to 'fiona/ogrext.c'")


# Extend distutil's sdist command to generate C extension sources from
# both `ogrext`.pyx` and `ogrext2.pyx` for GDAL 1.x and 2.x.
class sdist_multi_gdal(sdist):
    def run(self):
        shutil.copy('fiona/ogrext1.pyx', 'fiona/ogrext.pyx')
        _ = check_output(['cython', '-v', '-f', 'fiona/ogrext.pyx', '-o', 'fiona/ogrext1.c'])
        print(_)
        shutil.copy('fiona/ogrext2.pyx', 'fiona/ogrext.pyx')
        _ = check_output(['cython', '-v', '-f', 'fiona/ogrext.pyx', '-o', 'fiona/ogrext2.c'])
        print(_)
        sdist.run(self)


# By default we'll try to get options via gdal-config. On systems without,
# options will need to be set in setup.cfg or on the setup command line.
include_dirs = []
library_dirs = []
libraries = []
extra_link_args = []
gdal_output = [None] * 4

if 'clean' not in sys.argv:
    try:
        gdal_config = os.environ.get('GDAL_CONFIG', 'gdal-config')
        for i, flag in enumerate(("--cflags", "--libs", "--datadir", "--version")):
            gdal_output[i] = check_output([gdal_config, flag]).strip()

        for item in gdal_output[0].split():
            if item.startswith("-I"):
                include_dirs.extend(item[2:].split(":"))
        for item in gdal_output[1].split():
            if item.startswith("-L"):
                library_dirs.extend(item[2:].split(":"))
            elif item.startswith("-l"):
                libraries.append(item[2:])
            else:
                # e.g. -framework GDAL
                extra_link_args.append(item)
        gdalversion = gdal_output[3]

    except Exception as e:
        if os.name == "nt":
            log.info("Building on Windows requires extra options to setup.py "
                     "to locate needed GDAL files.\nMore information is "
                     "available in the README.")
        else:
            log.warning("Failed to get options via gdal-config: %s", str(e))

    if '--gdalversion' in sys.argv:
        index = sys.argv.index('--gdalversion')
        sys.argv.pop(index)
        gdalversion = sys.argv.pop(index)<commit_msg>Parse --gdalversion earlier in setup<commit_after>from distutils.command.sdist import sdist
import logging
import os
import shutil
import subprocess
import sys

from setuptools import setup
from setuptools.extension import Extension

# Use Cython if available.
try:
    from Cython.Build import cythonize
except ImportError:
    cythonize = None


logging.basicConfig()
log = logging.getLogger()

# python -W all setup.py ...
if 'all' in sys.warnoptions:
    log.level = logging.DEBUG


def check_output(cmd):
    # since subprocess.check_output doesn't exist in 2.6
    # we wrap it here.
    try:
        out = subprocess.check_output(cmd)
        return out.decode('utf')
    except AttributeError:
        # For some reasone check_output doesn't exist
        # So fall back on Popen
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        out, err = p.communicate()
        return out


def copy_data_tree(datadir, destdir):
    try:
        shutil.rmtree(destdir)
    except OSError:
        pass
    shutil.copytree(datadir, destdir)

# Parse the version from the fiona module.
with open('fiona/__init__.py', 'r') as f:
    for line in f:
        if line.find("__version__") >= 0:
            version = line.split("=")[1].strip()
            version = version.strip('"')
            version = version.strip("'")
            break

# Fiona's auxiliary files are UTF-8 encoded and we'll specify this when
# reading with Python 3+
open_kwds = {}
if sys.version_info > (3,):
    open_kwds['encoding'] = 'utf-8'

with open('VERSION.txt', 'w', **open_kwds) as f:
    f.write(version)

with open('README.rst', **open_kwds) as f:
    readme = f.read()

with open('CREDITS.txt', **open_kwds) as f:
    credits = f.read()

with open('CHANGES.txt', **open_kwds) as f:
    changes = f.read()

# Set a flag for builds where the source directory is a repo checkout.
source_is_repo = os.path.exists("MANIFEST.in")


def copy_gdalapi_pyx(gdalversion):
    if gdalversion[0] == u'1':
        log.info("Building Fiona for gdal 1.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext1.pyx', 'fiona/ogrext.pyx')
    else:
        log.info("Building Fiona for gdal 2.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext2.pyx', 'fiona/ogrext.pyx')


def copy_gdalapi_c(gdalversion):
    if gdalversion[0] == u'1':
        log.info("Building Fiona for gdal 1.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext1.c', 'fiona/ogrext.c')
        print("Copied 'fiona/ogrext1.c' to'fiona/ogrext.c'")
    else:
        log.info("Building Fiona for gdal 2.x: {0}".format(gdalversion))
        shutil.copy('fiona/ogrext2.c', 'fiona/ogrext.c')
        print("Copied 'fiona/ogrext2.c' to 'fiona/ogrext.c'")


if '--gdalversion' in sys.argv and 'clean' not in sys.argv:
    index = sys.argv.index('--gdalversion')
    sys.argv.pop(index)
    gdalversion = sys.argv.pop(index)


# Extend distutil's sdist command to generate C extension sources from
# both `ogrext`.pyx` and `ogrext2.pyx` for GDAL 1.x and 2.x.
class sdist_multi_gdal(sdist):
    def run(self):
        shutil.copy('fiona/ogrext1.pyx', 'fiona/ogrext.pyx')
        _ = check_output(['cython', '-v', '-f', 'fiona/ogrext.pyx',
                          '-o', 'fiona/ogrext1.c'])
        print(_)
        shutil.copy('fiona/ogrext2.pyx', 'fiona/ogrext.pyx')
        _ = check_output(['cython', '-v', '-f', 'fiona/ogrext.pyx',
                          '-o', 'fiona/ogrext2.c'])
        print(_)
        sdist.run(self)


# By default we'll try to get options via gdal-config. On systems without,
# options will need to be set in setup.cfg or on the setup command line.
include_dirs = []
library_dirs = []
libraries = []
extra_link_args = []
gdal_output = [None] * 4

if 'clean' not in sys.argv:
    try:
        gdal_config = os.environ.get('GDAL_CONFIG', 'gdal-config')
        for i, flag in enumerate(
                ["--cflags", "--libs", "--datadir", "--version"]):
            gdal_output[i] = check_output([gdal_config, flag]).strip()

        for item in gdal_output[0].split():
            if item.startswith("-I"):
                include_dirs.extend(item[2:].split(":"))
        for item in gdal_output[1].split():
            if item.startswith("-L"):
                library_dirs.extend(item[2:].split(":"))
            elif item.startswith("-l"):
                libraries.append(item[2:])
            else:
                # e.g. -framework GDAL
                extra_link_args.append(item)
        gdalversion = gdal_output[3]

    except Exception as e:
        if os.name == "nt":
            log.info("Building on Windows requires extra options to setup.py "
                     "to locate needed GDAL files.\nMore information is "
                     "available in the README.")
        else:
            log.warning("Failed to get options via gdal-config: %s", str(e))
{'fraction_non_alphanumeric': 0.13974025974025975, 'fraction_numerical': 0.008311688311688312, 'mean_word_length': 2.6065942300487075, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, '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': '1575676', 'n_tokens_mistral': 3360, 'n_tokens_neox': 3313, 'n_words': 809}