Skip to content

Commit

Permalink
Merge pull request #71 from FriedrichFroebel/warnings
Browse files Browse the repository at this point in the history
Fix some build warnings
  • Loading branch information
cdalitz authored Aug 23, 2023
2 parents c4fb218 + 88fdbcb commit fc0a29c
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 91 deletions.
2 changes: 1 addition & 1 deletion ACKNOWLEDGEMENTS
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Johanna Devaney
Georg Drees
Tim DiLauro
Robert Ferguson
Friedrich Fröbel
FriedrichFröbel
Andrew Hankinson
Manuel Jeltsch
Thomas Karsten
Expand Down
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Version 4.1.0, Feb 14, 2023

- Update install instructions to use pip

- ported from deprected distutils to setuptools
- ported from deprecated distutils to setuptools

- replaced old buffer protocol

Expand Down
79 changes: 25 additions & 54 deletions gamera/gendoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import shutil
import sys
import traceback
from pkg_resources import parse_version
from stat import ST_MTIME
from time import strftime, localtime

Expand All @@ -47,10 +46,6 @@
try:
from docutils.core import publish_file
import docutils.parsers.rst

if parse_version(docutils.__version__) < parse_version('0.4'):
print("docutils version (" + docutils.__version__ + ") too old")
raise ImportError()
except ImportError as e:
print("'docutils' 0.4 or later must be installed to generate the documentation.")
print("It can be downloaded at http://docutils.sf.net")
Expand All @@ -63,60 +58,36 @@
import pygments
import pygments.lexers
import pygments.formatters

source_highlighter = 'pygments'
if parse_version(pygments.__version__) < parse_version('0.6'):
print("pygments version (" + pygments.__version__ + ") too old")
raise ImportError()
except ImportError as e:
try:
import SilverCity

source_highlighter = 'silvercity'
except ImportError as e:
print("Either 'pygments' 0.6 or later or 'SilverCity' 0.9 or later")
print("must be installed to colorize the sourcecode snippets in the")
print("documentation.")
sys.exit(1)
print("'pygments' 0.6 or later must be installed to colorize the sourcecode")
print("snippets in the documentation.")
print("It can be downloaded at https://pygments.org/")
sys.exit(1)

# Source code highlighting support
if source_highlighter == 'pygments':
html_formatter = pygments.formatters.get_formatter_by_name("html")
html_formatter = pygments.formatters.get_formatter_by_name("html")


def code_block(
name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine
):
language = arguments[0].lower()
try:
lexer = pygments.lexers.get_lexer_by_name(language)
except ValueError:
# no lexer found - use the text one instead of an exception
error = state_machine.reporter.error(
"No pygments lexer found for language '%s'." % language,
docutils.nodes.literal_block(block_text, block_text), line=lineno)
return [error]
parsed = pygments.highlight(
'\n'.join(content),
lexer,
html_formatter)
return [docutils.nodes.raw('', parsed, format='html')]


