WUT_Computer_Science/Programming/PSD/zin3/python/setup_environment.sh
Krzysztof kuhy Rudnicki 50263f075a Add pre-commit and fix everything it found
`pre-commit run --all-files` is green. The config only carries hooks whose
subject is already clean, so it stays green at every commit -- file-length,
ruff/mypy and dependency-freshness are listed as blocked, each on its own
cleanup, and the file-REWRITING hooks (trailing-whitespace, end-of-file-fixer)
are held back for their own reviewed commit.

Turning it on found four real things:

1. A committed private key: ERSMS-project/nginx/ssl/nginx.key. It is a
   self-signed CN=localhost cert that had already expired (notAfter
   2025-06-16), so the risk is nil -- but it is regenerable in one openssl
   call, so it is replaced by generate-cert.sh rather than excluded from the
   hook. The script says plainly that removing it from HEAD does NOT
   unpublish it: history is deliberately not rewritten, which is acceptable
   only because nothing ever trusted this key.

2. Four files with unresolved merge conflict markers committed, left over
   from the subtree merges. EARIN/.gitignore and .vscode/extensions.json are
   resolved as the union of both sides. The two Unity folder .meta files each
   had two candidate GUIDs; grepping showed neither is referenced anywhere
   (folder GUIDs rarely are), so either is safe and the HEAD side is kept --
   an arbitrary choice, but a checked one rather than a guess.

3. 62 shellcheck findings across 11 scripts, all fixed, no disables added.
   The interesting pattern was `cd X; cmd &; PID=$!; cd ..`, which trips both
   SC2164 and SC2103 and cannot use a plain subshell without losing the PID.
   `( cd X && exec cmd ) &` keeps the directory, the PID and the semantics.
   EOPSY lab1's submitted solution was verified by RUNNING it afterwards:
   a->A, B->b, foldera->FOLDERA, FOLDERB->folderb, exactly as before.

4. check-json failing on 11 files, which was the wrong parser rather than a
   defect -- tsconfig*.json and .vscode/*.json are JSONC, where TypeScript
   and VS Code both allow comments. Those two path classes are excluded and
   every other .json is still checked. Excluding them is what surfaced the
   merge conflict in (2) as the one genuine failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
2026-08-28 18:21:22 +02:00

75 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# Configuration
VENV_NAME="psd_env"
VENV_PATH="$(pwd)/${VENV_NAME}"
# Recorded for reference: the interpreter this project was developed against.
# Not used by the script, which takes whatever python3 is on PATH.
export PYTHON_VERSION="3.8"
REQUIREMENTS=(
"confluent-kafka"
"apache-flink"
"apache-flink-libraries"
)
echo "Setting up Python environment for PSD project..."
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo "Python 3 is not installed. Please install Python 3 first."
exit 1
fi
# Create virtual environment if it doesn't exist
if [ ! -d "$VENV_PATH" ]; then
echo "Creating virtual environment at $VENV_PATH..."
if ! python3 -m venv "$VENV_PATH"; then
echo "Failed to create virtual environment. Please check your Python installation."
exit 1
fi
echo "Virtual environment created successfully."
else
echo "Virtual environment already exists at $VENV_PATH."
fi
# Activate virtual environment
echo "Activating virtual environment..."
# shellcheck source=/dev/null
if ! source "${VENV_PATH}/bin/activate"; then
echo "Failed to activate virtual environment."
exit 1
fi
# Upgrade pip
echo "Upgrading pip..."
pip install --upgrade pip
# Install required packages if not already installed
echo "Checking and installing required packages..."
for package in "${REQUIREMENTS[@]}"; do
if ! pip show "$package" &> /dev/null; then
echo "Installing $package..."
if ! pip install "$package"; then
echo "Failed to install $package."
exit 1
fi
else
echo "$package is already installed."
fi
done
# Print success message
echo ""
echo "===================================================="
echo "Python environment setup complete!"
echo "Python version: $(python -V)"
echo "Installed packages:"
pip list
echo "===================================================="
echo ""
echo "To activate this environment in the future, run:"
echo "source ${VENV_PATH}/bin/activate"
echo ""
echo "Your environment is now active and ready to use."
echo "===================================================="