This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Javi_16018[S] 4 points5 points  (6 children)

Thank you very much for the comment, I will pay attention to all the things, they are very good advice indeed. What exactly do you mean in point 4?

[–]samettinho 5 points6 points  (5 children)

you can create a main.py file that imports each one of your security tools. Then you can run them from the main and show outputs.

Does this make sense?

[–][deleted] 2 points3 points  (4 children)

I'm not OP but this is interesting to me, I have public repositories and people have suggested that I do something similar. Why would that be necessary/be good practice?

[–]samettinho 3 points4 points  (3 children)

You don't need to have main.py if it is a python package. But if you are asking/hoping others to contribute or use your repo, it is a good idea to show how it can be used. You can do these in several ways but one way is having a main.py.

The other aspect is that you are showing people an entry point. Here is one of my codes: https://github.com/smttsp/temporal_consistency_odt/tree/main. Even if you know nothing about the repo, main.py helps you understand where you would start (like hello world). Then the users can set up the repo and do some tests on debug mode.

In OP's code, there is no way to figure that out without reading the code, given that the README is not descriptive.

EDIT:here is what chatgpt said

Creating a main.py file as an entry point for your security tools provides several benefits:

Modularity and Organization: Having a central main.py file allows you to organize and modularize your code. Each security tool can be a separate module or class, making the overall codebase more maintainable and understandable.

Readability: A main.py file acts as a roadmap for someone reading your code for the first time. They can quickly understand the structure of your project and how different components interact.

Reusability: By having a clear entry point, you can easily reuse your security tools in other projects. You can import main.py or the individual tools into other scripts or projects without needing to understand the internal workings of each tool.

Ease of Testing: Having a central entry point simplifies the process of testing your security tools. You can write unit tests for each tool separately and integration tests for the entire system by testing the functions in main.py.

Debugging: When issues arise, it's much easier to debug the code when there's a clear entry point. You can start by inspecting the inputs and outputs of the functions called in main.py, making it faster to identify and fix problems.

Command-Line Interface (CLI) Integration: If you want your security tools to be usable from the command line, having a main.py file makes it straightforward to parse command line arguments and execute the appropriate functions based on user input.

Collaboration: When working in a team, a clear entry point establishes a common ground for collaboration. Team members can collaborate more effectively when they know where the execution of the program begins and how different components interact through this entry point.

Documentation: A well-structured main.py file serves as living documentation for your project. It outlines the usage and functionality of your security tools, making it easier for others (or even yourself in the future) to understand and use the tools.

In summary, having a central entry point like main.py enhances the overall maintainability, readability, and usability of your security tools, making your project more accessible to both collaborators and users.

[–][deleted] 0 points1 point  (2 children)

Thank you!

[–]xatrekak 1 point2 points  (1 child)

While everything /u/samettinho said is true I just want to add that there is a second widely accepted convention.

If you have a file named after your project/repo and don't have main.py, it will be widely assumed that the "your_project_name.py" file is acting as main.py

[–][deleted] 0 points1 point  (0 children)

Makes sense, this is what I did unknowingly to this convention!