def code_block(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
language = arguments[0].lower()
try:
lexer = pygments.lexers.get_lexer_by_name(language)
except ValueError:
# no lexer found - use the text one instead of an exception
error = state_machine.reporter.error(
"No pygments lexer found for language '%s'." % language,
docutils.nodes.literal_block(block_text, block_text), line=lineno)
return [error]
parsed = pygments.highlight(
'\n'.join(content),
lexer,
html_formatter)
return [docutils.nodes.raw('', parsed, format='html')]
elif source_highlighter == 'silvercity':
def code_block(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
language = arguments[0]
try:
module = getattr(SilverCity, language)
generator = getattr(module, language + "HTMLGenerator")
except AttributeError:
error = state_machine.reporter.error(
"No SilverCity lexer found for language '%s'." % language,
docutils.nodes.literal_block(block_text, block_text), line=lineno)
return [error]
io = ioutil.StringIO()
generator().generate_html(io, '\n'.join(content))
html = '<div class="code-block">\n%s\n</div>\n' % io.getvalue()
raw = docutils.nodes.raw('', html, format='html')
return [raw]
code_block.arguments = (1, 0, 0)
code_block.options = {'language': docutils.parsers.rst.directives.unchanged}
code_block.content = 1
Expand Down
4 changes: 2 additions & 2 deletions gamera/include/gamera/plugins/tiff_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ImageInfo* tiff_info(const char* filename) {
*/
try {
unsigned short tmp;
uint32 size;
uint32_t size;
TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGEWIDTH, &size);
info->ncols((size_t)size);
TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGELENGTH, &size);
Expand Down Expand Up @@ -256,7 +256,7 @@ namespace {
throw std::runtime_error("Error allocating scanline");
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
std::bitset<32> bits;
uint32* data = (uint32 *)buf;
uint32_t* data = (uint32_t *)buf;
bool little_endian = byte_order_little_endian();
typename T::const_vec_iterator it = matrix.vec_begin();
for (size_t i = 0; i < matrix.nrows(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion gamera/plugins/binarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __call__(self, x_lookahead=8, y_lookahead=1, bias_mode=0,


class shading_subtraction(PluginFunction):
"""
r"""
Thresholds an image after subtracting a -possibly shaded- background.
First the background image is extracted with a maximum filter with a
Expand Down
2 changes: 1 addition & 1 deletion gamera/plugins/id_name_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _build_id_regex_parts(s):
part0 = part0.replace('?', '[^.]')
l.append(part0)
regex_parts.append('(?:%s)' % '|'.join(['(?:%s)' % x for x in l]))
regex = '\.'.join(regex_parts)
regex = r'\.'.join(regex_parts)
return regex

def _build_id_regex_parens(s):
Expand Down
2 changes: 1 addition & 1 deletion gamera/plugins/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __call__(self, angles):


class rotation_angle_projections(PluginFunction):
"""
r"""
Estimates the rotation angle of a document with the aid of skewed
projections, as described in section 3.1 of C. Dalitz, G.K. Michalakis,
C. Pranzas: 'Optical Recognition of Psaltic Byzantine Chant Notation.'
Expand Down
16 changes: 8 additions & 8 deletions gamera/pyplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@

import sys, string, re, gamera.util as util, io, codecs

re_directive = re.compile("\[\[(.*?)\]\]")
re_for_loop = re.compile("for (.*) in (.*)")
re_if = re.compile("if (.*)")
re_elif = re.compile("elif (.*)")
re_def = re.compile("def (.*?)\((.*)\)")
re_call = re.compile("call (.*?)\((.*)\)")
re_exec = re.compile("exec (.*)")
re_comment = re.compile("#(.*)#")
re_directive = re.compile(r"\[\[(.*?)\]\]")
re_for_loop = re.compile(r"for (.*) in (.*)")
re_if = re.compile(r"if (.*)")
re_elif = re.compile(r"elif (.*)")
re_def = re.compile(r"def (.*?)\((.*)\)")
re_call = re.compile(r"call (.*?)\((.*)\)")
re_exec = re.compile(r"exec (.*)")
re_comment = re.compile(r"#(.*)#")

re_clean_whitespace = re.compile(r"\]\]\s+?")

Expand Down
4 changes: 2 additions & 2 deletions gamera/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def string2identifier(str):
"""Defines how illegal variable names are converted to legal ones."""
# TODO: Not very robust.
if len(str):
name = re.sub('\-|/|\.|\ ', '_', str, 0)
name = re.sub(r'\-|/|\.|\ ', '_', str, 0)
if name[0] in string.digits:
name = "_" + name
return name
Expand Down Expand Up @@ -339,7 +339,7 @@ def ProgressFactory(message, length=1, numsteps=0):
# A regular expression used to determine the amount of space to
# remove. It looks for the first sequence of spaces immediately
# following the first newline, or at the beginning of the string.
_find_dedent_regex = re.compile("(?:(?:\n\r?)|^)( *)\S")
_find_dedent_regex = re.compile(r"(?:(?:\n\r?)|^)( *)\S")
# A cache to hold the regexs that actually remove the indent.
_dedent_regex = {}
def dedent(s):
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = [
'setuptools', 'wheel', # Needed only to make pip happy.
]
22 changes: 4 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import glob
import os
import platform
import sys
from concurrent.futures import ThreadPoolExecutor as Pool
from pathlib import Path

from setuptools import setup, Extension, find_namespace_packages
from distutils.ccompiler import CCompiler
from distutils.command.build_ext import build_ext
from pathlib import Path
import sys

from gamera import gamera_setup

if sys.hexversion < 0x03050000:
Expand Down Expand Up @@ -133,22 +135,6 @@
**gamera_setup.extras)]
extensions.extend(plugin_extensions)

# https://stackoverflow.com/a/13176803
# multithreading building, can also be used with setuptools
try:
from concurrent.futures import ThreadPoolExecutor as Pool
except ImportError:
from multiprocessing.pool import ThreadPool as LegacyPool

# To ensure the with statement works. Required for some older 2.7.x releases
class Pool(LegacyPool):
def __enter__(self):
return self

def __exit__(self, *args):
self.close()
self.join()


def _build_extensions(self):
"""Function to monkey-patch
Expand Down
4 changes: 2 additions & 2 deletions src/knncore/knncoremodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ static PyObject* knn_set_selections(PyObject* self, PyObject* args) {
}
selections = (int*)buffer.buf;

if (buffer.len != o->num_features * sizeof(int)) {
if ((size_t)buffer.len != o->num_features * sizeof(int)) {
PyErr_SetString(PyExc_RuntimeError, "knn: selection vector is not the correct size.");
return nullptr;
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ static PyObject* knn_set_weights(PyObject* self, PyObject* args) {
return nullptr;
}
weights = (double*)buffer.buf;
if (buffer.len != o->num_features * sizeof(double)) {
if ((size_t)buffer.len != o->num_features * sizeof(double)) {
PyErr_SetString(PyExc_ValueError, "knn: weight vector is not the correct size.");
return nullptr;
}
Expand Down

0 comments on commit fc0a29c

Please sign in to comment.