Skip to content

Commit

Permalink
Added package version validation
Browse files Browse the repository at this point in the history
EPO-8832 Added package version validation as part of login
  • Loading branch information
ericdrosas87 committed Dec 12, 2023
1 parent 22c3cbf commit 17f8b40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ build-backend = "setuptools.build_meta"

[project]
name = "rubin.citsci"
version = "0.2.3"
version = "0.2.4"
readme = "README.md"
dependencies = [
"panoptes_client",
'google.cloud.storage',
'requests',
]
24 changes: 22 additions & 2 deletions src/rubin/citsci/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv, uuid, os, shutil, json, logging, urllib.request, base64, re
import csv, uuid, os, shutil, json, logging, urllib.request, base64, re, requests
from datetime import datetime, timezone, timedelta
from IPython.display import display
from importlib.metadata import version
import google.cloud.storage as storage
import panoptes_client
from panoptes_client import Project, SubjectSet, Classification
Expand Down Expand Up @@ -62,9 +63,12 @@ def login_to_zooniverse(self, slug_name, email):
https://www.zooniverse.org/
Email address validation occurs before the login prompt is called.
Email address validation occurs before the login prompt is called and also
checks if the latest version of this package is installed.
"""

self.__check_package_version()

valid_email = self.__validate_email_address(email)

if(valid_email):
Expand All @@ -78,6 +82,22 @@ def login_to_zooniverse(self, slug_name, email):
print("Invalid email address! Please check the email address you provided and ensure it is correct.")
return

def __check_package_version():
try:
installed_version = version('rubin.citsci')
res = requests.get('https://pypi.org/simple/rubin-citsci/', headers = {"Accept": "application/vnd.pypi.simple.v1+json"})
res_json = json.loads(res.content.decode('utf-8'))
latest_version = res_json["versions"][-1]

if (installed_version == latest_version) is False:
print("WARNING! : You currently have v" + installed_version + " of this package installed, but v" + latest_version + " is available.")
print("To install the latest version, open up a terminal tab and run the following command:")
print(" pip install --upgrade --force-reinstall rubin.citsci")
print("After the upgrade installation has finished, please restart the kernel for the changes to take effect.")
except Exception as e:
print("ERROR! : An error occurred while attempting to validate that the latest version of the rubin.citsci package is installed. Please notify the EPO citizen science team that this error message has occurred!")
return

def __validate_email_address(email):
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
if re.fullmatch(regex, email):
Expand Down

0 comments on commit 17f8b40

Please sign in to comment.