-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate Python code to a dedicated package #309
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96f31a2
migrate Python code to a dedicated package
stefan6419846 ab60ad8
document `extract_font_properties` parameter; update supported Python
stefan6419846 0ac2bda
fix cleanup when used without log file
stefan6419846 01c9fb9
remove IDE entry from .gitignore file
stefan6419846 d65fd3d
improve trove classifiers
stefan6419846 c4d7b86
remove clearly not required entries from .gitignore file
stefan6419846 e91a31d
update supported Python versions
stefan6419846 345379f
update supported Python versions
stefan6419846 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# tesstrain.py | ||
|
||
Utilities for working with Tesseract >= 4 using artificial training data. | ||
|
||
## Install | ||
|
||
This package requires the Tesseract training tools to be available on your system. | ||
|
||
To install the PIP package, either use `pip install tesstrain` (for existing packages) or `pip install .` (from source checkout). | ||
A supported Python version (at least 3.7) is required for running. | ||
|
||
## Running | ||
|
||
* Use the terminal interface to directly interact with the tools: `python -m tesstrain --help`. | ||
* Call it from your own code using the high-level interface `tesstrain.run()`. | ||
|
||
## License | ||
|
||
Software is provided under the terms of the `Apache 2.0` license. | ||
|
||
Sample training data provided by [Deutsches Textarchiv](https://deutschestextarchiv.de) is [in the public domain](http://creativecommons.org/publicdomain/mark/1.0/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
version = attr: tesstrain.__version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pathlib import Path | ||
|
||
import setuptools | ||
|
||
|
||
ROOT_DIRECTORY = Path(__file__).parent.resolve() | ||
|
||
setuptools.setup( | ||
name='tesstrain', | ||
description='Training utils for Tesseract', | ||
long_description=(ROOT_DIRECTORY / 'README.md').read_text(encoding='utf-8'), | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/tesseract-ocr/tesstrain', | ||
packages=setuptools.find_packages(), | ||
license='Apache Software License 2.0', | ||
author='Tesseract contributors', | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
'Topic :: Scientific/Engineering :: Image Recognition', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3 :: Only', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Programming Language :: Python :: 3.11', | ||
], | ||
keywords='Tesseract,tesseract-ocr,OCR,optical character recognition', | ||
|
||
python_requires='>=3.7', | ||
install_requires=[ | ||
'tqdm', | ||
], | ||
|
||
entry_points={ | ||
'console_scripts': [ | ||
], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# (C) Copyright 2014, Google Inc. | ||
# (C) Copyright 2018, James R Barlow | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from tesstrain.wrapper import run | ||
|
||
__version__ = '0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# (C) Copyright 2014, Google Inc. | ||
# (C) Copyright 2018, James R Barlow | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# This script provides an easy way to execute various phases of training | ||
# Tesseract. For a detailed description of the phases, see | ||
# https://tesseract-ocr.github.io/tessdoc/Training-Tesseract.html. | ||
|
||
import logging | ||
|
||
from tesstrain.arguments import ( | ||
get_argument_parser, | ||
TrainingArguments, | ||
verify_parameters_and_handle_defaults | ||
) | ||
from tesstrain.generate import cleanup | ||
from tesstrain.wrapper import run_from_context | ||
|
||
|
||
log = logging.getLogger() | ||
|
||
|
||
def setup_logging_console(): | ||
log.setLevel(logging.DEBUG) | ||
console = logging.StreamHandler() | ||
console.setLevel(logging.INFO) | ||
console_formatter = logging.Formatter( | ||
"[%(asctime)s] %(levelname)s - %(message)s", datefmt="%H:%M:%S" | ||
) | ||
console.setFormatter(console_formatter) | ||
log.addHandler(console) | ||
|
||
|
||
def setup_logging_logfile(logfile): | ||
logfile = logging.FileHandler(logfile, encoding='utf-8') | ||
logfile.setLevel(logging.DEBUG) | ||
logfile_formatter = logging.Formatter( | ||
"[%(asctime)s] - %(levelname)s - %(name)s - %(message)s" | ||
) | ||
logfile.setFormatter(logfile_formatter) | ||
log.addHandler(logfile) | ||
return logfile | ||
|
||
|
||
def parse_flags(argv=None): | ||
ctx = TrainingArguments() | ||
log.debug(ctx) | ||
parser = get_argument_parser() | ||
parser.parse_args(args=argv, namespace=ctx) | ||
return verify_parameters_and_handle_defaults(ctx) | ||
|
||
|
||
def main(): | ||
setup_logging_console() | ||
ctx = parse_flags() | ||
logfile = setup_logging_logfile(ctx.log_file) | ||
|
||
run_from_context(ctx) | ||
|
||
log.removeHandler(logfile) | ||
logfile.close() | ||
cleanup(ctx) | ||
log.info("All done!") | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file looks like a copy from somewhere else. Which parts are really required? Why can those parts not be included in the root
.gitignore
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the standard GitHub Python .gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the default Python .gitignore template which usually is recommended for Python projects.
Only keeping the relevant entries might be an option, mainly concerning specific libraries which are currently unused. Nevertheless, I usually prefer to keep the default .gitignore file as it usually is some type of common sense.
I did not add this to the root .gitignore file to avoid unintended side effects for now, as the whole repository consists of two more or less independent parts, while not being clearly separated for now (see #307).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stweil I have reduced the
.gitignore
to the entries which actually make sense in this use case (at least from my point of view).Do you still want me to migrate the corresponding entries to the root
.gitignore
file?