Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more informative exception handling in: import_py3package_from_pypi.py #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Utility/Python/import_py3package_from_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
def extract_and_compare_version(url, min_req_version):
try:
re.search('\d+(\.\d+)+', url).group(0)
except :
print ("Failed to extract and compare version URL %s min_req_versionor %s" % (url, min_req_version))
except Exception as e:
print ("Failed to extract and compare version URL %s min_req_versionor %s" % (url, min_req_version))
print ("Error: %s" % str(e))

extracted_ver = re.search('\d+(\.\d+)+', url).group(0)
print ("Extracted version %s min_req_versionor %s" % (extracted_ver, min_req_version))
Expand Down Expand Up @@ -82,7 +83,11 @@ def resolve_download_url(packagename, version):
for url in urls:
if 'py3-none-any.whl' in url and extract_and_compare_version(url,version):
print ("Detected download uri %s for %s" % (url, packagename))
return(url)
return(url)
for url in urls:
if 'cp38-none-win_amd64.whl' in url and version in url:
print ("Detected download uri %s for %s" % (url, packagename))
return(url)
print("Could not find WHL from PIPI for package %s and version %s" % (packagename, version))

def send_webservice_import_module_request(packagename, download_uri_for_file):
Expand All @@ -92,7 +97,9 @@ def send_webservice_import_module_request(packagename, download_uri_for_file):
requestbody = { 'properties': { 'description': 'uploaded via automation', 'contentLink': {'uri': "%s" % download_uri_for_file} } }
headers = {'Content-Type' : 'application/json', 'Authorization' : 'Bearer %s' % token}
r = requests.put(request_url, data=json.dumps(requestbody), headers=headers)
if str(r.status_code) not in ["200", "201"]:
if str(r.status_code) == "403":
raise Exception("Error 403 importing package {0} into Automation account. Did you assign the necessary write permission? (Microsoft.Automation/automationAccounts/python3Packages/write)".format(packagename))
elif str(r.status_code) not in ["200", "201"]:
raise Exception("Error importing package {0} into Automation account. Error code is {1}".format(packagename, str(r.status_code)))

def find_and_dependencies(packagename, version, dep_graph, dep_map):
Expand All @@ -104,7 +111,7 @@ def find_and_dependencies(packagename, version, dep_graph, dep_map):
if version == '?' :
version = dep['required_version'][2:]
if "!" in version :
version = version .split('!')[0]
version = version.split('!')[0]
find_and_dependencies(dep['package_name'],version,dep_graph, dep_map)


Expand Down