engineerjoe440 / ElectricPy

Electrical Engineering Formulas in Python
https://electricpy.readthedocs.io/en/latest/
MIT License
86 stars 16 forks source link

Source Code url in documentation #30

Closed Lakshmikanth2001 closed 2 years ago

Lakshmikanth2001 commented 2 years ago

image

Can we have a similar source pointing anchor tag in our https://engineerjoe440.github.io/ElectricPy/api/ documentation page

I have written a python script to generate URL for each function

function_url =  dict()
REMOTE_URL = "https://github.com/engineerjoe440/ElectricPy/blob/master/electricpy/"

#get only files electricpy directory
SOURCES = [file for file in os.listdir('./electricpy') if os.path.isfile(file)]

for source in SOURCES:
    with open(os.path.join(sys.path[0], f"electricpy\{source}"), "r") as code:
        # buid a regular expression for "def ()"
        RE = re.compile('def ()')

        # iterate over the lines in the file
        for line_number, line in enumerate(code):
            # find all the functions
            match = RE.findall(line)
            # if there are any matches
            if match:
                #get text between def and (

                function_name = line[line.find("def")+4:line.find("(")]

                function_url[function_name] = f"{REMOTE_URL}{source}#L{line_number+1}"

        with open("urls.json", 'w') as url_data:
            json.dump(function_url, url_data) 

urls.json would look similar to this

 "phasorz": "https://github.com/engineerjoe440/ElectricPy/blob/master/electricpy/__init__.py#L844",

https://github.com/engineerjoe440/ElectricPy/blob/master/electricpy/__init__.py#L844 will directly point to the actual function

Can we include this feature

engineerjoe440 commented 2 years ago

I'm afraid I don't fully understand what you're proposing. I think I like the idea of anchored links, but I'm not sure I see how your proposed implementation fits in.

Where is the urls.json file placed, and what does it provide? What references it?

I'll note, there's a subtle improvement that you could add to the RegEx find in your code to find everything up to the first bracket:

RE = re.compile(r'def (.*)\(') # Find all text (function name) up to the open-parenthesis

If you'd like to make the modifications in a fork of the repo and open a PR so I can see the results, I'd be very happy to explore more closely! :)

Lakshmikanth2001 commented 2 years ago

urls.json provide hyperlinks for the source code "phasorz": "https://github.com/engineerjoe440/ElectricPy/blob/master/electricpy/__init__.py#L844",

Phasor function source code can be viewed just by clicking this link

Lakshmikanth2001 commented 2 years ago

Additional Information <https://electrical-engineering-portal.com/download-center/books-and-guides/power-substations/insulator-pollution>

image

In suspension insulator we are having Additional Information hyperlink

Similarly, we can add a source which redirects to source code in GitHub

Lakshmikanth2001 commented 2 years ago

Sir any update regarding this ???

engineerjoe440 commented 2 years ago

Please forgive the delay on this issue, I believe you'll see updated documentation in the web documentation now!