Skip to content

Commit

Permalink
Merge pull request #16 from DINFO-UniFI/dependencies/embed
Browse files Browse the repository at this point in the history
Embed external Python libraries
  • Loading branch information
Guts authored Jun 28, 2021
2 parents 989fc4d + 07a113e commit 7d05103
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/packager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U -r requirements/packaging.txt
python -m pip install --no-deps -U -r requirements/embedded.txt -t roof_classify/embedded_external_libs
- name: Update translations
run: pylupdate5 -noobsolete -verbose ${{ env.PROJECT_FOLDER }}/resources/i18n/plugin_translation.pro
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U -r requirements/packaging.txt
python -m pip install --no-deps -U -r requirements/embedded.txt -t roof_classify/embedded_external_libs
- name: Compile translations
run: lrelease roof_classify/resources/i18n/*.ts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
- name: Install Python requirements
run: |
python3 -m pip install -U pip setuptools wheel
python -m pip install --no-deps -U -r requirements/embedded.txt -t roof_classify/embedded_external_libs
python3 -m pip install -U -r requirements/testing.txt
- name: Run Unit tests
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ dmypy.json

# *.qm
*.zip
.vscode/
roof_classify/embedded_external_libs/

10 changes: 9 additions & 1 deletion docs/development/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ In your virtual environment:

```bash
# use the latest pip version
python -m pip install -U pip setuptools wheel
python -m pip install -U pip
# install development tools
python -m pip install -U -r requirements/development.txt
# install external dependencies
python -m pip install --no-deps -U -r requirements/embedded.txt -t roof_classify/embedded_external_libs
# install pre-commit to respect common development guidelines
pre-commit install
```

## Additionnal external dependencies

This plugin has external dependencies listed in this specific file: <requirements/embedded.txt>

Because it's still hard to install Python 3rd party packages from an index (for example <https://pypi.org>), especially on Windows or Mac systems (or even on Linux if we want to do it properly in a virtual environment), those required packages are stored in the `embedded_external_libs` folder.
6 changes: 4 additions & 2 deletions requirements/development.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Develoment dependencies
# -----------------------
# Development dependencies
# ------------------------

-r base.txt

black
flake8>=3.8,<3.10
Expand Down
8 changes: 8 additions & 0 deletions requirements/embedded.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Embedded requirements
#
# Typical command to install:
# python -m pip install --no-deps -U -r requirements/embedded.txt -t roof_classify/embedded_external_libs
# -----------------------

joblib>=0.11
scikit-learn==0.24.*
25 changes: 17 additions & 8 deletions roof_classify/roof_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@
#IMPORT PER CLASSIFICATORE
import shapefile
from osgeo import gdal
from PyQt4.QtCore import QCoreApplication, QSettings, QTranslator, qVersion
from PyQt4.QtGui import QAction, QFileDialog, QIcon

# Import the code for the dialog
from roof_classify_dialog import RoofClassifyDialog
from sklearn import metrics
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QFileDialog

try:
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
except Exception:
import site

from roof_classify.__about__ import DIR_PLUGIN_ROOT
site.addsitedir(DIR_PLUGIN_ROOT / "embedded_external_libs")
# from roof_classify.embedded_external_libs import joblib
from roof_classify.embedded_external_libs.sklearn.ensemble import (
RandomForestClassifier,
)
from roof_classify.embedded_external_libs.sklearn.svm import SVC

from roof_classify.__about__ import DIR_PLUGIN_ROOT, __title__
from roof_classify.toolbelt import PlgLogger
Expand Down

0 comments on commit 7d05103

Please sign in to comment.