From faff0011b4f9b3add81722efe0947cf48613cb8d Mon Sep 17 00:00:00 2001
From: Jakob Fritz <j.fritz@fz-juelich.de>
Date: Thu, 30 Nov 2023 10:39:49 +0100
Subject: [PATCH] Tried to get automatic check to work

But did not succeed. Checking itself somewhat works
(only for github and gitlab.com; this has to be extended)
But passing back the variables does not work at the moment.
---
 public/check-requirements.html   |  1 +
 public/check-requirements.json   |  2 +-
 public/check-requirements.py     | 38 ++++++++++++++++++++++---
 src/pages/check-requirements.vue | 49 +++++++-------------------------
 4 files changed, 46 insertions(+), 44 deletions(-)

diff --git a/public/check-requirements.html b/public/check-requirements.html
index ef04f8a..a70c88d 100644
--- a/public/check-requirements.html
+++ b/public/check-requirements.html
@@ -25,6 +25,7 @@ SPDX-License-Identifier: MIT
         type="module"
         src="https://pyscript.net/releases/2023.11.1/core.js"
     ></script>
+    <script src="https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>
   </head>
 
   <body>
diff --git a/public/check-requirements.json b/public/check-requirements.json
index e937592..5781f06 100644
--- a/public/check-requirements.json
+++ b/public/check-requirements.json
@@ -1,3 +1,3 @@
 {
-    "packages": ["arrr"]
+    "packages": ["pyodide_http", "http://localhost:8080/howfairis-0.14.2-py3-none-any.whl", "http://localhost:8080/ratelimit-2.2.1-py3-none-any.whl", "voluptuous"]
 }
diff --git a/public/check-requirements.py b/public/check-requirements.py
index c3dd2ef..5790616 100644
--- a/public/check-requirements.py
+++ b/public/check-requirements.py
@@ -1,18 +1,48 @@
-from pyscript import when, document
+from pyscript import when, document, window
+import pyodide_http
+import sys
+import voluptuous
+from howfairis import Repo, Checker
 from js import console
 
+pyodide_http.patch_all()
+
 @when("submit", "#categoryForm")
 def trigger_check(data):
     # gitURL = data.repoURL
     console.log("trigger_check was called")
     console.log(data)
+    applicationClass = int(document.getElementById("applicationClassSlider").value)
+    console.log(applicationClass)
+    gitURL = document.getElementById("repoURL").value
+    console.log(gitURL)
+    console.log(document)
+    console.log(f"Python version: {sys.version_info}")
+    console.log(f"Volutptuous version: {voluptuous.__version__}")
+    console.log(f"Pyodide_http version: {pyodide_http.__version__}")
+
+    # url = "https://github.com/fair-software/howfairis"
+    # repo = Repo(url)
+    # checker = Checker(repo, is_quiet=False)
+    # repo_valid = checker.check_repository()
+    # console.log(f"Repo is checked and valid: {repo_valid}")
+    
+    existing_git(gitURL)
+
+    # Cannot access the JS-variable "allStandards"
+    # and therefore not report back the results of the tests
+
+    # allStd = document.getElementsByName("allStandards")
+    # console.log(allStd)
+    # allStandards.value.versionControl.fulfilled = True
+    # allStandards.value.versionControl.automaticallyChecked = True
     # if data.applicationClass >= 1:
     #     existing_git(gitURL=gitURL)
 
 
-# @when("triggerExistingGit", "#checkRequirements")
+# @when("triggerExistingGit", "#categoryForm")
 def existing_git(gitURL):
     console.log("existing_git was called")
     console.log(gitURL)
-    document.allStandards.value.versionControl.fulfilled = True
-    document.allStandards.value.versionControl.automaticallyChecked = True
+    window.document.allStandards.value.versionControl.fulfilled = True
+    window.document.allStandards.value.versionControl.automaticallyChecked = True
diff --git a/src/pages/check-requirements.vue b/src/pages/check-requirements.vue
index 38dae34..a9b97af 100644
--- a/src/pages/check-requirements.vue
+++ b/src/pages/check-requirements.vue
@@ -13,19 +13,18 @@ SPDX-License-Identifier: MIT
       v-model="category"
       type="form"
       :actions="true"
-      @submit="triggerCheck"
-      submit-label='Check'
+      submit-label="Automatically check some requirements"
       :submit-attr="{
-        help: 'Automatically check some requirements',
         'py-click': 'trigger_check'
       }"
+      @submit="triggerCheck"
     >
       <FormKit
+        id="applicationClassSlider"
         type="range"
         label="Application class of the software"
         help="If you don't know the application class, see the links above to determine it (by table or by decision tree)"
         name="applicationClass"
-        id="applicationClassSlider"
         number="integer"
         validation="required"
         min="0"
@@ -40,7 +39,7 @@ SPDX-License-Identifier: MIT
         Your chosen application class is {{ category.applicationClass }}
       </p>
       <FormKit
-        v-if="category.applicationClass>0"
+        id="repoURL"
         type="text"
         label="URL of the git-repository"
         name="repoURL"
@@ -49,21 +48,7 @@ SPDX-License-Identifier: MIT
           required: 'URL is required if automatic check shall be used.',
           url: 'A valid URL is required for automatic check to work.'
         }"
-
       />
-
-      <!-- <FormKit
-        v-if="category.applicationClass>0"
-        class="formkit-input"
-        type="submit"
-        name="check_category"
-        id=""
-        :disabled="disabled"
-        help="Automatically check some requirements"
-        label="Check python"
-        py-click="trigger_check"
-        @click="unused"
-      /> -->
     </FormKit>
 
     <FormKit
@@ -147,31 +132,17 @@ import CreateBadge from '@/components/createBadge.vue'
 import { FormKit } from '@formkit/vue'
 import { ref } from 'vue'
 import printJS from 'print-js'
-// import * as allStandards from '@/components/standards.json'
-// const triggerExistingGit = (allStandards, gitURL) => emit('existingGit', allStandards, gitURL);
 </script>
 
 <script>
 const getStandards = () => {
-  let standards = require('@/components/standards.json')
-      for (const [key, ] of Object.entries(standards)) {
-        standards[key]['automaticallyChecked'] = false,
-        standards[key]['fulfilled'] = false
-      }
-      return standards
+    let standards = require('@/components/standards.json')
+    for (const [key, ] of Object.entries(standards)) {
+      standards[key]['automaticallyChecked'] = false,
+      standards[key]['fulfilled'] = false
+    }
+    return standards
 }
-// const triggerCheck = (data)  => {
-//       const gitURL = data.repoURL
-//       if (data.applicationClass >= 1) {
-//         console.log(gitURL);
-//         // check versionControl
-//         emit('existingGit', {allStandards, gitURL});
-//         console.log("Triggered python");
-//         // allStandards.value.versionControl.fulfilled = validGit(gitURL);
-//         // allStandards.value.versionControl.automaticallyChecked = true;
-//         console.log(allStandards.value.versionControl.automaticallyChecked)
-//       }
-//     }
 var allStandards = ref(getStandards())
 const category = ref({})
 var requiredStandards = ref({})
-- 
GitLab