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

chore(ci): test /etc/os-release #706

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ jobs:
restore-keys: |
${{ runner.os }}-mypy

- if: matrix.os == 'ubuntu-latest'
name: Remove /etc/os-release to test #704
run: |
sudo mv /etc/os-release /etc/os-release.tmp
python -c 'import distro, json; print(json.dumps(distro.info(), indent=2))'

- name: Setup database
# for some reason prisma creates the database where the schema is stored
# but when using the prisma query engine it uses the root directory
run: |
python -m prisma db push --schema=tests/data/schema.prisma --skip-generate
cp tests/data/dev.db dev.db

- name: Setup coverage
run: |
Expand Down
1 change: 0 additions & 1 deletion databases/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
coverage==7.1.0
syrupy==3.0.6
dirty-equals==0.5.0
distro

-r ../pipelines/requirements/deps/pyright.txt
-r ../pipelines/requirements/deps/pytest.txt
Expand Down
1 change: 0 additions & 1 deletion pipelines/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ twine==4.0.2
typer==0.7.0
rtoml==0.9.0
GitPython
distro
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ python-dotenv>=0.12.0
typing-extensions>=3.7
tomlkit
nodeenv
distro
cached-property; python_version < '3.8'
28 changes: 8 additions & 20 deletions src/prisma/binaries/platform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import annotations

import re
import sys
import subprocess
import platform as _platform
from functools import lru_cache
from typing import Tuple

import distro


def name() -> str:
Expand All @@ -20,33 +23,18 @@ def check_for_extension(file: str) -> str:

def linux_distro() -> str:
# NOTE: this has only been tested on ubuntu
distro_id, distro_id_like = _get_linux_distro_details()
if distro_id == 'alpine':
if distro.id() == 'alpine':
return 'alpine'

if any(
distro in distro_id_like for distro in ['centos', 'fedora', 'rhel']
):
id_like = distro.like()

if any(d in id_like for d in ['centos', 'fedora', 'rhel']):
return 'rhel'

# default to debian
return 'debian'


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


@lru_cache(maxsize=None)
def binary_platform() -> str:
platform = name()
Expand Down