From 69efd27477e3e95725180cd71948d3f337da0b3b Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Wed, 30 Aug 2023 08:26:00 -1000 Subject: [PATCH] Fix config_server for osx (#304) * Changing the `multiprocessing` module to use `fork` explicitly for mac and windows. This shouldn't really be needed. Ideally would also switch out Flask for FastAPI and do a bunch of other improvements. --- .github/workflows/pythontest.yaml | 7 ++----- CHANGELOG.rst | 8 ++++++++ conftest.py | 14 ++++++++++++-- src/panoptes/utils/config/server.py | 7 +++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pythontest.yaml b/.github/workflows/pythontest.yaml index 6329ff04..2f154bf3 100644 --- a/.github/workflows/pythontest.yaml +++ b/.github/workflows/pythontest.yaml @@ -24,11 +24,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest ] - python-version: [ '3.7', '3.8', '3.9', '3.10' ] - exclude: - - os: macos-latest - python-version: '3.8' + os: [ 'ubuntu-latest' ] + python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bdbc0075..7a186566 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,14 @@ Changelog ========= +0.2.42 - 2023-08-30 +------------------- + +Fixed +^^^^^ + +* Fixed the config_server on osx. + 0.2.41 - 2023-05-17 ------------------- diff --git a/conftest.py b/conftest.py index 12cf8afa..5c7013f4 100644 --- a/conftest.py +++ b/conftest.py @@ -4,6 +4,7 @@ import shutil import tempfile from contextlib import suppress +from pathlib import Path # Doctest modules import numpy as np @@ -158,11 +159,20 @@ def noheader_fits_file(data_dir): @pytest.fixture(scope='function') def cr2_file(data_dir): - cr2_path = os.path.join(data_dir, 'canon.cr2') + cr2_path = Path(data_dir) / 'canon.cr2' - if not os.path.exists(cr2_path): + if cr2_path.exists() is False: pytest.skip("No CR2 file found, skipping test.") + # The file is fetched in conftest.py but may be a 404-not found text message. + # Try to read as text. If we fail it is because the file is a CR2 (i.e. bytes + # and not text). + try: + _ = cr2_path.read_text() + pytest.skip("CR2 file found but it is not a CR2 file, skipping test.") + except UnicodeDecodeError: + pass + with tempfile.TemporaryDirectory() as tmpdirname: copy_file = shutil.copy2(cr2_path, tmpdirname) yield copy_file diff --git a/src/panoptes/utils/config/server.py b/src/panoptes/utils/config/server.py index 30d38e86..289eb45b 100644 --- a/src/panoptes/utils/config/server.py +++ b/src/panoptes/utils/config/server.py @@ -1,5 +1,6 @@ import logging import os +from sys import platform from multiprocessing import Process from flask import Flask @@ -12,6 +13,12 @@ from panoptes.utils.config.helpers import load_config from panoptes.utils.config.helpers import save_config +# This seems to be needed. Should switch entire mechanism. +if platform == "darwin" or platform == "win32": + import multiprocessing + + multiprocessing.set_start_method('fork') + # Turn off noisy logging for Flask wsgi server. logging.getLogger('werkzeug').setLevel(logging.WARNING) logging.getLogger('gevent').setLevel(logging.WARNING)