Skip to content

Commit

Permalink
fix: global interpreter was used in subprocess instead of venv
Browse files Browse the repository at this point in the history
  • Loading branch information
BartSte committed Apr 7, 2024
1 parent 44fda4e commit 31a8d7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
- name: Run tests
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip
python3 -m pip install --upgrade pip
python3 -m venv .venv
source .venv/bin/activate
pip install ".[test]"
- name: Run Pytest
shell: 'script -q -e -c "bash {0}"' # work around tty issues
env:
TERM: linux # fix tput for tty issue work around
run: |
source .venv/bin/activate
python3 -m pip install ".[test]"
python3 -m pytest
4 changes: 2 additions & 2 deletions src/khalorg/khal/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(self, name: str):
"""
path_config: Union[str, None] = find_configuration_file()

new_item_args: list = ['khal', 'new']
list_args: list = ['khal', 'list', '-df', '']
new_item_args: list = ["python3", "-m", "khal", "new"]
list_args: list = ["python3", "-m", "khal", "list", "-df", ""]

self._collection: CalendarCollection
self._new_item: Callable = subprocess_callback(new_item_args)
Expand Down
7 changes: 5 additions & 2 deletions src/khalorg/khal/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys
from datetime import date, datetime
from subprocess import STDOUT, CalledProcessError, check_output
from typing import Callable
Expand Down Expand Up @@ -56,6 +57,7 @@ def subprocess_callback(cmd: list) -> Callable:
callback function
"""

def callback(args: list) -> str:
return try_check_output([*cmd, *args]).decode()

Expand All @@ -64,12 +66,13 @@ def callback(args: list) -> str:

def try_check_output(args: list) -> bytes:
try:
return check_output(args, stderr=STDOUT)
return check_output(args, stderr=STDOUT, executable=sys.executable)
except CalledProcessError as error:
error_message: str = (
f"The following arguments were sent to khal:\n\n{' '.join(args)}"
"\n\nNext, the following error was received from khal:\n\n"
f"{error.output.decode()}\n\n")
f"{error.output.decode()}\n\n"
)
logging.critical(error_message)
raise Exception(error_message) from error

Expand Down

0 comments on commit 31a8d7d

Please sign in to comment.