-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d42274
commit 70ed6d8
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |