DIY : Python Code Analyzer

DIY : Python Code Analyzer

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 :

  1. one that clones the repo only from GitHub
  2. 2.second it should analyze the validity of the module
  3. giving the cloned code some type of score according to the resources used.

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Science Projects | Data Science | Machine Learning | Python

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.

Data Science Projects | Data Science | Machine Learning | Python

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.

Data Science Projects | Data Science | Machine Learning | Python

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.

Data Science Projects | Data Science | Machine Learning | Python

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.

Data Science Projects | Data Science | Machine Learning | Python

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.