Skip to content

Commit

Permalink
#1 Add version validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
KaoruNishikawa committed May 12, 2022
1 parent 1d42274 commit 70ed6d8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def _import_dependencies():
from poetry.core.version import pep440
from poetry.core.version.exceptions import InvalidVersion
return pep440, InvalidVersion

async def import_dependencies():
try:
return _import_dependencies()
except ImportError:
import micropip
await micropip.install(["poetry==1.2.0b1"])
return _import_dependencies()


class PEP440:
def __init__(self):
pass

async def validate_version(self, version):
pep440, InvalidVersion = await import_dependencies()
try:
pep440.PEP440Version.parse(version)
return True
except InvalidVersion:
return False


async def test_version(event):
version = Element("version-to-test").element.value
is_valid = await PEP440().validate_version(version)
pyscript.write(
"version-test-result",
f"{version} is" + (" " if is_valid else " not ") + "valid version",
)

async def main():
_ = await import_dependencies()

from js import document
document.getElementById("loading").style.display = "none"

import asyncio
loop = asyncio.get_event_loop()
_ = loop.run_until_complete(main())

0 comments on commit 70ed6d8

Please sign in to comment.