Skip to content

Commit

Permalink
Merge pull request #740 from Lewiscowles1986/refactor/windows-error-b…
Browse files Browse the repository at this point in the history
…efore-other-statements

chore: windows error before other imports for nicer error message
  • Loading branch information
amoffat authored Oct 17, 2024
2 parents 695922e + a90f61c commit c767bc4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
from collections import deque
from collections.abc import Mapping

import platform
from importlib import metadata

try:
__version__ = metadata.version("sh")
except metadata.PackageNotFoundError: # pragma: no cover
__version__ = "unknown"

if "windows" in platform.system().lower(): # pragma: no cover
raise ImportError(
f"sh {__version__} is currently only supported on Linux and macOS."
)

import errno
import fcntl
import gc
Expand All @@ -35,7 +48,6 @@
import inspect
import logging
import os
import platform
import pty
import pwd
import re
Expand All @@ -55,7 +67,6 @@
from asyncio import Queue as AQueue
from contextlib import contextmanager
from functools import partial
from importlib import metadata
from io import BytesIO, StringIO, UnsupportedOperation
from io import open as fdopen
from locale import getpreferredencoding
Expand All @@ -64,17 +75,8 @@
from types import GeneratorType, ModuleType
from typing import Any, Dict, Type, Union

try:
__version__ = metadata.version("sh")
except metadata.PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
__project_url__ = "https://github.com/amoffat/sh"

if "windows" in platform.system().lower(): # pragma: no cover
raise ImportError(
f"sh {__version__} is currently only supported on Linux and macOS."
)

TEE_STDOUT = {True, "out", 1}
TEE_STDERR = {"err", 2}

Expand Down

0 comments on commit c767bc4

Please sign in to comment.