Closed tristan0x closed 2 years ago
Wow! Very nice. Can we open it up to do the equivalent for python? My personal interest is automatic formatting, so that's the context.
I would like to write in documentation something like: "Please use bbp-format.py format
to format the entire code-base according to the BBP standards." It would be awesome if it would format all code (to be formatted), including C++ (done), CMake (done) and Python and anything else that needs formatting at BBP. (We can add this later, I'm happy to help.) Therefore, I'd slightly change the name of the file to something less C++ centric: .bbp_project.yml
, .bbp_settings.yml
, .bbp_config.yml
, .hpc-coding-conventions.rc
.
It would be super nice if we can easily enable pre-write hooks in editors (vim). Can we implement:
bbp-format.py format --file to_be_formatted.{cpp,py}
which will format the specified file only? (Changing files while they're loaded in an IDE/editor causes a little bit of disruption, hence the request.) Also it would select the write formatter automatically.
Does it need a way of agreeing on where to put compile_commands.json
?
Wow! Very nice. Can we open it up to do the equivalent for python? My personal interest is automatic formatting, so that's the context.
Absolutely, we can extend the YAML to support other tools like Python. We could use Black, flake8 + flake8-import-order. I would first implement this issue and then add support for Python code formatting / analysis in another PR though.
I would like to write in documentation something like: "Please use
bbp-format.py format
to format the entire code-base according to the BBP standards." It would be awesome if it would format all code (to be formatted), including C++ (done), CMake (done) and Python and anything else that needs formatting at BBP. (We can add this later, I'm happy to help.)
👍
Therefore, I'd slightly change the name of the file to something less C++ centric:
.bbp_project.yml
,.bbp_settings.yml
,.bbp_config.yml
,.hpc-coding-conventions.rc
.
Ok for .bbp_project.yaml
! (.yaml is the official extension)
It would be super nice if we can easily enable pre-write hooks in editors (vim). Can we implement:
bbp-format.py format --file to_be_formatted.{cpp,py}
which will format the specified file only? (Changing files while they're loaded in an IDE/editor causes a little bit of disruption, hence the request.) Also it would select the write formatter automatically.
I like the idea to have a script per task, not per tool. I would make an even simpler synopsis for the formatting utility:
USAGE: format [options] [<file> or <dir> ...]
Format the given files or directories, the entire project otherwise.
OPTIONS:
-n --dry-run : do not actually update the files, simply report formatting issues.
--lang : only format the specified languages, default is: c++,cmake,python
Does it need a way of agreeing on where to put
compile_commands.json
?
The file compile_commands.json
is written by CMake in the top build directory and AFAIK there is no way to modify the path or its name, so it is IMO complicated to mention a proper location of this file in .bbp_project.yaml
, but I am really open to ideas. Today, the bbp-clang-tidy
script expects the compile command database to be passed through option -p
, see here
Besides, I would not worry too much about that since ClangTidy integration in CMake is pretty good:
make clang-tidy
to check the entire codebase.
Status
Many variables are defined at CMake level. It makes them a bit complicated to overwrite them (#117), and it is required to run the
configure
phase to use the associated tools (ClangFormat, ...). Furthermore, the CLI utilities are unusable right away since most of their inputs are defined at CMake level.Target
cmake
to use most of the tools. There are still inherent limits though, for instance:compile_commands.json
file (conveniently generated by CMake)Proposal
Remove some CMake variables and put them in a new configuration file. hpc-coding-conventions project would provide a default one, but a parent project could provide its own.
The config file
in YAML format. Filename:
.cppproject.yml
Default file used by hpc-coding-conventions in `cpp/.cppproject.ymlList of CMake cache variables to remove
${CODING_CONV_PREFIX}_GIT_COMMIT_HOOKS
${CODING_CONV_PREFIX}_GIT_PUSH_HOOKS
${CODING_CONV_PREFIX}_ClangFormat_REQUIRED_VERSION
${CODING_CONV_PREFIX}_ClangFormat_OPTIONS
${CODING_CONV_PREFIX}_ClangFormat_FILES_RE
${CODING_CONV_PREFIX}_ClangFormat_EXCLUDES_RE
${CODING_CONV_PREFIX}_ClangFormat_DEPENDENCIES
${CODING_CONV_PREFIX}_CMakeFormat_REQUIRED_VERSION
${CODING_CONV_PREFIX}_CMakeFormat_OPTIONS
${CODING_CONV_PREFIX}_CMakeFormat_FILES_RE
${CODING_CONV_PREFIX}_CMakeFormat_EXCLUDES_RE
${CODING_CONV_PREFIX}_ClangTidy_REQUIRED_VERSION
${CODING_CONV_PREFIX}_ClangTidy_OPTIONS
${CODING_CONV_PREFIX}_ClangTidy_FILES_RE
${CODING_CONV_PREFIX}_ClangTidy_EXCLUDES_RE
${CODING_CONV_PREFIX}_ClangTidy_DEPENDENCIES
${CODING_CONV_PREFIX}_TEST_FORMATTING
Content of the default configuration file
Implementation details
Finding utilities like ClangTidy or CMakeFormat
Using Python version specifiers in the YAML file to describe the versions required is a move toward the idea to create a virtualenv to automagically install the required tools. Right now, the utilities like ClangTidy (an executable) or CMakeFormat (a Python package) are searched by CMake. It is probable that introducing Python version specifiers means the end of this and rely on Python to find (and maybe later install) the required tools.