Skip to content

Commit 433c797

Browse files
committed
added docs for requirements.txt package install feature (see #66, #68, #69)
1 parent 60232a3 commit 433c797

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/reference.rst

+29
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,35 @@ This adds a new folder ``config/pyscript_modules`` to Python's module search pat
10461046
modules (files ending in ``.py``) to that folder, which will contain native python that is compiled
10471047
when imported (note that none of the pyscript-specific features are available).
10481048

1049+
Pyscript can install required Python packages if they are missing. Depending on how you run HASS
1050+
(eg, using a minimal Docker container) it might not be convenient to manually install Python packages
1051+
using `pip`. If your pyscript code requires particular Python packages that are not already installed
1052+
by HASS, add a ``requirements.txt`` file the ``<config>/pyscript`` directory. This file lists each
1053+
required package one per line, with an optional version if you require a specific version or minimum
1054+
version of that package, eg:
1055+
1056+
.. code::
1057+
1058+
# this is a comment
1059+
aiohttp
1060+
amazing_stuff>=3.1
1061+
another_package==5.1.2
1062+
1063+
Each app's or module's directory (assuming they use the directory-form of a package) can also
1064+
contain an optional ``requirements.txt`` file:
1065+
1066+
- ``<config>/pyscript/modules/PACKAGE_NAME/requirements.txt``
1067+
- ``<config>/pyscript/apps/APP_NAME/requirements.txt``
1068+
1069+
That allows you to specify the specific requirements for each pyscript module or app. If you release
1070+
or share your module or app, all its code and requirements are self-contained, and any user can
1071+
simply install the files in that directory and the requirements will be checked on the next
1072+
start of HASS or reload of pyscript.
1073+
1074+
If a required package version differs from the installed one, no change is made since it's likely
1075+
HASS has a requirement that pyscript should not change. In that case a warning message will be
1076+
logged and the requirement will be skipped.
1077+
10491078
Trigger Closures
10501079
^^^^^^^^^^^^^^^^
10511080

docs/release_history.rst

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The new features since 0.32 in master include:
3333
event firing and service calls. Proposal and PR by @dlashua (#50, #60).
3434
- Logbook now supported using ``context`` and informational message based on trigger type. Proposal and PR by
3535
@dlashua (#50, #62).
36+
- Required Python packages can be specified in ``requirements.txt`` files at the top-level pyscript
37+
directory, and each module's or app's directory. Those files are read and any missing packages are
38+
installed on HASS startup and pyscript reload. Contributed by @raman325 (#66, #68, #69).
3639

3740
The bug fixes since 0.32 in master include:
3841

0 commit comments

Comments
 (0)