Skip to content

Commit bd2493b

Browse files
authored
Merge pull request #631 from hx2A/downloadlibraries
Download libraries
2 parents 96b4fb5 + 022a21e commit bd2493b

15 files changed

Lines changed: 328 additions & 20 deletions

generator/reference.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,30 @@
354354
"None",
355355
)
356356
],
357+
("Py5Tools", "processing_library_storage_dir"): [
358+
(
359+
[],
360+
"Path",
361+
)
362+
],
363+
("Py5Tools", "processing_installed_libraries"): [
364+
(
365+
[],
366+
"list[str]",
367+
)
368+
],
369+
("Py5Tools", "processing_check_library"): [
370+
(
371+
["library_name: str"],
372+
"bool",
373+
)
374+
],
375+
("Py5Tools", "processing_download_library"): [
376+
(
377+
["library_name: str"],
378+
"bool",
379+
)
380+
],
357381
}
358382

359383
OPTIONAL_METHOD_SIGNATURES = {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@@ meta
2+
name = processing.check_library()
3+
type = function
4+
category = processing
5+
subcategory = None
6+
7+
@@ signatures
8+
processing_check_library(library_name: str) -> bool
9+
10+
@@ variables
11+
library_name: str - name of Processing library
12+
13+
@@ description
14+
Check if a Processing library has been downloaded and stored by py5. These are the same libraries available to you in the Library Manager when you use the Processing Development Environment (PDE). Downloaded libraries are available for you to import in Python after you import py5.
15+
16+
Downloaded libraries will be saved in the Processing library storage directory. Use [](py5tools_processing_library_storage_dir) to get the specific location of the storage directory on your machine.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@@ meta
2+
name = processing.download_library()
3+
type = function
4+
category = processing
5+
subcategory = None
6+
7+
@@ signatures
8+
processing_download_library(library_name: str) -> bool
9+
10+
@@ variables
11+
library_name: str - name of Processing library
12+
13+
@@ description
14+
Download and store a Processing library. These are the same libraries available to you in the Library Manager when you use the Processing Development Environment (PDE). After this function downloads a Processing library, it will be available for you to import in Python after you import py5.
15+
16+
Downloaded libraries will be saved in the Processing library storage directory. Use [](py5tools_processing_library_storage_dir) to get the specific location of the storage directory on your machine.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@@ meta
2+
name = processing.installed_libraries()
3+
type = function
4+
category = processing
5+
subcategory = None
6+
7+
@@ signatures
8+
processing_installed_libraries() -> list[str]
9+
10+
@@ description
11+
List the Processing libraries stored in your computer's Processing library storage directory. These are all of the Processing libraries that have been installed using the [](py5tools_processing_download_library) function. To get the location of the library storage directory, use the [](py5tools_processing_library_storage_dir) function.
12+
13+
Downloaded libraries will be saved in the Processing library storage directory. Use [](py5tools_processing_library_storage_dir) to get the specific location of the storage directory on your machine.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@@ meta
2+
name = processing.library_storage_dir()
3+
type = function
4+
category = processing
5+
subcategory = None
6+
7+
@@ signatures
8+
processing_library_storage_dir() -> Path
9+
10+
@@ description
11+
Return the location of the Processing library storage directory. You should never need to manually edit files in this directory, but if for some reason you do, you'll first need to find it. By default, this will be `~/.cache/py5` on Linux and MacOS machines and `~/AppData/Local/py5` on Windows machines. These locations are similar to where other Python libraries store their data files. If you wish, set the `PY5_HOME` environment variable to move the storage directory to a location of your choosing.
12+
13+
If you wish to add Java Jar files to py5's classpath, don't use this directory. Instead, put jars in a `jars` subdirectory (relative to the current working directory of your Python code) or set the `PY5_JARS` environment variable to the path of the directory you wish to use.

py5_resources/data/py5tools.csv

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ live_coding_screenshot,,,function,live_coding,,PYTHON,live_coding
1616
live_coding_copy_code,,,function,live_coding,,PYTHON,live_coding
1717
live_coding_snapshot,,,function,live_coding,,PYTHON,live_coding
1818
live_coding_count,,,function,live_coding,,PYTHON,live_coding
19-
live_coding_activate,,,function,live_coding,,PYTHON,live_coding
19+
live_coding_activate,,,function,live_coding,,PYTHON,live_coding
20+
processing_library_storage_dir,,,function,processing,,PYTHON,processing
21+
processing_installed_libraries,,,function,processing,,PYTHON,processing
22+
processing_check_library,,,function,processing,,PYTHON,processing
23+
processing_download_library,,,function,processing,,PYTHON,processing

py5_resources/py5_module/py5/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from jpype import JClass # noqa
4242
from jpype.types import JArray, JChar, JFloat, JInt, JString # noqa
4343
from PIL import Image # noqa
44+
from py5_tools.constants import VERSION as __version__
4445

4546
_environ = py5_tools.environ.Environment()
4647

@@ -97,6 +98,8 @@
9798

9899
# add py5 jars to the classpath first
99100
py5_tools.add_jars(str(base_path / "jars"))
101+
# add stored processing libraries
102+
py5_tools.add_jars(py5_tools.processing.library_storage_dir())
100103
# if the cwd has a jars subdirectory, add that next
101104
py5_tools.add_jars(Path("jars"))
102105
# if the PY5_JARS environment variable exists, add those jars
@@ -163,9 +166,6 @@
163166
# IPython must not be installed
164167
pass
165168

166-
167-
__version__ = "0.10.5.dev0"
168-
169169
_PY5_USE_IMPORTED_MODE = py5_tools.get_imported_mode()
170170
py5_tools._lock_imported_mode()
171171

py5_resources/py5_module/py5_tools/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
#
1919
# *****************************************************************************
2020
"""
21-
Utilities and accessory tools for py5.
21+
Utilities and accessory tools for py5.
2222
"""
2323
from . import live_coding # noqa
24+
from . import processing # noqa
2425
from . import translators # noqa
2526
from .config import * # noqa
27+
from .constants import VERSION as __version__
2628
from .hooks import * # noqa
2729
from .imported import _lock_imported_mode, get_imported_mode, set_imported_mode # noqa
2830
from .jvm import * # noqa
29-
from .libraries import * # noqa
30-
31-
__version__ = "0.10.5.dev0"
32-
3331

3432
__all__ = [
3533
"__version__",
@@ -43,6 +41,7 @@
4341
"is_jvm_running",
4442
"live_coding",
4543
"offline_frame_processing",
44+
"processing",
4645
"register_processing_mode_key",
4746
"save_frames",
4847
"screenshot",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# *****************************************************************************
2+
#
3+
# Part of the py5 library
4+
# Copyright (C) 2020-2025 Jim Schmitz
5+
#
6+
# This library is free software: you can redistribute it and/or modify it
7+
# under the terms of the GNU Lesser General Public License as published by
8+
# the Free Software Foundation, either version 2.1 of the License, or (at
9+
# your option) any later version.
10+
#
11+
# This library is distributed in the hope that it will be useful, but
12+
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14+
# General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this library. If not, see <https://www.gnu.org/licenses/>.
18+
#
19+
# *****************************************************************************
20+
import os
21+
import platform
22+
from pathlib import Path
23+
24+
VERSION = "0.10.5.dev0"
25+
PROCESSING_BUILD_NUMBER = 1292
26+
27+
if not (PY5_HOME := os.environ.get("PY5_HOME")):
28+
if platform.system() == "Windows":
29+
PY5_HOME = Path.home() / "AppData" / "Local" / "py5"
30+
else:
31+
PY5_HOME = Path.home() / ".cache" / "py5"

py5_resources/py5_module/py5_tools/environ.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# along with this library. If not, see <https://www.gnu.org/licenses/>.
1818
#
1919
# *****************************************************************************
20-
21-
2220
class Environment:
2321
def __init__(self):
2422
try:

0 commit comments

Comments
 (0)