Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use pathlib in sysinfo.py #14221

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions IPython/utils/sysinfo.py
Original file line number Diff line number Diff line change
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