diff --git a/Makefile b/Makefile index 81170e0e..ff4cb745 100644 --- a/Makefile +++ b/Makefile @@ -154,10 +154,10 @@ doc-check: build: rm -rf build/ dist/ - mv httpie/internal/_build_channel.py httpie/internal/_build_channel.py.original - echo 'BUILD_CHANNEL = "pip"' > httpie/internal/_build_channel.py + mv httpie/internal/__build_channel__.py httpie/internal/__build_channel__.py.original + echo 'BUILD_CHANNEL = "pip"' > httpie/internal/__build_channel__.py $(VENV_PYTHON) -m build --sdist --wheel --outdir dist/ - mv httpie/internal/_build_channel.py.original httpie/internal/_build_channel.py + mv httpie/internal/__build_channel__.py.original httpie/internal/__build_channel__.py publish: test-all publish-no-test diff --git a/extras/packaging/linux/Dockerfile b/extras/packaging/linux/Dockerfile index 83db86f9..ea441fd6 100644 --- a/extras/packaging/linux/Dockerfile +++ b/extras/packaging/linux/Dockerfile @@ -27,7 +27,7 @@ RUN python -m pip install /app RUN python -m pip install pyinstaller wheel RUN python -m pip install --force-reinstall --upgrade pip -RUN echo 'BUILD_CHANNEL="pypi"' > /app/httpie/internal/_build_channel.py +RUN echo 'BUILD_CHANNEL="pypi"' > /app/httpie/internal/__build_channel__.py RUN python build.py ENTRYPOINT ["mv", "/app/extras/packaging/linux/dist/", "/artifacts"] diff --git a/httpie/internal/_build_channel.py b/httpie/internal/__build_channel__.py similarity index 100% rename from httpie/internal/_build_channel.py rename to httpie/internal/__build_channel__.py diff --git a/httpie/internal/daemon_runner.py b/httpie/internal/daemon_runner.py index 8b27068f..1998ba17 100644 --- a/httpie/internal/daemon_runner.py +++ b/httpie/internal/daemon_runner.py @@ -6,7 +6,7 @@ from httpie.context import Environment from httpie.internal.update_warnings import _fetch_updates from httpie.status import ExitStatus -STATUS_FILE = '.status' +STATUS_FILE = '.httpie-test-daemon-status' def _check_status(env): diff --git a/httpie/internal/daemons.py b/httpie/internal/daemons.py index 16d33b12..bdf1be52 100644 --- a/httpie/internal/daemons.py +++ b/httpie/internal/daemons.py @@ -1,3 +1,10 @@ +""" +This module provides an interface to spawn a detached task to be +runned with httpie.internal.daemon_runner on a separate process. It is +based on DVC's daemon system. +https://github.com/iterative/dvc/blob/main/dvc/daemon.py +""" + import inspect import os import platform @@ -6,12 +13,8 @@ import httpie.__main__ from contextlib import suppress from subprocess import Popen from typing import Dict, List -from httpie.compat import is_frozen +from httpie.compat import is_frozen, is_windows -# This module provides an interface to spawn a detached task to be -# runned with httpie.internal.daemon_runner on a separate process. It is -# based on DVC's daemon system. -# https://github.com/iterative/dvc/blob/main/dvc/daemon.py ProcessContext = Dict[str, str] @@ -50,13 +53,15 @@ def _spawn_windows(cmd: List[str], process_context: ProcessContext) -> None: def _spawn_posix(args: List[str], process_context: ProcessContext) -> None: - from httpie.core import main + """ + Perform a double fork procedure* to detach from the parent + process so that we don't block the user even if their original + command's execution is done but the release fetcher is not. - # Perform a double fork procedure* to detach from the parent - # process so that we don't block the user even if their original - # command's execution is done but the release fetcher is not. - # - # [1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_03 + [1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_03 + """ + + from httpie.core import main try: pid = os.fork() @@ -94,6 +99,16 @@ def _spawn_posix(args: List[str], process_context: ProcessContext) -> None: os._exit(0) +def _spawn(args: List[str], process_context: ProcessContext) -> None: + """ + Spawn a new process to run the given command. + """ + if is_windows: + _spawn_windows(args, process_context) + else: + _spawn_posix(args, process_context) + + def spawn_daemon(task: str) -> None: args = [task, '--daemon'] process_context = os.environ.copy() @@ -103,9 +118,4 @@ def spawn_daemon(task: str) -> None: os.path.dirname(os.path.dirname(file_path)) ) - if os.name == 'nt': - # Windows lacks os.fork(), so we need to - # handle it separately. - _spawn_windows(args, process_context) - else: - _spawn_posix(args, process_context) + _spawn(args, process_context) diff --git a/httpie/internal/update_warnings.py b/httpie/internal/update_warnings.py index 9c8fd4c1..a4b80d46 100644 --- a/httpie/internal/update_warnings.py +++ b/httpie/internal/update_warnings.py @@ -8,7 +8,7 @@ import requests import httpie from httpie.context import Environment, LogLevel -from httpie.internal._build_channel import BUILD_CHANNEL +from httpie.internal.__build_channel__ import BUILD_CHANNEL from httpie.internal.daemons import spawn_daemon from httpie.utils import is_version_greater, open_with_lockfile