Apply review feedback.

This commit is contained in:
Batuhan Taskaya 2022-05-05 19:24:37 +03:00
parent 6e75c5244d
commit 309037fca9
6 changed files with 33 additions and 23 deletions

View File

@ -154,10 +154,10 @@ doc-check:
build: build:
rm -rf build/ dist/ rm -rf build/ dist/
mv httpie/internal/_build_channel.py httpie/internal/_build_channel.py.original mv httpie/internal/__build_channel__.py httpie/internal/__build_channel__.py.original
echo 'BUILD_CHANNEL = "pip"' > httpie/internal/_build_channel.py echo 'BUILD_CHANNEL = "pip"' > httpie/internal/__build_channel__.py
$(VENV_PYTHON) -m build --sdist --wheel --outdir dist/ $(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 publish: test-all publish-no-test

View File

@ -27,7 +27,7 @@ RUN python -m pip install /app
RUN python -m pip install pyinstaller wheel RUN python -m pip install pyinstaller wheel
RUN python -m pip install --force-reinstall --upgrade pip 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 RUN python build.py
ENTRYPOINT ["mv", "/app/extras/packaging/linux/dist/", "/artifacts"] ENTRYPOINT ["mv", "/app/extras/packaging/linux/dist/", "/artifacts"]

View File

@ -6,7 +6,7 @@ from httpie.context import Environment
from httpie.internal.update_warnings import _fetch_updates from httpie.internal.update_warnings import _fetch_updates
from httpie.status import ExitStatus from httpie.status import ExitStatus
STATUS_FILE = '.status' STATUS_FILE = '.httpie-test-daemon-status'
def _check_status(env): def _check_status(env):

View File

@ -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 inspect
import os import os
import platform import platform
@ -6,12 +13,8 @@ import httpie.__main__
from contextlib import suppress from contextlib import suppress
from subprocess import Popen from subprocess import Popen
from typing import Dict, List 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] 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: 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 [1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_03
# process so that we don't block the user even if their original """
# command's execution is done but the release fetcher is not.
# from httpie.core import main
# [1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_03
try: try:
pid = os.fork() pid = os.fork()
@ -94,6 +99,16 @@ def _spawn_posix(args: List[str], process_context: ProcessContext) -> None:
os._exit(0) 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: def spawn_daemon(task: str) -> None:
args = [task, '--daemon'] args = [task, '--daemon']
process_context = os.environ.copy() process_context = os.environ.copy()
@ -103,9 +118,4 @@ def spawn_daemon(task: str) -> None:
os.path.dirname(os.path.dirname(file_path)) os.path.dirname(os.path.dirname(file_path))
) )
if os.name == 'nt': _spawn(args, process_context)
# Windows lacks os.fork(), so we need to
# handle it separately.
_spawn_windows(args, process_context)
else:
_spawn_posix(args, process_context)

View File

@ -8,7 +8,7 @@ import requests
import httpie import httpie
from httpie.context import Environment, LogLevel 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.internal.daemons import spawn_daemon
from httpie.utils import is_version_greater, open_with_lockfile from httpie.utils import is_version_greater, open_with_lockfile