Skip to content

Commit

Permalink
Use absolute paths for dependencies (#576)
Browse files Browse the repository at this point in the history
Use absolute paths for dependencies

In order to make the dependencies in the CCPP datatable more usable,
store absolute pathnames where possible.

User interface changes?: Yes
This may require a change in any build system that uses the
dependencies.

Fixes: #575

Testing:
  test removed: None
  unit tests: passed
  system tests: ?
  manual testing: ran Fortran tests

---------

Co-authored-by: Steve Goldhaber <[email protected]>
  • Loading branch information
gold2718 and Steve Goldhaber authored Jul 19, 2024
1 parent 42e892f commit 5f338dd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
8 changes: 8 additions & 0 deletions scripts/metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ def __init__(self, run_env, table_name_in=None, table_type_in=None,
# end if
self.__start_context = ParseContext(context=self.__pobj)
self.__init_from_file(known_ddts, self.__run_env, skip_ddt_check=skip_ddt_check)
# Set absolute path for all dependencies
path = os.path.dirname(self.__pobj.filename)
if self.relative_path:
path = os.path.join(path, self.relative_path)
# end if
for ind, dep in enumerate(self.__dependencies):
self.__dependencies[ind] = os.path.abspath(os.path.join(path, dep))
# end for
# end if

def __init_from_file(self, known_ddts, run_env, skip_ddt_check=False):
Expand Down
2 changes: 1 addition & 1 deletion test/capgen_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ ccpp_files="${ccpp_files},${build_dir}/ccpp/ccpp_ddt_suite_cap.F90"
ccpp_files="${ccpp_files},${build_dir}/ccpp/ccpp_temp_suite_cap.F90"
process_list="adjusting=temp_calc_adjust,setter=temp_set"
module_list="environ_conditions,make_ddt,setup_coeffs,temp_adjust,temp_calc_adjust,temp_set"
dependencies="bar.F90,foo.F90,qux.F90"
dependencies="${scriptdir}/adjust/qux.F90,${scriptdir}/bar.F90,${scriptdir}/foo.F90"
suite_list="ddt_suite;temp_suite"
required_vars_ddt="ccpp_error_code,ccpp_error_message,horizontal_dimension"
required_vars_ddt="${required_vars_ddt},horizontal_loop_begin"
Expand Down
2 changes: 2 additions & 0 deletions test/capgen_test/temp_adjust.meta
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[ccpp-table-properties]
name = temp_adjust
type = scheme
dependencies = qux.F90
relative_path = adjust
[ccpp-arg-table]
name = temp_adjust_run
type = scheme
Expand Down
1 change: 0 additions & 1 deletion test/capgen_test/temp_calc_adjust.meta
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = temp_calc_adjust
type = scheme
dependencies = foo.F90, bar.F90
dependencies = qux.F90
[ccpp-arg-table]
name = temp_calc_adjust_run
type = scheme
Expand Down
22 changes: 13 additions & 9 deletions test/unit_tests/test_metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import os
import unittest

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
SCRIPTS_DIR = os.path.abspath(os.path.join(TEST_DIR, os.pardir, os.pardir, "scripts"))
SAMPLE_FILES_DIR = os.path.join(TEST_DIR, "sample_files")
UNIT_TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DIR = os.path.abspath(os.path.join(UNIT_TEST_DIR, os.pardir))
SCRIPTS_DIR = os.path.abspath(os.path.join(TEST_DIR, os.pardir, "scripts"))
SAMPLE_FILES_DIR = os.path.join(UNIT_TEST_DIR, "sample_files")

if not os.path.exists(SCRIPTS_DIR):
raise ImportError("Cannot find scripts directory")
Expand Down Expand Up @@ -374,11 +375,15 @@ def test_dependencies_rel_path(self):
titles = [elem.table_name for elem in result]

self.assertEqual(len(dependencies), 4)
self.assertIn('machine.F', dependencies, msg="Dependency 'machine.F' is expected but not found")
self.assertIn('physcons.F90', dependencies, msg="Dependency 'physcons.F90' is expected but not found")
self.assertIn('GFDL_parse_tracers.F90', dependencies, msg="Dependency 'GFDL_parse_tracers.F90' is expected but not found")
self.assertIn('rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90', dependencies, \
msg="Header name 'rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90' is expected but not found")
phys_dir = os.path.join(TEST_DIR, "ccpp", "physics", "physics")
self.assertIn(os.path.join(phys_dir, 'machine.F'), dependencies, \
msg="Dependency 'machine.F' is expected but not found")
self.assertIn(os.path.join(phys_dir, 'physcons.F90'), dependencies, \
msg="Dependency 'physcons.F90' is expected but not found")
self.assertIn(os.path.join(phys_dir, 'GFDL_parse_tracers.F90'), dependencies, \
msg="Dependency 'GFDL_parse_tracers.F90' is expected but not found")
self.assertIn(os.path.join(phys_dir, 'rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90'), dependencies, \
msg="Header name 'rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90' is expected but not found")

self.assertIn(rel_path, "../../ccpp/physics/physics")
self.assertEqual(len(result), 1)
Expand All @@ -399,4 +404,3 @@ def test_invalid_table_properties_type(self):

if __name__ == "__main__":
unittest.main()

2 changes: 1 addition & 1 deletion test_prebuild/unit_tests/test_metadata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_MetadataTable_parse_table(tmpdir):
assert metadata_header.table_name == "<name>"
assert metadata_header.table_type == "scheme"
assert metadata_header.relative_path == "path"
assert metadata_header.dependencies == ["a.f", "b.f"]
assert metadata_header.dependencies == [os.path.join(tmpdir, metadata_header.relative_path,"a.f"), os.path.join(tmpdir, metadata_header.relative_path,"b.f")]

# check metadata section
assert len(metadata_header.sections()) == 1
Expand Down

0 comments on commit 5f338dd

Please sign in to comment.