Skip to content

Commit

Permalink
refactor: use pathlib in sysinfo.py (#14221)
Browse files Browse the repository at this point in the history
* Replace `os.path` with `pathlib.Path`
* Add type hints for the functions

Related to: #12515
  • Loading branch information
Carreau committed Oct 27, 2023
2 parents 7781a42 + 2710ec6 commit 1229389
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions IPython/utils/sysinfo.py
Expand Up @@ -20,14 +20,16 @@
import sys
import subprocess

from pathlib import Path

from IPython.core import release
from IPython.utils import _sysinfo, encoding

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------

def pkg_commit_hash(pkg_path):
def pkg_commit_hash(pkg_path: str) -> tuple[str, str]:
"""Get short form of commit hash given directory `pkg_path`
We get the commit hash from (in order of preference):
Expand Down Expand Up @@ -65,7 +67,7 @@ def pkg_commit_hash(pkg_path):
return '(none found)', '<not found>'


def pkg_info(pkg_path):
def pkg_info(pkg_path: str) -> dict:
"""Return dict describing the context of this package
Parameters
Expand All @@ -92,11 +94,10 @@ def pkg_info(pkg_path):
default_encoding=encoding.DEFAULT_ENCODING,
)

def get_sys_info():
def get_sys_info() -> dict:
"""Return useful information about IPython and the system, as a dict."""
p = os.path
path = p.realpath(p.dirname(p.abspath(p.join(__file__, '..'))))
return pkg_info(path)
path = Path(__file__, "..").resolve().parent
return pkg_info(str(path))

def sys_info():
"""Return useful information about IPython and the system, as a string.
Expand Down

0 comments on commit 1229389

Please sign in to comment.