Skip to content

Commit

Permalink
Future3 fix venv usage (#2111)
Browse files Browse the repository at this point in the history
* fix node setup

nodejs includes npm. fails on extra installation
folder keyrings might not be created yet

* install python packages via pip in venv

* move venv to project root

* remove outdated comments / messages about venv

* remove hardwired path. replace during installation

* fix dead variable

* #2112 fix 'not tagged as plugin callable'
  • Loading branch information
AlvinSchiller authored Nov 16, 2023
1 parent d62de5f commit acf6ec0
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 41 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pythonpackage_future3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
sudo apt-get update
sudo apt-get install -y libasound2-dev pulseaudio
python3 -m pip install --upgrade pip
pip3 install wheel
pip3 install spidev
pip3 install -r requirements.txt
# For operation of the Jukebox, ZMQ must be compiled from sources due to Websocket support
# Also install all optional dependencies
Expand Down
5 changes: 2 additions & 3 deletions docker/armv7/jukebox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ RUN apt-get update && apt-get install -qq -y \
--allow-downgrades --allow-remove-essential --allow-change-held-packages \
at wget gcc \
mpc mpg123 git ffmpeg spi-tools netcat alsa-tools \
python3 python3-venv python3-dev python3-pip python3-setuptools python3-mutagen python3-gpiozero
python3 python3-venv python3-dev python3-mutagen
#samba samba-common-bin
#raspberrypi-kernel-headers
#resolvconf
#python3-spidev

# Install Jukebox
# Install libzmq with Websocket support from pre-compiled source
Expand Down Expand Up @@ -57,7 +56,7 @@ RUN mkdir -p ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
# zeromq-${ZMQ_VERSION}/configure --prefix=${ZMQ_PREFIX} --enable-drafts; \
# make && make install;

ENV VIRTUAL_ENV=/opt/venv
ENV VIRTUAL_ENV=${INSTALLATION_PATH}/.venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

Expand Down
4 changes: 2 additions & 2 deletions docker/jukebox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ RUN apt-get update && apt-get install -qq -y \
--allow-downgrades --allow-remove-essential --allow-change-held-packages \
gcc at wget \
espeak mpc mpg123 git ffmpeg spi-tools netcat \
python3 python3-venv python3-dev python3-pip python3-mutagen python3-gpiozero
python3 python3-venv python3-dev python3-mutagen

ENV VIRTUAL_ENV=/opt/venv
ENV VIRTUAL_ENV=${INSTALLATION_PATH}/.venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

Expand Down
3 changes: 1 addition & 2 deletions documentation/content/developers/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ developing.

The jukebox also runs on any Linux machine. The Raspberry Pi specific
stuff will not work of course. That is no issue depending our your
development area. USB RFID Readers, however, will work. You may setup a
Python virtual environment or a conda virtual environment. You will have
development area. USB RFID Readers, however, will work. You will have
to install and configure [MPD (Music Player
Daemon)](https://www.musicpd.org/).

Expand Down
2 changes: 1 addition & 1 deletion installation/includes/00_constants.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RPI_BOOT_CONFIG_FILE="/boot/config.txt"
SHARED_PATH="${INSTALLATION_PATH}/shared"
SETTINGS_PATH="${SHARED_PATH}/settings"
SYSTEMD_USR_PATH="/usr/lib/systemd/user/"
SYSTEMD_USR_PATH="/usr/lib/systemd/user"

# The default upstream user, release branch, and develop branch
# These are used to prepare the repo for developers
Expand Down
32 changes: 17 additions & 15 deletions installation/routines/setup_jukebox_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@ echo " --------------------------------------------------------------------

# Functions
_jukebox_core_install_os_dependencies() {
echo "Install Jukebox OS dependencies"
sudo apt-get -y update; sudo apt-get -y install \
echo " Install Jukebox OS dependencies"
sudo apt-get -y update && sudo apt-get -y install \
at \
alsa-utils \
python3 python3-venv python3-dev python3-pip python3-setuptools \
python3-rpi.gpio python3-gpiozero \
python3 python3-venv python3-dev \
espeak ffmpeg mpg123 \
pulseaudio pulseaudio-module-bluetooth pulseaudio-utils caps \
libasound2-dev \
--no-install-recommends \
--allow-downgrades \
--allow-remove-essential \
--allow-change-held-packages
}

_jukebox_core_install_python_requirements() {
echo " Install Python requirements"

VIRTUAL_ENV="${HOME_PATH}/.venv"
cd "${INSTALLATION_PATH}" || exit_on_error

VIRTUAL_ENV="${INSTALLATION_PATH}/.venv"
python3 -m venv $VIRTUAL_ENV
PATH="$VIRTUAL_ENV/bin:$PATH"
source "$VIRTUAL_ENV/bin/activate"

pip install --upgrade pip
pip install --no-cache-dir -r "${INSTALLATION_PATH}/requirements.txt"
}

_jukebox_core_configure_pulseaudio() {
Expand Down Expand Up @@ -111,12 +116,6 @@ _jukebox_core_build_and_install_pyzmq() {
fi
}

_jukebox_core_install_python_requirements() {
echo " Install requirements"
cd "${INSTALLATION_PATH}" || exit_on_error
pip install --no-cache-dir -r "${INSTALLATION_PATH}/requirements.txt"
}

_jukebox_core_install_settings() {
echo " Register Jukebox settings"
cp -f "${INSTALLATION_PATH}/resources/default-settings/jukebox.default.yaml" "${SETTINGS_PATH}/jukebox.yaml"
Expand All @@ -125,8 +124,11 @@ _jukebox_core_install_settings() {

_jukebox_core_register_as_service() {
echo " Register Jukebox Core user service"
sudo cp -f "${INSTALLATION_PATH}/resources/default-services/jukebox-daemon.service" "${SYSTEMD_USR_PATH}"
sudo chmod 644 "${SYSTEMD_USR_PATH}/jukebox-daemon.service"

local jukebox_service="${SYSTEMD_USR_PATH}/jukebox-daemon.service"
sudo cp -f "${INSTALLATION_PATH}/resources/default-services/jukebox-daemon.service" "${jukebox_service}"
sudo sed -i "s|%%INSTALLATION_PATH%%|${INSTALLATION_PATH}|g" "${jukebox_service}"
sudo chmod 644 "${jukebox_service}"

systemctl --user daemon-reload
systemctl --user enable jukebox-daemon.service
Expand All @@ -136,8 +138,8 @@ setup_jukebox_core() {
echo "Install Jukebox Core" | tee /dev/fd/3

_jukebox_core_install_os_dependencies
_jukebox_core_configure_pulseaudio
_jukebox_core_install_python_requirements
_jukebox_core_configure_pulseaudio
_jukebox_core_build_and_install_pyzmq
_jukebox_core_install_settings
_jukebox_core_register_as_service
Expand Down
4 changes: 3 additions & 1 deletion installation/routines/setup_jukebox_webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ _jukebox_webapp_install_node() {
else
# install NodeJS and npm as recommended in
# https://github.com/nodesource/distributions
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs npm -y
sudo apt-get install -y nodejs
fi

fi
Expand Down
2 changes: 1 addition & 1 deletion installation/routines/setup_mpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setup_mpd() {

local MPD_EXECUTE_INSTALL=true

if [[ -f ${MPD_CONF_PATH} || -f ${SYSTEMD_PATH}/mpd.service ]]; then
if [[ -f ${MPD_CONF_PATH} || -f ${SYSTEMD_USR_PATH}/mpd.service ]]; then
echo " It seems there is a MPD already installed."
echo " Note: It is important that MPD runs as a user service!"
echo " Would you like to overwrite your configuration? [Y/n] " | tee /dev/fd/3
Expand Down
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Common python packages
# You need to install these with `python -m pip install --no-cache-dir -r requirements.txt`

setuptools
wheel

# Note:
# sudo apt install libasound2-dev required on some machines

Expand All @@ -13,10 +19,9 @@ requests
# For the publisher event reactor loop:
tornado

# RPi's GPIO packages: these are installed via APT on the PI
# On regular machines, install them manually if needed for development
# RPi.GPIO
# gpiozero
# RPi's GPIO packages:
RPi.GPIO
gpiozero

# PyZMQ is a special case:
# On the PI, it needs to be compiled with special options to enable Websocket support
Expand All @@ -28,4 +33,3 @@ tornado
flake8>=4.0.0
pytest
mock

4 changes: 2 additions & 2 deletions resources/default-services/jukebox-daemon.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ After=network.target sound.target mpd.service pulseaudio.service
Requires=mpd.service pulseaudio.service

[Service]
WorkingDirectory=/home/pi/RPi-Jukebox-RFID/src/jukebox
ExecStart=/bin/bash -c 'source /home/pi/.venv/bin/activate && /home/pi/.venv/bin/python run_jukebox.py'
WorkingDirectory=%%INSTALLATION_PATH%%/src/jukebox
ExecStart=/bin/bash -c 'source %%INSTALLATION_PATH%%/.venv/bin/activate && python run_jukebox.py'
StandardOutput=inherit
StandardError=inherit
Restart=always
Expand Down
7 changes: 0 additions & 7 deletions src/jukebox/components/rfid/configure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ def reader_install_dependencies(reader_path: str, dependency_install: str) -> No
if os.path.exists(reader_path + '/requirements.txt'):
# The python dependencies (if any)
print("\nInstalling/Checking Python dependencies ...\n")
print("IMPORTANT for developers: Python dependencies will be installed using "
" $ pip install --upgrade -r requirements.txt'\n"
" i.e. on system level. This is target for the default RPI setup. "
"If you do not want that, but rather have them in a local or virtual environment, "
"hit No here and manually install the dependencies from your virtual environment\n"
" $ pip install --upgrade -r requirements.txt'\n"
"It is no problem to install them after running this script.\n\n")
if dependency_install == 'auto' or pyil.input_yesno("Install Python dependencies?", blank=True,
prompt_color=Colors.lightgreen, prompt_hint=True):
print(f"{'=' * 80}")
Expand Down
1 change: 1 addition & 0 deletions src/jukebox/jukebox/multitimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def start(self, iterations=None, wait_seconds_per_iteration=None):
self._function = self._callee(*self.class_args, iterations=self._iterations, **self.class_kwargs)
super().start(wait_seconds_per_iteration)

@plugin.tag
def get_state(self):
return {'enabled': self.is_alive(),
'wait_seconds_per_iteration': self.get_timeout(),
Expand Down

0 comments on commit acf6ec0

Please sign in to comment.