now using a venv to run the scripts

This commit is contained in:
Félix Boisselier
2023-11-29 11:43:21 +01:00
parent a1e9269ba3
commit 43a205d036
9 changed files with 220 additions and 20 deletions

160
.gitignore vendored Normal file
View File

@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

View File

@@ -55,7 +55,7 @@ gcode:
RESPOND MSG="X axis frequency profile generation..." RESPOND MSG="X axis frequency profile generation..."
RESPOND MSG="This may take some time (1-3min)" RESPOND MSG="This may take some time (1-3min)"
{% endif %} {% endif %}
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER RUN_SHELL_COMMAND CMD=shaketune PARAMS=SHAPER
{% endif %} {% endif %}
{% if Y %} {% if Y %}
@@ -66,7 +66,7 @@ gcode:
RESPOND MSG="Y axis frequency profile generation..." RESPOND MSG="Y axis frequency profile generation..."
RESPOND MSG="This may take some time (1-3min)" RESPOND MSG="This may take some time (1-3min)"
{% endif %} {% endif %}
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER RUN_SHELL_COMMAND CMD=shaketune PARAMS=SHAPER
{% endif %} {% endif %}
@@ -88,7 +88,7 @@ gcode:
RESPOND MSG="Belts comparative frequency profile generation..." RESPOND MSG="Belts comparative frequency profile generation..."
RESPOND MSG="This may take some time (3-5min)" RESPOND MSG="This may take some time (3-5min)"
{% endif %} {% endif %}
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=BELTS RUN_SHELL_COMMAND CMD=shaketune PARAMS=BELTS
[gcode_macro EXCITATE_AXIS_AT_FREQ] [gcode_macro EXCITATE_AXIS_AT_FREQ]

View File

@@ -168,7 +168,7 @@ gcode:
{% if verbose %} {% if verbose %}
RESPOND MSG="Graphs generation... Please wait a minute or two and look in the configured folder." RESPOND MSG="Graphs generation... Please wait a minute or two and look in the configured folder."
{% endif %} {% endif %}
RUN_SHELL_COMMAND CMD=plot_graph PARAMS="VIBRATIONS {direction}" RUN_SHELL_COMMAND CMD=shaketune PARAMS="VIBRATIONS {direction}"
# Restore the previous acceleration values # Restore the previous acceleration values
SET_VELOCITY_LIMIT ACCEL={old_accel} ACCEL_TO_DECEL={old_accel_to_decel} SQUARE_CORNER_VELOCITY={old_sqv} SET_VELOCITY_LIMIT ACCEL={old_accel} ACCEL_TO_DECEL={old_accel_to_decel} SQUARE_CORNER_VELOCITY={old_sqv}

View File

@@ -1,4 +1,4 @@
[gcode_shell_command plot_graph] [gcode_shell_command shaketune]
command: ~/printer_data/config/K-ShakeTune/scripts/is_workflow.py command: ~/printer_data/config/K-ShakeTune/scripts/shaketune.sh
timeout: 600.0 timeout: 600.0
verbose: True verbose: True

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
############################################ ############################################
###### INPUT SHAPER KLIPPAIN WORKFLOW ###### ###### INPUT SHAPER KLIPPAIN WORKFLOW ######
############################################ ############################################
@@ -223,7 +224,7 @@ def main():
os.makedirs(folder) os.makedirs(folder)
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("Usage: plot_graphs.py [SHAPER|BELTS|VIBRATIONS]") print("Usage: is_workflow.py [SHAPER|BELTS|VIBRATIONS]")
sys.exit(1) sys.exit(1)
if sys.argv[1].lower() == 'belts': if sys.argv[1].lower() == 'belts':
@@ -233,7 +234,7 @@ def main():
elif sys.argv[1].lower() == 'vibrations': elif sys.argv[1].lower() == 'vibrations':
fig, png_filename = get_vibrations_graph(axis_name=sys.argv[2]) fig, png_filename = get_vibrations_graph(axis_name=sys.argv[2])
else: else:
print("Usage: plot_graphs.py [SHAPER|BELTS|VIBRATIONS]") print("Usage: is_workflow.py [SHAPER|BELTS|VIBRATIONS]")
sys.exit(1) sys.exit(1)
fig.savefig(png_filename) fig.savefig(png_filename)

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
source ~/klippain_shaketune-env/bin/activate
python ~/klippain_shaketune/K-ShakeTune/scripts/is_workflow.py "$@"
deactivate

View File

