From 7a2a60f34719be5a2c5d3abb5e858b2bee7cc79b Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 7 Mar 2022 12:48:13 +0100 Subject: [PATCH 1/6] Use trexio int types in Fortran tests --- tests/test_f.f90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_f.f90 b/tests/test_f.f90 index bc227ad..421ed0b 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -51,9 +51,9 @@ subroutine test_write(file_name, back_end) character*(*), intent(in) :: file_name integer, intent(in) :: back_end - integer(8) :: trex_file + integer(trexio_t) :: trex_file - integer :: rc = 1 + integer(trexio_exit_code) :: rc = 1 integer :: num, basis_shell_num @@ -186,10 +186,10 @@ subroutine test_read(file_name, back_end) character*(*), intent(in) :: file_name integer, intent(in) :: back_end - integer(8) :: trex_file + integer(trexio_t) :: trex_file integer :: i, j, k, ind, offset, flag - integer :: rc = 1 + integer(trexio_exit_code) :: rc = 1 integer :: num, num_read, basis_shell_num integer :: basis_nucleus_index(24) From 0e75cb42b582e662c8b46375da8b1b2b63c66d8d Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 7 Mar 2022 14:12:31 +0100 Subject: [PATCH 2/6] Add support for Python with statement (see PEP 343 for more details) --- python/test/test_api.py | 25 ++++++++++++++++++------- src/templates_front/templator_front.org | 19 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/python/test/test_api.py b/python/test/test_api.py index f3ee2d5..e347c35 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -32,7 +32,7 @@ try: elif TEST_TREXIO_BACKEND == trexio.TREXIO_TEXT: shutil.rmtree(output_filename) except: - print ('Nothing to remove.') + print('Nothing to remove.') #=========================================================# #============ WRITE THE DATA IN THE TEST FILE ============# @@ -40,6 +40,17 @@ except: trexio.info() + +# test with ... as ... block +with trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) as tfile: + trexio.write_metadata_description(tfile, "Test file produced by the Python API") + assert trexio.has_metadata_description(tfile) + assert tfile.isOpen + +# the file handle can remain existing but the file itself is closed upon exit from the `with` block +assert not tfile.isOpen + + # create TREXIO file and open it for writing test_file = trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) assert test_file.exists @@ -281,7 +292,7 @@ assert rpoint_group==point_group # another way to read only if the variable exists if trexio.has_ao_num(test_file2): - rmo_num = trexio.read_ao_num(test_file2) + rao_num = trexio.read_ao_num(test_file2) else: print("Pass on reading the non-existing variable ao_num: checked") @@ -290,12 +301,12 @@ else: # cleaning (remove the TREXIO file) try: - if TEST_TREXIO_BACKEND == trexio.TREXIO_HDF5: - os.remove(output_filename) - elif TEST_TREXIO_BACKEND == trexio.TREXIO_TEXT: - shutil.rmtree(output_filename) + if TEST_TREXIO_BACKEND == trexio.TREXIO_HDF5: + os.remove(output_filename) + elif TEST_TREXIO_BACKEND == trexio.TREXIO_TEXT: + shutil.rmtree(output_filename) except: - print (f'No output file {output_filename} has been produced') + print(f'No output file {output_filename} has been produced') #==========================================================# diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index ad8eacb..b678704 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -720,8 +720,7 @@ class File: def __init__(self, filename, mode='r', back_end=TREXIO_HDF5, pytrexio_s=None, info=None): - """This is a TREXIO File constructor.""" - + """TREXIO File class constructor.""" self.filename = filename self.mode = mode self.back_end = back_end @@ -740,9 +739,19 @@ class File: self.info = info + def __enter__(self): + """Enter statement for with ... as ... handling.""" + return self + + + def __exit__(self, *args): + """Exit statement for with ... as ... handling.""" + if self.isOpen: + self.close() + + def close(self): """Close a TREXIO File.""" - if self.isOpen: _close(self.pytrexio_s) self.isOpen = False @@ -752,13 +761,11 @@ class File: def inquire(self): """Inquire whether a TREXIO file exists.""" - self.exists = _inquire(self.filename) def __del__(self): - """This is a TREXIO File destructor.""" - + """TREXIO File class destructor.""" if self.isOpen: _close(self.pytrexio_s) elif self.isOpen is None: From f9908b21a03aa05012ebd25ce1bd7abc82bedb08 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 7 Mar 2022 14:18:29 +0100 Subject: [PATCH 3/6] Update ChangeLog --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index e73227b..1335fa7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ CHANGES 2.2 --- +- Added support for Python-ic `with` statements - Merged local and non-local pseudopotential integrals in #86 - Fixed backwards incompatibility of the `TREXIO_TEXT` back end in #82 - Added `TREXIO_AUTO` back end for read-only mode (`r`) in PR #80 From de9c8fad1fc750a35ff8ea6fa7ac83bebd39688d Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 7 Mar 2022 14:34:23 +0100 Subject: [PATCH 4/6] Run CI workflows on each GitHub release --- .github/workflows/actions.yml | 10 ++++++---- .github/workflows/build-wheels.yml | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f0570fb..7a23aa0 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,12 +2,14 @@ name: TREXIO CI on: push: - branches: [ master ] + branches: + - master + tags: + # After vMajor.Minor.Patch _anything_ is allowed (without "/") ! + - v[0-9]+.[0-9]+.[0-9]+* pull_request: branches: [ master ] - release: - types: - - published + jobs: diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 5baf3d7..f6b8ded 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -38,7 +38,7 @@ jobs: needs: get_commit_message if: >- contains(needs.get_commit_message.outputs.message, '[wheel build]') || - github.event_name == 'release' + (github.repository == 'TREX-CoE/trexio' && startsWith(github.ref, 'refs/tags/v')) runs-on: ubuntu-latest strategy: matrix: @@ -99,7 +99,7 @@ jobs: needs: get_commit_message if: >- contains(needs.get_commit_message.outputs.message, '[wheel build]') || - github.event_name == 'release' + (github.repository == 'TREX-CoE/trexio' && startsWith(github.ref, 'refs/tags/v')) runs-on: ${{ matrix.os }} strategy: matrix: From 823372aa8905ca6d199fd7c2bf6093bfedbee436 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 7 Mar 2022 14:39:06 +0100 Subject: [PATCH 5/6] Align Python API version with the upstream C --- python/pytrexio/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index 6849410..c68196d 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.1.0" +__version__ = "1.2.0" From 54884358e55703cbaae7e80c70c4adb1730f4aa2 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 11 Mar 2022 13:53:11 +0100 Subject: [PATCH 6/6] Update docs on the HDF5 dataset naming issue --- trex.org | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trex.org b/trex.org index 61233c9..4c03d41 100644 --- a/trex.org +++ b/trex.org @@ -181,7 +181,11 @@ ECP that replaces the core electrons. *Note for developers*: avoid having variables with similar prefix in their name. HDF5 back end might cause issues due to the way ~find_dataset~ function works. For example, in the ECP group we use ~max_ang_mom~ and not ~ang_mom_max~. -The latter causes issues when written before ~ang_mom~ in the TREXIO file. +The latter causes issues when written before the ~ang_mom~ array in the TREXIO file. +*Update*: in fact, the aforementioned issue has only been observed when using HDF5 version 1.10.4 +installed via ~apt-get~. Installing the same version from the ~conda-forge~ channel and running it in +an isolated ~conda~ environment works just fine. Thus, it seems to be a bug in the ~apt~-provided package. +If you encounter the aforementioned issue, please report it to our [[https://github.com/TREX-CoE/trexio/issues][issue tracker on GitHub]]. #+CALL: json(data=ecp, title="ecp")