Skip to content
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

Automate C++ include file grouping and ordering using clang-format #4205

Merged

Conversation

harrism
Copy link
Member

@harrism harrism commented Feb 29, 2024

Description

This uses the IncludeCategories settings in .clang-format to automate include ordering and grouping and to make include ordering more consistent with the rest of RAPIDS. For discussion, see rapidsai/cudf#15063. This PR uses a similar set of header grouping categories used in that PR, adapted for cuGraph.

One purpose of this is to make it easier to automate injection of a header change with an upcoming RMM refactoring (and in the future).

Note that this PR also updates all of cugraph to use quotes ("") when includeing local source headers. That is, whenever something is included from cugraph/src/*, it should be included with quotes rather than angle brackets. This makes it much easier to order includes from "nearest to farthest", and matches the approach now taken in other RAPIDS repos. Without switching to quotes, keeping these includes at the top requires special casing each subdirectory of src in the clang-format group regular expressions.

Includes from the include directory stay as angle brackets, because they always use #include <cugraph/...>.

cuGraph tests include a LOT of internal source headers. I think we should generally avoid this, but it depends on the testing philosophy. If one believes that tests should only cover the external interfaces of the library, then there is no need to include internal headers. But if we want to test internal functionality, then the tests need to be more "internal" to the library.

The header reordering in this PR also uncovered some places where headers were not included where they are used, which I have fixed.

Closes #4185

@harrism harrism requested a review from a team as a code owner February 29, 2024 02:45
@harrism harrism added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 29, 2024
@harrism harrism self-assigned this Feb 29, 2024
@github-actions github-actions bot added cuGraph and removed improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 29, 2024
@harrism harrism added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 29, 2024
@bdice bdice mentioned this pull request Feb 29, 2024
Copy link
Contributor

@seunghwak seunghwak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have questions about few empty lines. Otherwise, looks good to me and thank you very much for the contribution!

#include <c_api/error.hpp>
#include <c_api/resource_handle.hpp>
#include "c_api/array.hpp"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have an empty line here?

Copy link
Contributor

@bdice bdice Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a small number of cases like this in cudf, too. We suspected a clang-format bug was responsible. (We agreed that an automated solution, even if imperfect, is much better than manual enforcement.)

@@ -14,14 +14,15 @@
* limitations under the License.
*/

#include <cugraph_c/graph_functions.h>
#include "c_api/graph_functions.hpp"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have an empty line here?

@@ -14,13 +14,13 @@
* limitations under the License.
*/

#include <utilities/device_comm_wrapper.hpp>
#include <utilities/test_utilities.hpp>
#include "c_api/mg_test_utils.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we group this header with the c_api headers below?

@naimnv
Copy link
Contributor

naimnv commented Feb 29, 2024

Thank you. It is super useful.

@ChuckHastings
Copy link
Collaborator

/merge

@rapids-bot rapids-bot bot merged commit cc4199d into rapidsai:branch-24.04 Feb 29, 2024
137 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuGraph improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Automate C++ include file grouping and ordering using clang-format
5 participants