Skip to content

Commit ede1311

Browse files
committed
update to sync with local changes
1 parent 5df80d2 commit ede1311

File tree

3 files changed

+86
-27
lines changed

3 files changed

+86
-27
lines changed

Diff for: .github/workflows/build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ jobs:
173173
linux/amd64
174174
linux/arm/v7
175175
linux/arm64
176-
linux/386
177176
push: ${{ github.event_name != 'pull_request' }}
178177
tags: |
179178
${{ env.GHCR_SLUG }}:pylav

Diff for: Dockerfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ RUN set -eux; \
6464
# CrabRave
6565
ffmpeg \
6666
imagemagick \
67-
# RSS (SciPy has no wheels for armv7)
68-
$([ "$(uname --machine)" = "armv7l" ] && echo "gfortran libopenblas-dev liblapack-dev") \
67+
# RSS \
68+
gfortran \
69+
libopenblas-dev \
70+
liblapack-dev \
6971
# ReTrigger
7072
tesseract-ocr \
7173
; \
@@ -148,7 +150,7 @@ CMD ["/app/start-redbot.sh"]
148150

149151
#######################################################################################
150152

151-
FROM core-build as core-pylav-build
153+
FROM core-audio-build as core-pylav-build
152154

153155
RUN set -eux; \
154156
# Install pylav dependencies
@@ -180,7 +182,7 @@ CMD ["/app/start-redbot.sh"]
180182

181183
#######################################################################################
182184

183-
FROM extra-build as extra-pylav-build
185+
FROM extra-audio-build as extra-pylav-build
184186

185187
RUN set -eux; \
186188
# Install pylav dependencies

Diff for: root/app/functions/pylav_setup.py

+80-22
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
import subprocess
66
import sys
77
import json
8-
from typing import Set, Dict, Union
8+
from typing import Set, Dict, Union, Any
99

1010
RepoManagerSetting = pathlib.Path("/data/cogs/RepoManager/settings.json")
1111
DownloaderSetting = pathlib.Path("/data/cogs/Downloader/settings.json")
1212
DownloaderLibFolder = pathlib.Path("/data/cogs/Downloader/lib")
1313
RepoManagerRepoFolder = pathlib.Path("/data/cogs/RepoManager/repos/pylav")
1414
CogManagerCogFolder = pathlib.Path("/data/cogs/CogManager/cogs")
1515
CogRepoURL = "https://github.com/PyLav/Red-Cogs"
16-
PyLavHashFile = pathlib.Path("/data/pylav/.hashfile")
16+
PyLavHashFile = pathlib.Path("/pylav/.hashfile")
1717

1818
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)5s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
1919

2020
log = logging.getLogger("PyLavSetup")
2121

22-
STORAGE_TYPE = os.environ.get("STORAGE_TYPE")
2322

24-
if not STORAGE_TYPE:
25-
with pathlib.Path("/data/config.json").open("r", encoding="utf-8") as __f:
26-
STORAGE_TYPE = json.load(__f)["docker"]["STORAGE_TYPE"]
23+
DEV_PYLAV = os.environ.get("PYLAV__DEV_LIB")
24+
DEV_PYLAV_COGS = os.environ.get("PYLAV__DEV_COG")
2725

2826

29-
IS_JSON = STORAGE_TYPE.upper() == "JSON"
27+
with pathlib.Path("/data/config.json").open("r", encoding="utf-8") as __f:
28+
IS_JSON = json.load(__f)["docker"]["STORAGE_TYPE"].upper() == "JSON"
29+
3030

3131
if not IS_JSON:
32-
RepoManagerRepoFolder = pathlib.Path("/data/pylav/cogs")
32+
RepoManagerRepoFolder = pathlib.Path("/pylav/git-cogs")
3333

3434

3535
def get_git_env() -> Dict[str, str]:
@@ -84,11 +84,20 @@ def clone_or_update_pylav_repo() -> str:
8484

8585

8686
def get_pylav_cogs() -> Dict[str, pathlib.Path]:
87-
return {
88-
cog.name: cog
89-
for cog in RepoManagerRepoFolder.iterdir()
90-
if cog.is_dir() and (cog.name.startswith("pl") or cog.name == "audio")
91-
}
87+
88+
return (
89+
{
90+
cog.name: cog
91+
for cog in RepoManagerRepoFolder.iterdir()
92+
if cog.is_dir() and (cog.name.startswith("pl") or cog.name == "audio")
93+
}
94+
if not DEV_PYLAV_COGS
95+
else {
96+
cog.name: cog
97+
for cog in pathlib.Path(DEV_PYLAV_COGS).iterdir()
98+
if cog.is_dir() and (cog.name.startswith("pl") or cog.name == "audio")
99+
}
100+
)
92101

