Skip to content

Commit

Permalink
treewide: make snagfactory an optional package feature
Browse files Browse the repository at this point in the history
The Kivy dependency is causing issues for some users. These users are not
necessarily interested in snagfactory and only want to use snagboot and
snagflash.

Add an optional "gui" dependency group and move the Kivy dependency to this new
group. Snagfactory will not be available unless this dependency group is
selected during installation.

Signed-off-by: Romain Gantois <[email protected]>
  • Loading branch information
rgantois committed Jan 16, 2025
1 parent 937306c commit b3ab72d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ include src/snagrecover/am335x_usb_setup.sh
include src/snagfactory/gui.kv
include src/snagfactory/config.kv
include src/snagfactory/assets/*
include src/snagfactory/gui-requirements.txt

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ $ snagrecover -h
$ snagflash -h
```

Installing the gui variant: `python3 -m pip install --user snagboot[gui]`, provides the additional "snagfactory" command.

You also need to install udev rules so that snagrecover has read and write
access to the USB devices exposed by the SoCs.

Expand All @@ -63,6 +65,8 @@ installation script is provided to automatically build and install the package.
```bash
$ cd snagboot
$ ./install.sh
OR
$ ./install.sh --with-gui
```

There is also an [AUR package](https://aur.archlinux.org/packages/snagboot)
Expand Down Expand Up @@ -129,6 +133,8 @@ To recover and reflash a board using snagboot:
For recovering and flashing large batches of boards efficiently, you may use the Snagfactory application which is included in Snagboot. Usage instructions for Snagfactory are available at [snagfactory.md](https://github.com/bootlin/snagboot/blob/main/docs/snagfactory.md). The configuration file syntax for Snagfactory is documented at [snagfactory_config.md](https://github.com/bootlin/snagboot/blob/main/docs/snagfactory_config.md).


Note that Snagfactory support is only included in the "gui" package variant: `pip install snagboot[gui]`

If you encounter issues, please take a look at the
[troubleshooting](https://github.com/bootlin/snagboot/blob/main/docs/troubleshooting.md) section.

Expand Down
11 changes: 10 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#!/bin/env sh

PACKAGE_VERSION_PATTERN='([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?'
VENV=$(python3 -c "import sys;print(sys.prefix != sys.base_prefix)")
EXTRA=""
if [ "$VENV" = "False" ]; then
EXTRA="--user"
fi

snagboot_version=$(grep "__version__" src/snagrecover/__init__.py | grep -E -o "$PACKAGE_VERSION_PATTERN")

python3 -m pip install $EXTRA build || exit 1

#old binaries in dist can confuse build
rm -f dist/snagboot-*.whl dist/snagboot*.tar.gz
python3 -m build || exit 2

python3 -m pip install $EXTRA dist/snagboot-*-py3-none-any.whl --force-reinstall || exit 3
if [ "$1" = "--with-gui" ]; then
GUI_FEATURE="[gui]"
else
GUI_FEATURE=""
fi

python3 -m pip install $EXTRA "dist/snagboot-$snagboot_version-py3-none-any.whl$GUI_FEATURE" --force-reinstall || exit 3

exit 0
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ where = ["src"]

[tool.setuptools.dynamic]
version = {attr = "snagrecover.__version__"}
optional-dependencies.gui = {file = ["src/snagfactory/gui-requirements.txt"]}

[project]
name = "snagboot"
dynamic = ["version"]
dynamic = ["version", "optional-dependencies"]
authors = [
{ name="Romain Gantois", email="[email protected]" },
]
Expand All @@ -34,7 +35,7 @@ dependencies = [
"crccheck >= 1.3.0",
"pylibfdt >= 1.7.0.post1",
"swig >= 4.1.1",
"kivy == 2.3.0",
"packaging >= 24.2"
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions src/snagfactory/gui-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kivy == 2.3.0
30 changes: 27 additions & 3 deletions src/snagfactory/gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# Check that required Kivy version is installed
# Kivy is an optional dependency for snagboot but snagfactory requires it
import sys
import os
import importlib.metadata
import packaging.requirements
import packaging.version

with open(os.path.dirname(__file__) + "/gui-requirements.txt", "r") as req_file:
gui_dependencies = req_file.read(-1).splitlines()

gui_reqs = [packaging.requirements.Requirement(req_str) for req_str in gui_dependencies]

for req in gui_reqs:
dep_error = ""
try:
version = importlib.metadata.version(req.name)
if version not in req.specifier:
dep_error = f"{req} is required by snagfactory but version {version} is installed"
except importlib.metadata.PackageNotFoundError:
dep_error = f"{req} is required by snagfactory but this package is not installed"

if dep_error != "":
print("please install the snagboot[gui] package variant to run snagfactory! e.g. pip install snagboot[gui]")
print(f"underlying cause: {dep_error}")
sys.exit(1)

from kivy.logger import Logger as kivy_logger
from kivy.app import App
from kivy.uix.widget import Widget
Expand All @@ -16,7 +43,6 @@
import time
import yaml
from math import ceil
import sys

from snagfactory.session import SnagFactorySession
from snagfactory.config import SnagFactoryConfigError
Expand All @@ -25,8 +51,6 @@
import logging
factory_logger = logging.getLogger("snagfactory")

import os

LOG_VIEW_CAPACITY = 100
PROGBAR_TICKS = 20

Expand Down

0 comments on commit b3ab72d

Please sign in to comment.