From 7d4470277555ee39ffc0bae2e062a40c20f3c53f Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 19 Dec 2020 19:56:27 +0100 Subject: [PATCH 1/5] Add .editorconfig --- .editorconfig | 21 +++++++++++++++++++++ .gitignore | 1 + 2 files changed, 22 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0f4b35f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# see http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.py] +line_length = 119 + +[{Makefile,**.mk}] +indent_style = tab +insert_final_newline = false + +[*.yml] +indent_style = tab +indent_size = 4 diff --git a/.gitignore b/.gitignore index 145be6a..a7c2f58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .* !.github +!.editorconfig !.gitignore __pycache__ secret.txt From 12a5adab54c53e24deb7f25ec8e03992989e9991 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 19 Dec 2020 20:06:07 +0100 Subject: [PATCH 2/5] bugfix import "local_settings.py" --- conf/ynh_pyinventory_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/ynh_pyinventory_settings.py b/conf/ynh_pyinventory_settings.py index cfc0b79..1eb9104 100644 --- a/conf/ynh_pyinventory_settings.py +++ b/conf/ynh_pyinventory_settings.py @@ -188,6 +188,6 @@ LOGGING = { # ----------------------------------------------------------------------------- try: - from .local_settings import * # noqa + from local_settings import * # noqa except ImportError: pass From a4b04d118651ff7cba25fc08035e86a3f29ce15e Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 19 Dec 2020 20:16:49 +0100 Subject: [PATCH 3/5] Set Django dbbackup path to /opt/yunohost/$app/backups/ --- conf/ynh_pyinventory_settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conf/ynh_pyinventory_settings.py b/conf/ynh_pyinventory_settings.py index 1eb9104..73cd39e 100644 --- a/conf/ynh_pyinventory_settings.py +++ b/conf/ynh_pyinventory_settings.py @@ -150,6 +150,11 @@ MEDIA_ROOT = str(FINAL_WWW_PATH / 'media') CKEDITOR_BASEPATH = STATIC_URL + 'ckeditor/ckeditor/' +# _____________________________________________________________________________ +# Django-dbbackup + +DBBACKUP_STORAGE_OPTIONS['location']=str(FINAL_HOME_PATH / 'backups') + # ----------------------------------------------------------------------------- LOGGING = { From 4206f55b36c06124025c56799606ac39e6a28827 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 19 Dec 2020 20:17:57 +0100 Subject: [PATCH 4/5] Just define own urls.py so we also support settings.SERVE_FILES here, too. And this removes one warnings about duplicate namespaces. --- conf/ynh_urls.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/conf/ynh_urls.py b/conf/ynh_urls.py index 57a7f7c..eef81a2 100644 --- a/conf/ynh_urls.py +++ b/conf/ynh_urls.py @@ -1,16 +1,25 @@ from django.conf import settings -from django.conf.urls import include +from django.conf.urls import include, static +from django.contrib import admin from django.urls import path +from django.views.generic import RedirectView # settings.PATH_URL is the $YNH_APP_ARG_PATH if settings.PATH_URL: + # Prefix all urls with "PATH_URL": urlpatterns = [ - # XXX: Hack - the MEDIA_URL contains the "PATH_URL" already: - path(settings.MEDIA_URL.lstrip('/'), include('django_tools.serve_media_app.urls')), + path(f'{settings.PATH_URL}/admin/', admin.site.urls), - # Prefix all urls with "PATH_URL": - path(f'{settings.PATH_URL}/', include('inventory_project.urls')) + path(f'{settings.PATH_URL}/', RedirectView.as_view(pattern_name='admin:index')), + + path(f'{settings.PATH_URL}/ckeditor/', include('ckeditor_uploader.urls')), + + # MEDIA_URL contains the "PATH_URL" already: + path(settings.MEDIA_URL.lstrip('/'), include('django_tools.serve_media_app.urls')), ] + if settings.SERVE_FILES: + urlpatterns += static.static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) else: - # Installed to domain root, without a path prefix? + # Installed to domain root, without a path prefix + # Just use the default project urls.py from inventory_project.urls import urlpatterns # noqa From 0995215fd26dbddf1d543aeadfdf928ffe765744 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 19 Dec 2020 20:19:06 +0100 Subject: [PATCH 5/5] Use poetry to run local_test.py So we get django-auth-ldap installed. Also add a Makefile for easier usage. --- .gitignore | 1 + Makefile | 37 +++++++++++++++++++++++++++++++++++++ README.md | 24 +++++++++++------------- local_test.py | 4 ++++ manifest.json | 2 +- pyproject.toml | 17 +++++++++++++++++ 6 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 Makefile create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index a7c2f58..d18d5cc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ secret.txt /local_test/ +/poetry.lock diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4bec259 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +SHELL := /bin/bash + +all: help + +help: + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -]+:.*?## / {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +check-poetry: + @if [[ "$(shell poetry --version 2>/dev/null)" == *"Poetry"* ]] ; \ + then \ + echo "Poetry found, ok." ; \ + else \ + echo 'Please install poetry first, with e.g.:' ; \ + echo 'make install-poetry' ; \ + exit 1 ; \ + fi + +install-poetry: ## install or update poetry + pip3 install -U poetry + +install: check-poetry ## install PyInventory via poetry + sudo apt install python3-ldap libldap2-dev libsasl2-dev + poetry install + +update: install-poetry ## update the sources and installation + poetry update + +local-test: check-poetry ## Run local_test.py to run pyinventory_ynh locally + poetry run ./local_test.py + +local-diff-settings: ## Run "manage.py diffsettings" with local test + poetry run python3 local_test/opt_yunohost/manage.py diffsettings + + +############################################################################## + +.PHONY: help check-poetry install-poetry install update local-test \ No newline at end of file diff --git a/README.md b/README.md index 3216318..518731d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # PyInventory for YunoHost -[![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg) [![Install PyInventory with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=pyinventory) -> *This package allows you to install PyInventory quickly and simply on a YunoHost server. +> *This package allows you to install PyInventory quickly and simply on a YunoHost server. If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* Pull requests welcome ;) @@ -106,20 +106,18 @@ For quicker developing of PyInventory in the context of YunoHost app, it's possible to run the Django developer server with the settings and urls made for YunoHost installation. -For this, just run `local_test.py` in a PyInventory virtualenv. - e.g.: ```bash -~$ git clone https://github.com/jedie/PyInventory.git ~$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git -~$ cd PyInventory/ -~/PyInventory$ make install -~/PyInventory$ poetry shell -(pyinventory-yd_5sxYx-py3.8) ~/PyInventory$ cd ../pyinventory_ynh/ -(pyinventory-yd_5sxYx-py3.8) ~/pyinventory_ynh$ ./local_test.py -... -Django version 2.2.17, using settings 'ynh_pyinventory_settings' -Starting development server at http://127.0.0.1:8000/ +~$ cd pyinventory_ynh/ +~/pyinventory_ynh$ make +install-poetry install or update poetry +install install PyInventory via poetry +update update the sources and installation +local-test Run local_test.py to run pyinventory_ynh locally +~/pyinventory_ynh$ make install-poetry +~/pyinventory_ynh$ make install +~/pyinventory_ynh$ make local-test ``` Notes: diff --git a/local_test.py b/local_test.py index fe38671..3430c3f 100755 --- a/local_test.py +++ b/local_test.py @@ -130,6 +130,10 @@ def main(): # conf/ynh_urls.py -> local_test/ynh_urls.py copy_patch(src_file=URLS_FILE, replaces=REPLACES) + with Path(FINAL_HOME_PATH / 'local_settings.py').open('w') as f: + f.write('# Only for local test run\n') + f.write('SERVE_FILES=True # used in src/inventory_project/urls.py\n') + # call "local_test/manage.py" via subprocess: call_manage_py('check --deploy') call_manage_py('migrate --no-input') diff --git a/manifest.json b/manifest.json index 081d7f7..35f4dee 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Web based management to catalog things including state and location etc." }, - "version": "0.8.1~ynh6", + "version": "0.8.1~ynh7", "url": "https://github.com/jedie/PyInventory", "license": "GPL-3.0", "maintainer": { diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..00b4c2b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "pyinventory_ynh" +version = "0.8.1~ynh7" +description = "Test pyinventory_ynh via local_test.py" +authors = ["JensDiemer "] +license = "GPL" + +[tool.poetry.dependencies] +python = ">=3.7,<4.0.0" +pyinventory = "*" +django-auth-ldap = "*" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api"