<commit_before>find_program(PYTHON python)

get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set(INCLUDE_FLAGS)
foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
	list(APPEND INCLUDE_FLAGS "-I${DIR}")
endforeach()

include(FindPythonLibs)
list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
include_directories(AFTER ${PYTHON_INCLUDE_DIRS})

file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py
                   COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR}
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                   DEPENDS ${BINARY_NAME}
                   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py
                   DEPENDS ${PYTHON_HEADERS}
                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)

add_custom_command(OUTPUT lib.c
                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
                  DEPENDS ${PYTHON_HEADERS}
                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)

set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib.c PROPERTIES GENERATED ON)

file(GLOB PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
add_library(${BINARY_NAME}-pylib STATIC ${CMAKE_CURRENT_BINARY_DIR}/lib.c ${PYTHON_SRC})
set_target_properties(${BINARY_NAME}-pylib PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR};${INCLUDE_DIRECTORIES}")
set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
set(PYTHON_LIBRARY ${BINARY_NAME}-pylib PARENT_SCOPE)

add_custom_target(${BINARY_NAME}-py ALL
                  COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build
                  DEPENDS ${BINARY_NAME}-pylib ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py)

file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/test_*.py)
foreach(TEST IN LISTS TESTS)
	if(APPLE)
		set(PATH DYLD_LIBRARY_PATH)
	elseif(WIN32)
		set(PATH PATH)
	else()
		set(PATH LD_LIBRARY_PATH)
	endif()
	string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/test_" "" TEST_NAME "${TEST}")
	string(REPLACE ".py" "" TEST_NAME "${TEST_NAME}")
	add_test(python-${TEST_NAME} ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py pytest --addopts ${TEST})
	set_tests_properties(python-${TEST_NAME} PROPERTIES ${PATH} "${BINDIR}")
endforeach()<commit_msg>Python: Set environment variable properly<commit_after>find_program(PYTHON python)

get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set(INCLUDE_FLAGS)
foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
	list(APPEND INCLUDE_FLAGS "-I${DIR}")
endforeach()

include(FindPythonLibs)
list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
include_directories(AFTER ${PYTHON_INCLUDE_DIRS})

file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py
                   COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR}
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                   DEPENDS ${BINARY_NAME}
                   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py
                   DEPENDS ${PYTHON_HEADERS}
                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)

add_custom_command(OUTPUT lib.c
                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
                  DEPENDS ${PYTHON_HEADERS}
                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)

set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib.c PROPERTIES GENERATED ON)

file(GLOB PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
add_library(${BINARY_NAME}-pylib STATIC ${CMAKE_CURRENT_BINARY_DIR}/lib.c ${PYTHON_SRC})
set_target_properties(${BINARY_NAME}-pylib PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR};${INCLUDE_DIRECTORIES}")
set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
set(PYTHON_LIBRARY ${BINARY_NAME}-pylib PARENT_SCOPE)

add_custom_target(${BINARY_NAME}-py ALL
                  COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build
                  DEPENDS ${BINARY_NAME}-pylib ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py)

file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/test_*.py)
foreach(TEST IN LISTS TESTS)
	if(APPLE)
		set(PATH DYLD_LIBRARY_PATH)
	elseif(WIN32)
		set(PATH PATH)
	else()
		set(PATH LD_LIBRARY_PATH)
	endif()
	string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/test_" "" TEST_NAME "${TEST}")
	string(REPLACE ".py" "" TEST_NAME "${TEST_NAME}")
	add_test(python-${TEST_NAME} ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py pytest --addopts ${TEST})
	set_tests_properties(python-${TEST_NAME} PROPERTIES ENVIRONMENT "${PATH}=${CMAKE_CURRENT_BINARY_DIR}/..")
endforeach()
{'fraction_non_alphanumeric': 0.12328251458686242, 'fraction_numerical': 0.0007528703180877094, 'mean_word_length': 5.356459330143541, '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': '7538601', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1889, 'n_words': 251}