<commit_before>// Package mapnik renders beautiful maps with Mapnik.
package mapnik

// #include <stdlib.h>
// #include "mapnik_c_api.h"
import "C"

import (
	"errors"
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"unsafe"
)

type LogLevel int

var (
	None  = LogLevel(C.MAPNIK_NONE)
	Debug = LogLevel(C.MAPNIK_DEBUG)
	Warn  = LogLevel(C.MAPNIK_WARN)
	Error = LogLevel(C.MAPNIK_ERROR)
)

var (
	// You can overwrite defaults at compile time, eg:
	// go build -ldflags "-X github.com/omniscale/go-mapnik/v2.fontPath $(mapnik-config -fonts)"
	fontPath   = "/usr/local/lib/mapnik/fonts"
	pluginPath = "/usr/local/lib/mapnik/input"
)

func init() {
	// Register default datasources path and fonts path like the Python bindings do.
	if err := RegisterDatasources(pluginPath); err != nil {
		fmt.Fprintf(os.Stderr, "MAPNIK: %s\n", err)
	}
	if err := RegisterFonts(fontPath); err != nil {
		fmt.Fprintf(os.Stderr, "MAPNIK: %s\n", err)
	}
}

// RegisterDatasources registers all input plugins found in the given path.
func RegisterDatasources(path string) error {
	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return err
	}

	for _, file := range fileInfos {
		cs := C.CString(filepath.Join(path, file.Name()))
		defer C.free(unsafe.Pointer(cs))
		// Register datasources one-by-one to avoid recursive_mutex assertion
		// errors in register_datasources, triggered at least on MacOS 10.13
		// with Mapnik 3.0.22
		if C.mapnik_register_datasource(cs) == 0 {
			e := C.GoString(C.mapnik_register_last_error())
			if e != "" {
				return errors.New("registering datasources: " + e)
			}
			return errors.New("error while registering datasources")
		}
	}
	return nil
}

// RegisterDatasources registers all fonts found in the given path.
func RegisterFonts(path string) error {
	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return err
	}

	for _, file := range fileInfos {
		fullPath := filepath.Join(path, file.Name())
		if !isFontFile(fullPath) {
			continue
		}
		cs := C.CString(fullPath)
		defer C.free(unsafe.Pointer(cs))
		// Register fonts one-by-one. See comment in RegisterDatasources.
		if C.mapnik_register_font(cs) == 0 {
			e := C.GoString(C.mapnik_register_last_error())
			fmt.Fprintln(os.Stderr)
			fmt.Fprintln(os.Stderr, path, file, e)
			if e != "" {
				return errors.New("registering fonts: " + e)
			}
			return errors.New("error while registering fonts")<commit_msg>remove debug print calls<commit_after>// Package mapnik renders beautiful maps with Mapnik.
package mapnik

// #include <stdlib.h>
// #include "mapnik_c_api.h"
import "C"

import (
	"errors"
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"unsafe"
)

type LogLevel int

var (
	None  = LogLevel(C.MAPNIK_NONE)
	Debug = LogLevel(C.MAPNIK_DEBUG)
	Warn  = LogLevel(C.MAPNIK_WARN)
	Error = LogLevel(C.MAPNIK_ERROR)
)

var (
	// You can overwrite defaults at compile time, eg:
	// go build -ldflags "-X github.com/omniscale/go-mapnik/v2.fontPath $(mapnik-config -fonts)"
	fontPath   = "/usr/local/lib/mapnik/fonts"
	pluginPath = "/usr/local/lib/mapnik/input"
)

func init() {
	// Register default datasources path and fonts path like the Python bindings do.
	if err := RegisterDatasources(pluginPath); err != nil {
		fmt.Fprintf(os.Stderr, "MAPNIK: %s\n", err)
	}
	if err := RegisterFonts(fontPath); err != nil {
		fmt.Fprintf(os.Stderr, "MAPNIK: %s\n", err)
	}
}

// RegisterDatasources registers all input plugins found in the given path.
func RegisterDatasources(path string) error {
	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return err
	}

	for _, file := range fileInfos {
		cs := C.CString(filepath.Join(path, file.Name()))
		defer C.free(unsafe.Pointer(cs))
		// Register datasources one-by-one to avoid recursive_mutex assertion
		// errors in register_datasources, triggered at least on MacOS 10.13
		// with Mapnik 3.0.22
		if C.mapnik_register_datasource(cs) == 0 {
			e := C.GoString(C.mapnik_register_last_error())
			if e != "" {
				return errors.New("registering datasources: " + e)
			}
			return errors.New("error while registering datasources")
		}
	}
	return nil
}

// RegisterDatasources registers all fonts found in the given path.
func RegisterFonts(path string) error {
	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return err
	}

	for _, file := range fileInfos {
		fullPath := filepath.Join(path, file.Name())
		if !isFontFile(fullPath) {
			continue
		}
		cs := C.CString(fullPath)
		defer C.free(unsafe.Pointer(cs))
		// Register fonts one-by-one. See comment in RegisterDatasources.
		if C.mapnik_register_font(cs) == 0 {
			e := C.GoString(C.mapnik_register_last_error())
			if e != "" {
				return errors.New("registering fonts: " + e)
			}
			return errors.New("error while registering fonts")
{'fraction_non_alphanumeric': 0.1335121749896822, 'fraction_numerical': 0.004539826661163846, 'mean_word_length': 3.7195715676728334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5657091', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1749, 'n_words': 441}