93102

94103
def copy_and_overwrite(from_path: Union[str, os.PathLike[str]], to_path: Union[str, os.PathLike[str]]) -> None:
@@ -111,11 +120,20 @@ def get_requirements_for_all_cogs(cogs: Dict[str, pathlib.Path]) -> Set[str]:
111120
data = json.load(f)
112121
if "requirements" in data:
113122
for req in data["requirements"]:
123+
if DEV_PYLAV and req.startswith("Py-Lav"):
124+
continue
114125
requirements.add(req)
115126
return requirements
116127

117128

118-
def install_requirements(cogs: Dict[str, pathlib.Path]) -> None | subprocess.Popen[str]:
129+
def install_requirements(
130+
cogs: Dict[str, pathlib.Path]
131+
) -> tuple[
132+
subprocess.Popen[str] | subprocess.Popen[str | bytes | Any] | None,
133+
subprocess.Popen[str] | subprocess.Popen[str | bytes | Any] | None,
134+
]:
135+
proc = None
136+
proc2 = None
119137
if requirements := get_requirements_for_all_cogs(cogs):
120138
log.info("Installing requirements: %s", requirements)
121139
proc = subprocess.Popen(
@@ -143,8 +161,38 @@ def install_requirements(cogs: Dict[str, pathlib.Path]) -> None | subprocess.Pop
143161
log.info(line.strip("\n"))
144162
if line.startswith("Successfully installed"):
145163
break
146-
return proc
164+
165+
if DEV_PYLAV:
166+
log.info("Installing editable PyLav")
167+
proc2 = subprocess.Popen(
168+
[
169+
"/data/venv/bin/pip",
170+
"install",
171+
"--upgrade",
172+
"--no-input",
173+
"--no-warn-conflicts",
174+
"--require-virtualenv",
175+
"--upgrade-strategy",
176+
"eager",
177+
"--target",
178+
DownloaderLibFolder,
179+
"--editable",
180+
".[all]",
181+
],
182+
cwd=DEV_PYLAV,
183+
env=get_git_env(),
184+
stdout=subprocess.PIPE,
185+
universal_newlines=True,
186+
)
187+
while True:
188+
line = proc2.stdout.readline()
189+
if not line:
190+
break
191+
log.info(line.strip("\n"))
192+
if line.startswith("Successfully installed"):
193+
break
147194
log.info("Requirements installed")
195+
return proc, proc2
148196

149197

150198
def generate_updated_downloader_setting(
@@ -181,32 +229,42 @@ def update_existing_commit(commit_hash: str) -> None:
181229
for folder in (DownloaderLibFolder, RepoManagerRepoFolder, CogManagerCogFolder):
182230
if not folder.exists():
183231
folder.mkdir(parents=True, mode=0o776)
184-
current_commit = clone_or_update_pylav_repo()
185-
existing_commit = get_existing_commit()
232+
if not DEV_PYLAV_COGS:
233+
current_commit = clone_or_update_pylav_repo()
234+
existing_commit = get_existing_commit()
235+
else:
236+
current_commit = 1
237+
existing_commit = 0
186238
cogs_mapping = get_pylav_cogs()
187239
if current_commit == existing_commit:
188240
log.info("PyLav is up to date")
189241
sys.exit(0)
190242
else:
191-
if IS_JSON:
192-
install_or_update_pylav_cogs(cogs_mapping)
193-
process = install_requirements(cogs_mapping)
243+
install_or_update_pylav_cogs(cogs_mapping)
244+
process, process2 = install_requirements(cogs_mapping)
194245
try:
195246
log.info("Current PyLav-Cogs Commit: %s", current_commit)
196247
downloader_data = generate_updated_downloader_setting(cogs_mapping, current_commit)
197-
log.info("Updated Downloader Data: %s", downloader_data)
198248
if IS_JSON:
249+
log.info("Updating Downloader Data: %s", downloader_data)
199250
create_or_update_downloader_setting(downloader_data)
200251
create_or_update_repo_manager_setting()
201-
update_existing_commit(current_commit)
252+
if not DEV_PYLAV_COGS:
253+
update_existing_commit(current_commit)
202254
if process is not None:
203255
log.info("Waiting for requirements to finish installing")
204256
process.wait()
257+
if process2 is not None:
258+
log.info("Waiting for PyLav to finish installing")
259+
process2.wait()
205260
log.info("PyLav setup and update finished")
206261
except Exception as e:
207262
log.info("PyLav setup and update failed: %s", e, exc_info=e)
208263
finally:
209264
if process is not None:
210265
process.kill()
211266
process.terminate()
267+
if process2 is not None:
268+
process2.kill()
269+
process2.terminate()
212270
sys.exit(0)

0 commit comments

Comments
 (0)