-
Notifications
You must be signed in to change notification settings - Fork 718
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
Documentation for ssg library #12606
Documentation for ssg library #12606
Conversation
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
There are some relatively complex rules in this file and some opportunities for refactoring. But it is not in the scope of this initiative around documentation. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
This module already had docstrings for some rules, but in some cases they were not updated. So I basically reviewed them, updated what was necessary and ensured a consistent format. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
The structure of this file is a bit weird, so I included docstrings in only one function used to build guides. This file and respective functions should be reviewed in another opportunity. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
There are many functions in this file and some simple docstrings were already present for some functions. They were reviewed and updated while new docstrings were created. In some cases, functions comments were incorporated in docstrings. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
ssg/boolean_expression.py
Outdated
to enrich expression elements with domain-specific methods. | ||
|
||
Methods: | ||
is_and() -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcusburghardt just to clarify, are you sure it is a good idea to consolidate documentation for all class members here? Wouldn't it make problems when someone wants to see help for particular method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention is not to consolidate documentation of methods within the class Docstrings.
Within the Class Docstring there is just a brief of their methods so when the class is called, for example in VSCode IDE it already shows the available methods. Otherwise we need to rely on autocomplete or check the class definition, for example. So it is helpful in this case. It is true that once the class is updated, we should also update the Docstring otherwise there is risk to have outdated Docstring. I would like to hear more opinions if it is worth or not to briefly mention the methods within class Docstrings. What do you think @jan-cerny , @Mab879 ?
Another topic is about functions Docstrings. They should not be replaced by Class Docstrings, but in some cases, as I mentioned in the PR description, I opted to not create a Docstring because the one line function was self explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the list of methods up-to-date is one concern I have about listing the method in the class docstring,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to move forward with this. Considering at least one case where methods mentioned in class Docstrings is useful for developers and the risk of misalignment between Docstrings and methods along the time, I would prefer to keep this for now since they are already there.
We can mitigate the risk of misalignment by exercising due diligence both when developing and when reviewing code. If this becomes a real problem in the future, we can always reevaluate and perhaps remove method information from class Docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I must say I am not in favor of this. I see the benefit of having everything at the one place, so that when you open documentation for the class, you see methods as well. However, I have following concerns:
- There are specific facilities exactly for this, without writing it in the code directly. For example, VS Code has the "outline" view, see the screenshot. It is very configurable I would say.
- It is not standard.
- That means, that people are not used to that and we will have to keep extra eye on consistency between the real method definition and the definition in the class documentation.
In case you stand strongly behind this desire, I suggest you propose a separate PR adding this documentation to classes together with update of our style guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example of "outline" is similar to what I mentioned before, regarding autocomplete
. The same information in your "outline" example can be obtained in different ways, but not as straightforward as in Docstrings.
In my assessment, having this offers more pros than cons. I don't believe that in this case we should remove this helpful information only because there is an hypothetical risk of having something outdated along the time, which is something we can pretty much mitigate. Also, this SSG package is relatively stable if we look the changes along the last years. In addition, I saw multiple cases of Docstrings not mentioning all methods in different projects and I found the methods anyways with some extra steps. It can happen, but what is the real problem of not having a class Docstring perfectly updated about a new method included or considerably changed, specially if the methods have their own Docstrings, which are more complete?
I don't see an strong argument against having this information there for who wants to use them among other options to obtain the same information. The intention of the documentation is to make ssg easier to be consumed and I am in favor of giving options for different preferences, specially in this case where no code is impacted.
But I want to move forward with the documentation. So, let me know if this is blocking the PR to be merged. If so, I will work on an additional commit to remove the information. If you believe this should be removed, I am fine to remove and unblock it. In any case, thanks for the feedback on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that having this section in the class documentation is handy, because it is just next to other information about the class, but I am still not convinced that pros outweight cons. As I am not the only one having concerns around this change, please propose it as a separate PR, preferably with an ammendment to the style guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in my last commit. I am personally in favor of including documentation that is helpful for some people even if not everybody is expected to use the same information, so we can support a wider audience. Specially when the information causes no harm to the project. But I removed the information so we can move forward with this PR and discuss preferences in another place. : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @marcusburghardt and thank you for this large update. It is a big piece of work. I read through it and I have mostly minor comments, I put them near to relevant lines.
One more thing to be resolved is documentation of methods within the class documentation, let's discuss it in the particular thread which already exists.
ssg/controls.py
Outdated
AUTOMATED (str): Indicates the control is fully automated. | ||
|
||
Methods: | ||
__init__(self, status): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if it is a good idea to have these methods listed here. I understand it might be convenient to have nice list of methods just under the class description, but I am afraid this list and real list of methods (not talking about their parameters and meaning) can get out of sync.
One more thing which could but does not need to be part of this PR is updating of style guide adding a bullet point that new functions should be documented. |
Thanks @vojtapolasek Co-authored-by: vojtapolasek <krecoun@gmail.com>
I plan to create a separate PR for this. |
Thanks @vojtapolasek for noticing. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
They are not necessary. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
There are cases where this information is useful. Myself can use this information and can say they are handy. This information causes no harm and nonody is mandated to use it as well. But there is a conflict of personal preferences. I wouldn't like to block this PR until we find a consensus. So I decided to remove it now and keep the discussion in a separate PR. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Code Climate has analyzed commit 2c71e1e and detected 92 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 60.9% (0.0% change). View more on Code Climate. |
/packit test |
/packit retest-failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the changes. I am merging the PR.
Failing tests are not relevant for these changes, they are only doc string changes anyway.
13d47ad
into
ComplianceAsCode:master
Description:
This PR consists of several commits, one commit for each file in
ssg
folder (without considering sub-folders), whereDocstrings
are included in functions and classes.I have opted by the Google format since it has a good compatibility with tools and a good readability.
During this work, I reviewed about
365
functions and40
classes to make sure the Docstring was aligned to the code.In most of the cases complete Docstring was created, in some cases it was just formatted to be consistent with Google format and in other cases I had to update the content.
In some really simple functions I opted to not include a Docstring because the function was self-explained.
It was also included Docstrings for internal functions when I considered them important to better understand when and how they were used.
I tried to keep the Docstrings as generic as possible but also inclined to the context of the project since some functions without context would be difficult to understand.
Finally, I skipped all files/scripts used to build the content, which start with
build_*.py
and thecontent_diff.py
file.Rationale:
Once the PR is merged, the Docstrings should also improve our documentation in https://complianceascode.readthedocs.io/en/latest/modules/ssg.html, making it easier for the community to consume and contribute to the ssg library.
Review Hints:
Be prepared for a time-consuming task, but I would say that it was great to improve my understanding about the SSG library. The work also gave me many insights about what could be improved, but this is definitely out of scope here.
No code was changed, so no risk is expected from this PR. In some isolated cases I removed comments from functions because they were incorporated in Docstrings, so duplication was not necessary. But in general ensured no code changes.