Skip to content

Commit

Permalink
Merge develop into master (#161)
Browse files Browse the repository at this point in the history
* Hotfix/conditional deps (#154)

* hotfix: conditional requirement for python<3.9

* conditional depedency added

* bump version

* silly mistake not calling get on the env vars

* update changelog

* updating for minor version bump

* removed unnecessary Dockerfile
  • Loading branch information
Bee-Mar authored Jan 8, 2024
1 parent f432346 commit efc79cc
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ htmlcov
.idea
mmpm/ui
.pdm-python
mmpm/ui
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,11 @@
## Version 4.0.4

- hotfix of calling get on env vars

## Version 4.1.0

- removed extra log messages to reduce log pollution
- changed casing of function names in UI to conform to camelCasing
- using appropriate interpreter based on environment in ecosystem.json
- removed custom package directory extension to prevent naming issues in config.json
- removed multi-threading options from gunicorn servers
4 changes: 2 additions & 2 deletions mmpm/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
major = 4
minor = 0
patch = 4
minor = 1
patch = 0

version = f"{major}.{minor}.{patch}"
26 changes: 16 additions & 10 deletions mmpm/api/endpoints/ep_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ def remove() -> Response:
failure = []

for package in packages:
if MagicMirrorPackage(**package).remove():
logger.debug(f"Removed {package['title']}")
pkg = MagicMirrorPackage(**package)

if pkg.remove():
logger.debug(f"Removed {pkg.title}")
success.append(package)
else: # honestly, this should never fail anyway
logger.debug(f"Failed to remove {package['title']}")
logger.debug(f"Failed to remove {pkg.title}")
failure.append(package)

return self.success({"success": success, "failure": failure})
Expand All @@ -128,11 +130,13 @@ def upgrade() -> Response:
failure = []

for package in packages:
if MagicMirrorPackage(**package).upgrade():
logger.debug(f"Upgraded {package['title']}")
pkg = MagicMirrorPackage(**package)

if pkg.upgrade():
logger.debug(f"Upgraded {pkg.title}")
success.append(package)
else:
logger.debug(f"Failed to upgrade {package['title']}")
logger.debug(f"Failed to upgrade {pkg.title}")
failure.append(package)

return self.success({"success": success, "failure": failure})
Expand Down Expand Up @@ -168,15 +172,17 @@ def remove_mm_pkg() -> Response:
Response: A Flask Response object containing the status of each custom package removal attempt.
"""

packages = [MagicMirrorPackage(**pkg) for pkg in request.get_json()["packages"]]
packages = request.get_json()["packages"]
success = []
failure = []

for package in packages:
if self.db.remove_mm_pkg(package.title):
success.append(package.serialize(full=True))
pkg = MagicMirrorPackage(**package)

if self.db.remove_mm_pkg(pkg.title):
success.append(package)
else:
failure.append(package.serialize(full=True))
failure.append(package)

return self.success({"success": success, "failure": failure})

Expand Down
7 changes: 3 additions & 4 deletions mmpm/api/repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ def setup_mm_client():
attempt = 0
max_retries = 250

logger.debug("Attempting to connect to MagicMirror SocketIO server. Using a maximum of 250 retries")

while attempt < max_retries and not mm_client.connected:
try:
mm_client.connect(env.MMPM_MAGICMIRROR_URI.get(), wait_timeout=10, wait=True)

logger.debug("Successfully connected to the MagicMirror SocketIO server")
break # Connection successful, break out of the loop
except Exception as error:
logger.error(error)
logger.error(f"Connection failed on attempt ({attempt+1}/{max_retries}). Retrying.")
except Exception:
attempt += 1
sleep(1)

Expand Down
10 changes: 5 additions & 5 deletions mmpm/magicmirror/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def __download_packages__(self) -> List[MagicMirrorPackage]:
table_soup = soup.find_all("table")
categories_soup = soup.find_all(attrs={"class": "markdown-body"})[0].find_all("h3")

categories = []
self.categories = []

for category in categories_soup[2:]:
if hasattr(category, "contents"):
if hasattr(category.contents, "contents"):
categories.append(category.contents[-1].contents[0])
self.categories.append(category.contents[-1].contents[0])
else:
categories.append(category.contents[-1])
self.categories.append(category.contents[-1])

# the first index is a row that literally says 'Title' 'Author' 'Description'
tr_soup: list = [table.find_all("tr")[1:] for table in table_soup]
Expand All @@ -73,7 +73,7 @@ def __download_packages__(self) -> List[MagicMirrorPackage]:
if not table_data or not table_data[0].text or table_data[0].text == "mmpm":
continue

pkg = MagicMirrorPackage.from_raw_data(table_data, category=categories[index])
pkg = MagicMirrorPackage.from_raw_data(table_data, category=self.categories[index])
packages.append(pkg)

except Exception as error: # broad exception isn't best, but there's a lot that can happen here
Expand Down Expand Up @@ -357,7 +357,7 @@ def add_mm_pkg(self, title: str, author: str, repository: str, description: str
category="Custom Packages",
)

package.directory = Path(f'{package.repository.split("/")[-1].replace(".git", "")}-ext-mm-pkg')
package.directory = Path(package.repository.split("/")[-1].replace(".git", ""))

try:
ext_pkgs_file = paths.MMPM_CUSTOM_PACKAGES_FILE
Expand Down
32 changes: 16 additions & 16 deletions mmpm/magicmirror/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ class InstallationHandler:
def __init__(self, package: MagicMirrorPackage):
self.package = package

def execute(self, funk: Callable) -> bool:
def exec(self, funk: Callable) -> bool:
logger.debug(f"Calling exec wrapper to install dependencies for '{self.package.title}'")
error_code, _, stderr = funk()

if error_code:
Expand Down Expand Up @@ -369,32 +370,31 @@ def install(self) -> bool:
return False

os.chdir(modules_dir)
error_code = 0

if not self.package.directory.exists():
self.package.directory.mkdir(exist_ok=True)
if not (self.package.directory / ".git").exists():
logger.debug(f"{self.package.directory / '.git'} not found. Cloning repo.")
error_code, _, stderr = self.package.clone()

os.chdir(self.package.directory)
if error_code:
logger.error(f"Failed to clone {self.package.title}: {stderr}")
return False

if error_code:
logger.error(f"Failed to clone {self.package.title}: {stderr}")
return False
os.chdir(self.package.directory)

elif self.exists("package.json"):
return self.execute(self.npm_install)
if self.exists("package.json"):
return self.exec(self.npm_install)
elif self.exists("Gemfile"):
return self.execute(self.bundle_install)
return self.exec(self.bundle_install)
elif self.exists("Makefile"):
return self.execute(self.make)
return self.exec(self.make)
elif self.exists("CMakeLists.txt"):
return self.execute(self.cmake)
return self.exec(self.cmake)
elif self.exists("requirements.txt"):
return self.execute(self.pip_install)
return self.exec(self.pip_install)
elif self.exists("pom.xml"):
return self.execute(self.maven_install)
return self.exec(self.maven_install)
elif self.exists("go.mod"):
return self.execute(self.go_build)
return self.exec(self.go_build)

logger.debug(f"Unable to find any dependency file associated with {self.package.title}")
return True
Expand Down
2 changes: 2 additions & 0 deletions mmpm/subcommands/_sub_cmd_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def exec(self, args, extra):
logger.error("Failed to remove MMPM UI")
self.ui.delete()

sleep(2)

if not self.ui.install():
logger.error("Failed to install MMPM UI")
self.ui.delete()
Expand Down
29 changes: 16 additions & 13 deletions mmpm/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,38 @@ class MMPMui(Singleton):
"""

def __init__(self):
self.pm2_config_path = Path("/tmp/mmpm/ecosystem.json")
# make sure we have the right python environment
python = shutil.which("python")
namespace = "mmpm"

self.pm2_config_path = Path("/tmp/mmpm/ecosystem.json")
self.pm2_ecosystem_config = {
"apps": [
{
"namespace": "mmpm",
"name": "mmpm.api",
"script": f"python3 -m gunicorn -k gevent -b 0.0.0.0:{urls.MMPM_API_SERVER_PORT} mmpm.wsgi:app",
"namespace": namespace,
"name": f"{namespace}.api",
"script": f"{python} -m gunicorn -k gevent -b 0.0.0.0:{urls.MMPM_API_SERVER_PORT} mmpm.wsgi:app",
"version": version,
"watch": True,
},
{
"namespace": "mmpm",
"name": "mmpm.log-server",
"script": f"python3 -m gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 'mmpm.log.server:create()' -b 0.0.0.0:{urls.MMPM_LOG_SERVER_PORT}",
"namespace": namespace,
"name": f"{namespace}.log-server",
"script": f"{python} -m gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 'mmpm.log.server:create()' -b 0.0.0.0:{urls.MMPM_LOG_SERVER_PORT}",
"version": version,
"watch": True,
},
{
"namespace": "mmpm",
"name": "mmpm.repeater",
"script": f"python3 -m gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 'mmpm.api.repeater:create()' -b 0.0.0.0:{urls.MMPM_REPEATER_SERVER_PORT}",
"namespace": namespace,
"name": f"{namespace}.repeater",
"script": f"{python} -m gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 'mmpm.api.repeater:create()' -b 0.0.0.0:{urls.MMPM_REPEATER_SERVER_PORT}",
"version": version,
"watch": True,
},
{
"namespace": "mmpm",
"name": "mmpm.ui",
"script": f"python3 -m http.server -d {pkg_resources.files('mmpm').resolve() / 'ui'} -b 0.0.0.0 {urls.MMPM_UI_PORT}",
"namespace": namespace,
"name": f"{namespace}.ui",
"script": f"{python} -m http.server -d {pkg_resources.files('mmpm').resolve() / 'ui'} -b 0.0.0.0 {urls.MMPM_UI_PORT}",
"version": version,
"watch": True,
},
Expand Down
2 changes: 1 addition & 1 deletion mmpm/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

if __name__ == "__main__":
app.run(
threaded=True,
threaded=False,
keepalive=True,
log=logger,
extra_files=[
Expand Down
Loading

0 comments on commit efc79cc

Please sign in to comment.