Skip to content

Commit

Permalink
Fix platform check
Browse files Browse the repository at this point in the history
`cat /etc/os-release` is not always available, the prisma client broke when trying to deploy in an Ubuntu 22.04 VM. This uses the standard library's `platform` instead.
  • Loading branch information
m3at authored Dec 13, 2024
1 parent b12ab3a commit d4658e4
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/prisma/binaries/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ def linux_distro() -> str:


def _get_linux_distro_details() -> Tuple[str, str]:
process = subprocess.run(['cat', '/etc/os-release'], stdout=subprocess.PIPE, check=True)
output = str(process.stdout, sys.getdefaultencoding())

match = re.search(r'ID="?([^"\n]*)"?', output)
distro_id = match.group(1) if match else ''

match = re.search(r'ID_LIKE="?([^"\n]*)"?', output)
distro_id_like = match.group(1) if match else ''
return distro_id, distro_id_like
if hasattr(platform, 'freedesktop_os_release'):
# For python >= 3.10
distro = platform.freedesktop_os_release()
else:
distro = platform.linux_distribution()
return distro.get('ID', ''), distro.get('ID_LIKE', '')


@lru_cache(maxsize=None)
Expand Down

0 comments on commit d4658e4

Please sign in to comment.