From ff17ebd700b507a2020d1aec28057b0074e3b370 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 3 Nov 2026 08:50:24 -0600 Subject: [PATCH] COMP: Restore the clang-format lint check The lint job referenced ITKClangFormatLinterAction@master, which no longer resolves since the action's default branch became main. The action now also fails when no tracked file has the hooks.style=clangformat attribute, so add a .gitattributes marking the C++ sources, and apply the module's .clang-format to the four files that did not conform. The reformat changes only whitespace and line breaks. --- .gitattributes | 3 + .github/workflows/clang-format-linter.yml | 2 +- src/itkOMEZarrNGFFImageIO.cxx | 9 +- src/itkOMEZarrNGFFImageIOFactory.cxx | 14 +-- test/itkOMEZarrNGFFInMemoryTest.cxx | 10 +- test/itkOMEZarrNGFFReadSliceTest.cxx | 129 +++++++++++----------- 6 files changed, 85 insertions(+), 82 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1a698ab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.h hooks.style=clangformat +*.hxx hooks.style=clangformat +*.cxx hooks.style=clangformat diff --git a/.github/workflows/clang-format-linter.yml b/.github/workflows/clang-format-linter.yml index a4582b7..f41889a 100644 --- a/.github/workflows/clang-format-linter.yml +++ b/.github/workflows/clang-format-linter.yml @@ -8,4 +8,4 @@ jobs: steps: - uses: actions/checkout@v1 - - uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@master + - uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@main diff --git a/src/itkOMEZarrNGFFImageIO.cxx b/src/itkOMEZarrNGFFImageIO.cxx index 6a02db2..4062bdb 100644 --- a/src/itkOMEZarrNGFFImageIO.cxx +++ b/src/itkOMEZarrNGFFImageIO.cxx @@ -374,7 +374,7 @@ MakeKVStoreHTTPDriverSpec(nlohmann::json & spec, const std::string & fullPath) // JSON file path, e.g. "C:/Dev/ITKIOOMEZarrNGFF/v0.4/cyx.ome.zarr/.zgroup" void -writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore::Context& tsContext) +writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore::Context & tsContext) { auto attrs_store = tensorstore::Open( { { "driver", "json" }, { "kvstore", { { "driver", driver }, { "path", path } } } }, @@ -395,7 +395,7 @@ writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore // JSON file path, e.g. "C:/Dev/ITKIOOMEZarrNGFF/v0.4/cyx.ome.zarr/.zattrs" bool -jsonRead(const std::string path, nlohmann::json & result, std::string driver, tensorstore::Context& tsContext) +jsonRead(const std::string path, nlohmann::json & result, std::string driver, tensorstore::Context & tsContext) { // Reading JSON via TensorStore allows it to be in the cloud nlohmann::json readSpec = { { "driver", "json" }, { "kvstore", { { "driver", driver }, { "path", path } } } }; @@ -584,7 +584,7 @@ OMEZarrNGFFImageIO::ReadArrayMetadata(std::string path, std::string driver) ImageIORegion OMEZarrNGFFImageIO::ConfigureTensorstoreIORegion(const ImageIORegion & ioRegion) const { - const auto storeRank = m_TensorStoreData->store.rank(); + const auto storeRank = m_TensorStoreData->store.rank(); // Set up IO region to match known store dimensions itkAssertOrThrowMacro(m_StoreAxes.size() == storeRank, "Detected mismatch in axis count and store rank"); @@ -858,7 +858,8 @@ OMEZarrNGFFImageIO::Write(const void * buffer) { // Attempt to read a non-existent file from the in-memory zip to close the current one nlohmann::json temp; - bool wasRead = jsonRead(m_EmptyZipFileName + "/non-existent.json", temp, "zip_memory", m_TensorStoreData->tsContext); + bool wasRead = + jsonRead(m_EmptyZipFileName + "/non-existent.json", temp, "zip_memory", m_TensorStoreData->tsContext); assert(wasRead == false); } } diff --git a/src/itkOMEZarrNGFFImageIOFactory.cxx b/src/itkOMEZarrNGFFImageIOFactory.cxx index a0ae52f..d5f8acb 100644 --- a/src/itkOMEZarrNGFFImageIOFactory.cxx +++ b/src/itkOMEZarrNGFFImageIOFactory.cxx @@ -23,12 +23,11 @@ namespace itk { OMEZarrNGFFImageIOFactory::OMEZarrNGFFImageIOFactory() { - this->RegisterOverride( - "itkImageIOBase", - "itkOMEZarrNGFFImageIO", - "Open Microscopy Environment Zarr Next Generation File Format", - true, - CreateObjectFunction::New()); + this->RegisterOverride("itkImageIOBase", + "itkOMEZarrNGFFImageIO", + "Open Microscopy Environment Zarr Next Generation File Format", + true, + CreateObjectFunction::New()); } const char * @@ -40,7 +39,8 @@ OMEZarrNGFFImageIOFactory::GetITKSourceVersion() const const char * OMEZarrNGFFImageIOFactory::GetDescription() const { - return "OMEZarrNGFF ImageIO Factory, allows the loading of images in Open Microscopy Environment Zarr Next Generation File Format"; + return "OMEZarrNGFF ImageIO Factory, allows the loading of images in Open Microscopy Environment Zarr Next " + "Generation File Format"; } // Undocumented API used to register during static initialization. diff --git a/test/itkOMEZarrNGFFInMemoryTest.cxx b/test/itkOMEZarrNGFFInMemoryTest.cxx index a7b2b76..83cb8df 100644 --- a/test/itkOMEZarrNGFFInMemoryTest.cxx +++ b/test/itkOMEZarrNGFFInMemoryTest.cxx @@ -51,7 +51,7 @@ doTest(const char * inputFileName, const char * outputFileName) // Copy zip data into memory // Adapted from https://stackoverflow.com/a/18816228/276168 - std::ifstream file(inputFileName, std::ios::binary | std::ios::ate); + std::ifstream file(inputFileName, std::ios::binary | std::ios::ate); const std::streamsize inputBufferSize = file.tellg(); file.seekg(0, std::ios::beg); std::vector buffer(inputBufferSize); @@ -63,8 +63,8 @@ doTest(const char * inputFileName, const char * outputFileName) // Read the zip-compressed bitstream from memory into an ITK image itk::OMEZarrNGFFImageIO::BufferInfo bufferInfo{ buffer.data(), buffer.size() }; - const auto inputBufferPointer = buffer.data(); - std::string memAddress = itk::OMEZarrNGFFImageIO::MakeMemoryFileName(bufferInfo); + const auto inputBufferPointer = buffer.data(); + std::string memAddress = itk::OMEZarrNGFFImageIO::MakeMemoryFileName(bufferInfo); typename ReaderType::Pointer memReader = ReaderType::New(); memReader->SetFileName(memAddress); @@ -84,8 +84,8 @@ doTest(const char * inputFileName, const char * outputFileName) } // Verify a local copy of the buffer is maintained in the itk::Image - memImage->DisconnectPipeline(); // keep our local copy of the memory buffer - std::fill(buffer.begin(), buffer.end(), 0); // reset the memory buffer in place + memImage->DisconnectPipeline(); // keep our local copy of the memory buffer + std::fill(buffer.begin(), buffer.end(), 0); // reset the memory buffer in place ITK_TRY_EXPECT_NO_EXCEPTION(comparer->Update()); // should not reflect buffer update if (comparer->GetNumberOfPixelsWithDifferences() > 0) { diff --git a/test/itkOMEZarrNGFFReadSliceTest.cxx b/test/itkOMEZarrNGFFReadSliceTest.cxx index 994052b..50443ec 100644 --- a/test/itkOMEZarrNGFFReadSliceTest.cxx +++ b/test/itkOMEZarrNGFFReadSliceTest.cxx @@ -16,14 +16,14 @@ * *=========================================================================*/ - /// This test utility may be used to validate that an OME-Zarr image can be - /// read from disk or from an HTTP source. - /// - /// No attempt is made to validate input data. A summary of the retrieved image - /// is printed to `std::cout`. - /// - /// Does not currently support multichannel sources. - /// https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF/issues/32 +/// This test utility may be used to validate that an OME-Zarr image can be +/// read from disk or from an HTTP source. +/// +/// No attempt is made to validate input data. A summary of the retrieved image +/// is printed to `std::cout`. +/// +/// Does not currently support multichannel sources. +/// https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF/issues/32 #include #include @@ -39,71 +39,70 @@ namespace { - template - void - doRead(const std::string& inputPath, - const std::string& outputPath, - const int timeIndex, - const int channelIndex, - const int datasetIndex) - { - using ImageType = itk::Image; - auto imageReader = itk::ImageFileReader::New(); - imageReader->SetFileName(inputPath); +template +void +doRead(const std::string & inputPath, + const std::string & outputPath, + const int timeIndex, + const int channelIndex, + const int datasetIndex) +{ + using ImageType = itk::Image; + auto imageReader = itk::ImageFileReader::New(); + imageReader->SetFileName(inputPath); - auto imageIO = itk::OMEZarrNGFFImageIO::New(); - imageIO->SetDatasetIndex(datasetIndex); - imageIO->SetTimeIndex(timeIndex); - imageIO->SetChannelIndex(channelIndex); - imageReader->SetImageIO(imageIO); + auto imageIO = itk::OMEZarrNGFFImageIO::New(); + imageIO->SetDatasetIndex(datasetIndex); + imageIO->SetTimeIndex(timeIndex); + imageIO->SetChannelIndex(channelIndex); + imageReader->SetImageIO(imageIO); - imageReader->UpdateOutputInformation(); - auto output = imageReader->GetOutput(); - output->Print(std::cout); + imageReader->UpdateOutputInformation(); + auto output = imageReader->GetOutput(); + output->Print(std::cout); - imageReader->Update(); - output->Print(std::cout); + imageReader->Update(); + output->Print(std::cout); - using WriterType = itk::ImageFileWriter; - auto writer = WriterType::New(); - writer->SetInput(output); - writer->SetFileName(outputPath); - writer->SetUseCompression(true); - writer->Update(); - } + using WriterType = itk::ImageFileWriter; + auto writer = WriterType::New(); + writer->SetInput(output); + writer->SetFileName(outputPath); + writer->SetUseCompression(true); + writer->Update(); +} } // namespace int -itkOMEZarrNGFFReadSliceTest(int argc, char* argv[]) +itkOMEZarrNGFFReadSliceTest(int argc, char * argv[]) { - if (argc < 4) - { - std::cerr << "Missing parameters." << std::endl; - std::cerr << "Usage: " << std::endl; - std::cerr << itkNameOfTestExecutableMacro(argv) - << " [timeIndex] [channelIndex] [datasetIndex]" - << std::endl; - return EXIT_FAILURE; - } - const char* inputFileName = argv[1]; - const char* outputFileName = argv[2]; - const size_t imageDimension = std::atoi(argv[3]); - const size_t timeIndex = (argc > 4 ? std::atoi(argv[4]) : 0); - const size_t channelIndex = (argc > 5 ? std::atoi(argv[5]) : 0); - const size_t datasetIndex = (argc > 6 ? std::atoi(argv[6]) : 0); + if (argc < 4) + { + std::cerr << "Missing parameters." << std::endl; + std::cerr << "Usage: " << std::endl; + std::cerr << itkNameOfTestExecutableMacro(argv) + << " [timeIndex] [channelIndex] [datasetIndex]" << std::endl; + return EXIT_FAILURE; + } + const char * inputFileName = argv[1]; + const char * outputFileName = argv[2]; + const size_t imageDimension = std::atoi(argv[3]); + const size_t timeIndex = (argc > 4 ? std::atoi(argv[4]) : 0); + const size_t channelIndex = (argc > 5 ? std::atoi(argv[5]) : 0); + const size_t datasetIndex = (argc > 6 ? std::atoi(argv[6]) : 0); - if (imageDimension == 2) - { - doRead(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex); - } - else if (imageDimension == 3) - { - doRead(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex); - } - else - { - throw std::invalid_argument("Received an invalid test case"); - } + if (imageDimension == 2) + { + doRead(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex); + } + else if (imageDimension == 3) + { + doRead(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex); + } + else + { + throw std::invalid_argument("Received an invalid test case"); + } - return EXIT_SUCCESS; + return EXIT_SUCCESS; }