How I made a small python code analyzing tool in a day
What is Code Analyzer ?
This is basically a sort of framework that clones a repo from GitHub and tests the code within it and returns the time and space used by the code. The code in the repo should be in a particular format i.e the code should be written in test.py file , The code to be analyzed should be written inside class name called Testing and should contain code within setup function with params as parameters to the function.
Motivation: As I was searching for a tool that analyzes a particular format of python codes and return their time complexity and peak memory used, But found out there were no such thing. So why not make one yourself. In this blog I will explain every piece of code and trouble I faced when making my own analyzing sort of framework.
Lets Get Into The Code (The Fun Part)
So as I was brainstorming I came to a conclusion that the system needs 3 part :
Cloning
import os
import shutil
from os import path
import urllib3
import subprocess
class RepoClone:
"""
Class to clone repos from github
"""
def __init__(self, url):
"""
Initializing the instance
:param url: url of the desired repo must be HTTPS not SSH
"""
self.url = url
self.path = str(os.getcwd() + '/temp/')
def __check_path__(self):
if path.exists(self.path):
shutil.rmtree(self.path)
else:
os.mkdir(self.path)
def clone(self):
"""
:return: if the clone is success returns true otherwise false
"""
self.__check_path__()
url_check = urllib3.connection_from_url(self.url)
## checking if the host is github or not
if url_check.host == 'github.com':
try:
var = subprocess.run(["git", "clone", self.url, self.path], check=True, stdout=subprocess.PIPE).stdout
## os.system('git clone ' + self.url + ' ' + self.path)
return True
except subprocess.CalledProcessError:
return False
else:
return False
data-science machine-learning programming python artificial-intelligence
Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.
Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.
Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.
Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.
Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.