ultralytics 8.0.215 Windows UTF-8 fix 2 (#6463)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-11-20 15:56:55 +01:00 committed by GitHub
parent d43fcecc8a
commit 618923ab11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 10 deletions

View File

@ -24,9 +24,9 @@ Note:
- This script is built to be run in an environment where Python and MkDocs are installed and properly configured. - This script is built to be run in an environment where Python and MkDocs are installed and properly configured.
""" """
import os
import re import re
import shutil import shutil
import subprocess
from pathlib import Path from pathlib import Path
DOCS = Path(__file__).parent.resolve() DOCS = Path(__file__).parent.resolve()
@ -41,12 +41,12 @@ def build_docs():
# Build the main documentation # Build the main documentation
print(f'Building docs from {DOCS}') print(f'Building docs from {DOCS}')
os.system(f'mkdocs build -f {DOCS}/mkdocs.yml') subprocess.run(f'mkdocs build -f {DOCS}/mkdocs.yml', check=True, shell=True)
# Build other localized documentations # Build other localized documentations
for file in DOCS.glob('mkdocs_*.yml'): for file in DOCS.glob('mkdocs_*.yml'):
print(f'Building MkDocs site with configuration file: {file}') print(f'Building MkDocs site with configuration file: {file}')
os.system(f'mkdocs build -f {file}') subprocess.run(f'mkdocs build -f {file}', check=True, shell=True)
print(f'Site built at {SITE}') print(f'Site built at {SITE}')

View File

@ -94,7 +94,8 @@ keywords: Ultralytics, Utils, utilitarian functions, colorstr, yaml_save, set_lo
<br><br> <br><br>
--- ---
## ::: ultralytics.utils.is_github_actions_ci
## ::: ultralytics.utils.is_github_action_running
<br><br> <br><br>
--- ---

View File

@ -379,10 +379,10 @@ def test_cfg_init():
def test_utils_init(): def test_utils_init():
"""Test initialization utilities.""" """Test initialization utilities."""
from ultralytics.utils import get_git_branch, get_git_origin_url, get_ubuntu_version, is_github_actions_ci from ultralytics.utils import get_git_branch, get_git_origin_url, get_ubuntu_version, is_github_action_running
get_ubuntu_version() get_ubuntu_version()
is_github_actions_ci() is_github_action_running()
get_git_origin_url() get_git_origin_url()
get_git_branch() get_git_branch()

View File

@ -229,19 +229,29 @@ def set_logging(name=LOGGING_NAME, verbose=True):
level = logging.INFO if verbose and RANK in {-1, 0} else logging.ERROR # rank in world for Multi-GPU trainings level = logging.INFO if verbose and RANK in {-1, 0} else logging.ERROR # rank in world for Multi-GPU trainings
# Configure the console (stdout) encoding to UTF-8 # Configure the console (stdout) encoding to UTF-8
formatter = logging.Formatter('%(message)s') # Default formatter
if WINDOWS and sys.stdout.encoding != 'utf-8': if WINDOWS and sys.stdout.encoding != 'utf-8':
try: try:
if hasattr(sys.stdout, 'reconfigure'): if hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(encoding='utf-8') sys.stdout.reconfigure(encoding='utf-8')
else: elif hasattr(sys.stdout, 'buffer'):
import io import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
else:
sys.stdout.encoding = 'utf-8'
except Exception as e: except Exception as e:
print(f'ERROR setting UTF-8 encoding: {e}') print(f'Creating custom formatter for non UTF-8 environments due to {e}')
class CustomFormatter(logging.Formatter):
def format(self, record):
return emojis(super().format(record))
formatter = CustomFormatter('%(message)s') # Use CustomFormatter to eliminate UTF-8 output as last recourse
# Create and configure the StreamHandler # Create and configure the StreamHandler
stream_handler = logging.StreamHandler(sys.stdout) stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(logging.Formatter('%(message)s')) stream_handler.setFormatter(formatter)
stream_handler.setLevel(level) stream_handler.setLevel(level)
logger = logging.getLogger(name) logger = logging.getLogger(name)
@ -254,7 +264,7 @@ def set_logging(name=LOGGING_NAME, verbose=True):
# Set logger # Set logger
LOGGER = set_logging(LOGGING_NAME, verbose=VERBOSE) # define globally (used in train.py, val.py, predict.py, etc.) LOGGER = set_logging(LOGGING_NAME, verbose=VERBOSE) # define globally (used in train.py, val.py, predict.py, etc.)
for logger in 'sentry_sdk', 'urllib3.connectionpool': for logger in 'sentry_sdk', 'urllib3.connectionpool':
logging.getLogger(logger).setLevel(logging.CRITICAL) logging.getLogger(logger).setLevel(logging.CRITICAL + 1)
def emojis(string=''): def emojis(string=''):