@@ -19,16 +19,16 @@ Check out the **[detailed documentation of the Shake&Tune module here](./docs/RE
## Installation ## Installation
For those not using the full [Klippain](https://github.com/Frix-x/klippain), follow these steps to integrate this Shake&Tune module in your setup: Follow these steps to install the Shake&Tune module in your printer:
1. Run the install script over SSH on your printer: 1. Run the install script over SSH on your printer:
```bash ```bash
wget -O - https://raw.githubusercontent.com/Frix-x/klippain-shaketune/main/install.sh | bash wget -O - https://raw.githubusercontent.com/Frix-x/klippain-shaketune/main/install.sh | bash
``` ```
2. Append the following to your `printer.cfg` file: 1. Append the following to your `printer.cfg` file:
``` ```
[include K-ShakeTune/*.cfg] [include K-ShakeTune/*.cfg]
``` ```
3. Optionally, if you want to get automatic updates, add the following to your `moonraker.cfg` file: 1. Optionally, if you want to get automatic updates, add the following to your `moonraker.cfg` file:
``` ```
[update_manager Klippain-ShakeTune] [update_manager Klippain-ShakeTune]
type: git_repo type: git_repo
@@ -42,7 +42,7 @@ For those not using the full [Klippain](https://github.com/Frix-x/klippain), fol
> **Note**: > **Note**:
> >
> If already using my old IS workflow scripts, please remove everything before installing this new module. This include the macros, the Python scripts, the `plot_graph.sh` and the `[gcode_shell_command plot_graph]` section. > If already using my old IS workflow scripts, please remove everything before installing this new module. This include the macros, the Python scripts, the `plot_graph.sh` and the `[gcode_shell_command plot_graph]` section that are not needed anymore.
## Usage ## Usage

View File

@@ -2,7 +2,9 @@
USER_CONFIG_PATH="${HOME}/printer_data/config" USER_CONFIG_PATH="${HOME}/printer_data/config"
KLIPPER_PATH="${HOME}/klipper" KLIPPER_PATH="${HOME}/klipper"
K_SHAKETUNE_PATH="${HOME}/klippain_shaketune" K_SHAKETUNE_PATH="${HOME}/klippain_shaketune"
K_SHAKETUNE_VENV_PATH="${HOME}/klippain_shaketune-env"
set -eu set -eu
export LC_ALL=C export LC_ALL=C
@@ -14,19 +16,17 @@ function preflight_checks {
exit -1 exit -1
fi fi
if ! command -v python3 &> /dev/null; then
echo "[ERROR] Python 3 is not installed. Please install Python 3 to use the Shake&Tune module!"
exit -1
fi
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F 'klipper.service')" ]; then if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F 'klipper.service')" ]; then
printf "[PRE-CHECK] Klipper service found! Continuing...\n\n" printf "[PRE-CHECK] Klipper service found! Continuing...\n\n"
else else
echo "[ERROR] Klipper service not found, please install Klipper first!" echo "[ERROR] Klipper service not found, please install Klipper first!"
exit -1 exit -1
fi fi
if [ -d "${HOME}/klippain_config" ]; then
if [ -f "${USER_CONFIG_PATH}/.VERSION" ]; then
echo "[ERROR] Klippain full installation found! Nothing is needed in order to use the K-Shake&Tune module!"
exit -1
fi
fi
} }
function check_download { function check_download {
@@ -48,9 +48,31 @@ function check_download {
fi fi
} }
function setup_venv {
if [ ! -d "${K_SHAKETUNE_VENV_PATH}" ]; then
echo "[SETUP] Creating Python virtual environment..."
python3 -m venv "${K_SHAKETUNE_VENV_PATH}"
else
echo "[SETUP] Virtual environment already exists. Continuing..."
fi
source "${K_SHAKETUNE_VENV_PATH}/bin/activate"
echo "[SETUP] Installing/Updating K-Shake&Tune dependencies..."
pip install --upgrade pip
pip install -r "${K_SHAKETUNE_PATH}/requirements.txt"
deactivate
printf "\n"
}
function link_extension { function link_extension {
echo "[INSTALL] Linking scripts to your config directory..." echo "[INSTALL] Linking scripts to your config directory..."
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/K-ShakeTune
if [ -d "${HOME}/klippain_config" ] && [ -f "${USER_CONFIG_PATH}/.VERSION" ]; then
echo "[INSTALL] Klippain full installation found! Linking module to the script folder of Klippain"
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/scripts/K-ShakeTune
else
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/K-ShakeTune
fi
} }
function link_gcodeshellcommandpy { function link_gcodeshellcommandpy {
@@ -76,6 +98,7 @@ printf "=============================================\n\n"
# Run steps # Run steps
preflight_checks preflight_checks
check_download check_download
setup_venv
link_extension link_extension
link_gcodeshellcommandpy link_gcodeshellcommandpy
restart_klipper restart_klipper

11
requirements.txt Normal file
View File

@@ -0,0 +1,11 @@
contourpy==1.2.0
cycler==0.12.1
fonttools==4.45.1
kiwisolver==1.4.5
matplotlib==3.8.2
numpy==1.26.2
packaging==23.2
Pillow==10.1.0
pyparsing==3.1.1
python-dateutil==2.8.2
six==1.16.0