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

Extract a formatting script. #1055

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,4 @@ jobs:

- name: Run clang-format
run: |
clang-format --version
for i in $(git ls-files | grep ".[ch]pp$");
do
clang-format -i "$i" > /dev/null 2>&1;
done
modified_files=$(git diff --name-only)
if [ -n "$modified_files" ];
then
echo "Some files are not well formatted:"
echo $modified_files
echo ""
echo "The diff is:"
git diff
exit 1
fi
bash bin/format.sh
41 changes: 41 additions & 0 deletions bin/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

clang_format_version="19.1.3"

script_dir="$(dirname "${BASH_SOURCE[0]}")"
venv_dir="$script_dir/../.clang-format-venv"

if [ ! -d "$venv_dir" ]; then
python3 -m venv "$venv_dir"
source "$venv_dir/bin/activate"
pip install clang-format=="$clang_format_version"
deactivate
fi

source "$venv_dir/bin/activate"

# Check if the installed version matches the expected version
installed_version="$(pip show clang-format | grep Version | cut -d ' ' -f 2)"

if [ "$installed_version" != "$clang_format_version" ]; then
echo "Error: clang-format version mismatch. Expected $clang_format_version, got $installed_version"
echo "Please remove the virtual environment and run the script again:"
echo " rm -r \"$venv_dir\" && \"$0\""
exit 1
fi

clang-format --version
for i in $(git ls-files | grep ".[ch]pp$"); do
clang-format -i "$i" > /dev/null 2>&1
done

modified_files=$(git diff --name-only)
if [ -n "$modified_files" ]; then
echo "Some files are not well formatted:"
echo "$modified_files"
echo ""
echo "The diff is:"
git --no-pager diff
exit 1
fi
18 changes: 6 additions & 12 deletions doc/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,16 @@ tests.
### Code formatting
The project is formatted using clang-format version 12.0.1 and CI will complain
if a commit isn't formatted accordingly. The `.clang-format` is at the root of
the git repository. Conveniently, `clang-format` is available via `pip`:
the git repository. Conveniently, `clang-format` is available via `pip`.

Formatting the entire code base can be done with:
```bash
python -m venv venv
source venv/bin/activate

pip install clang-format==12.0.1
bin/format.sh
```
which will install the required version of clang-format in a venv called
`.clang-format-venv`.

The changed lines can be formatted with `git-clang-format`, e.g. to format all lines changed compared to master:

```bash
git-clang-format master
```
(add `-f` to allow formatting unstaged changes if you trust it to not destroy
your changes.)
To format only the changed files `git-clang-format` can be used.

## Releasing HighFive
Before releasing a new version perform the following:
Expand Down
2 changes: 1 addition & 1 deletion include/highfive/H5Group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Group: public Object,
}

Group(Object&& o) noexcept
: Object(std::move(o)){};
: Object(std::move(o)) {};

protected:
using Object::Object;
Expand Down
2 changes: 1 addition & 1 deletion include/highfive/H5Reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Reference {
protected:
/// \brief Create a Reference from a low-level HDF5 object reference
inline explicit Reference(const hobj_ref_t h5_ref)
: href(h5_ref){};
: href(h5_ref) {};

/// \brief Create the low-level reference and store it at refptr
///
Expand Down
4 changes: 2 additions & 2 deletions include/highfive/bits/H5Converter_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ShallowCopyBuffer {
ShallowCopyBuffer() = delete;

explicit ShallowCopyBuffer(typename std::conditional<IsReadOnly, const T&, T&>::type val)
: ptr(inspector<T>::data(val)){};
: ptr(inspector<T>::data(val)) {};

hdf5_type* getPointer() const {
return ptr;
Expand Down Expand Up @@ -349,7 +349,7 @@ struct Writer<T, typename enable_shallow_copy<T>::type>: public ShallowCopyBuffe
explicit Writer(const T& val,
const std::vector<size_t>& /* dims */,
const DataType& /* file_datatype */)
: super(val){};
: super(val) {};
};

template <typename T>
Expand Down
24 changes: 18 additions & 6 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,22 @@ TEST_CASE("Test open modes in HighFive") {
CHECK_THROWS_AS(File(file_name, File::ReadWrite), FileException);

// But with Create flag should be fine
{ File file(file_name, File::ReadWrite | File::Create); }
{
File file(file_name, File::ReadWrite | File::Create);
}

// But if its there and exclusive is given, should fail
CHECK_THROWS_AS(File(file_name, File::ReadWrite | File::Excl), FileException);
// ReadWrite and Excl flags are fine together (posix)
std::remove(file_name.c_str());
{ File file(file_name, File::ReadWrite | File::Excl); }
{
File file(file_name, File::ReadWrite | File::Excl);
}
// All three are fine as well (as long as the file does not exist)
std::remove(file_name.c_str());
{ File file(file_name, File::ReadWrite | File::Create | File::Excl); }
{
File file(file_name, File::ReadWrite | File::Create | File::Excl);
}

// Just a few combinations are incompatible, detected by hdf5lib
CHECK_THROWS_AS(File(file_name, File::Truncate | File::Excl), FileException);
Expand All @@ -132,12 +138,18 @@ TEST_CASE("Test open modes in HighFive") {
CHECK_THROWS_AS(File(file_name, File::Truncate | File::Excl), FileException);

// But in most cases we will truncate and that should always work
{ File file(file_name, File::Truncate); }
{
File file(file_name, File::Truncate);
}
std::remove(file_name.c_str());
{ File file(file_name, File::Truncate); }
{
File file(file_name, File::Truncate);
}

// Last but not least, defaults should be ok
{ File file(file_name); } // ReadOnly
{
File file(file_name);
} // ReadOnly
}

void check_access_mode(File::AccessMode mode) {
Expand Down
Loading