-
Notifications
You must be signed in to change notification settings - Fork 34
Control over Fortran file extensions recognised by ModuleManager
#3469
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
Open
mn416
wants to merge
6
commits into
master
Choose a base branch
from
mn416-fortran-file-exts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−7
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
578b976
Control over Fortran file extensions recognised by `ModuleManager`
mn416 0734da1
Another `ModuleManager` test, for coverage
mn416 26be2c2
Preserve existing behaviour exactly in `ModuleManager`'s "doesn't nee…
mn416 a10202d
Fix new "doesn't need preprocessing" check in `ModuleManager`
mn416 5321b24
Merge branch 'master' into mn416-fortran-file-exts
LonelyCat124 636f73c
Add .f95, .F95, .f03, and .F03 to the default set of file extensions …
mn416 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,10 @@ def __init__(self): | |
| self._module_pattern = re.compile(r"^\s*module\s+([a-z]\S*)\s*$", | ||
| flags=re.IGNORECASE | re.MULTILINE) | ||
|
|
||
| # Files with an extension from this set will be considered | ||
| # when searching for Fortran files | ||
| self._fortran_file_exts = {".F90", ".f90", ".X90", ".x90"} | ||
|
|
||
| @property | ||
| def cache_active(self) -> bool: | ||
| ''' | ||
|
|
@@ -210,6 +214,28 @@ def resolve_indirect_imports(self, value: Union[bool, Iterable[str]]): | |
| f"str, but found an item of {type(x)}") | ||
| self._resolve_indirect_imports = value | ||
|
|
||
| @property | ||
| def fortran_file_exts(self) -> set[str]: | ||
| ''' | ||
| :returns: the set of file extensions that are considered when | ||
| searching for Fortran files. | ||
| ''' | ||
| return self._fortran_file_exts | ||
|
|
||
| @fortran_file_exts.setter | ||
| def fortran_file_exts(self, exts: set[str]): | ||
| ''' | ||
| :param exts: the set of file extensions that are considered when | ||
| searching for Fortran files. | ||
|
|
||
| :raises TypeError: if the provided value is not a set. | ||
| ''' | ||
| if not isinstance(exts, set): | ||
| raise TypeError( | ||
| f"'fortran_file_exts' must be a set, but found " | ||
| f"{type(exts).__name__}") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually @mn416 one minor formatting thing - would you mind adjust this to before I merge? I can't merge this until after our release anyway |
||
| self._fortran_file_exts = exts | ||
|
|
||
| # ------------------------------------------------------------------------ | ||
| def add_search_path(self, | ||
| directories: Union[str, Path, | ||
|
|
@@ -254,7 +280,7 @@ def add_search_path(self, | |
| # ------------------------------------------------------------------------ | ||
| def _add_all_files_from_dir(self, directory: str) -> list[FileInfo]: | ||
| '''This function creates (and caches) FileInfo objects for all files | ||
| with an extension of (F/f/X/x)90 in the given directory that have | ||
| with a Fortran file extension in the given directory that have | ||
| not previously been visited. The new FileInfo objects are returned. | ||
|
|
||
| :param directory: the directory containing Fortran files | ||
|
|
@@ -269,7 +295,7 @@ def _add_all_files_from_dir(self, directory: str) -> list[FileInfo]: | |
| for entry in all_entries: | ||
| _, ext = os.path.splitext(entry.name) | ||
| if (not entry.is_file() or | ||
| ext not in [".F90", ".f90", ".X90", ".x90"]): | ||
| ext not in self._fortran_file_exts): | ||
| continue | ||
| full_path = os.path.join(directory, entry.name) | ||
| if full_path in self._visited_files: | ||
|
|
@@ -321,7 +347,7 @@ def _find_module_in_files( | |
| self._modules[name] = mod_info | ||
| # A file that has been (or does not require) | ||
| # preprocessing always takes precedence. | ||
| if finfo.filename.endswith(".f90"): | ||
| if self._doesnt_need_preprocessing(finfo.filename): | ||
| return mod_info | ||
| return mod_info | ||
|
|
||
|
|
@@ -490,6 +516,19 @@ def all_file_infos(self) -> list[FileInfo]: | |
| """ | ||
| return list(self._filepath_to_file_info.values()) | ||
|
|
||
| def _doesnt_need_preprocessing(self, filename: str) -> bool: | ||
| """Returns True if the file with the given filename | ||
| doesn't need preprocessing.""" | ||
| # The current method is just to check that the file extension | ||
| # is a lower-case Fortran file extension and doesn't begin | ||
| # with '.x'. (The latter condition is present to preserve | ||
| # previous behaviour, although it's unclear if that behavior | ||
| # is indeed desired.) | ||
| base, ext = os.path.splitext(filename) | ||
| return (ext in self._fortran_file_exts and | ||
| ext.islower() and | ||
| not ext.startswith(".x")) | ||
|
|
||
| def get_module_info(self, module_name: str) -> Optional[ModuleInfo]: | ||
| """This function returns the ModuleInfo for the specified | ||
| module. | ||
|
|
@@ -509,16 +548,15 @@ def get_module_info(self, module_name: str) -> Optional[ModuleInfo]: | |
| return None | ||
|
|
||
| # First check if we have already seen this module. We only end the | ||
| # search early if the file we've found does not require pre-processing | ||
| # (i.e. has a .f90 suffix). | ||
| # search early if the file we've found does not require pre-processing. | ||
| mod_info = self._modules.get(mod_lower, None) | ||
| if mod_info and mod_info.filename.endswith(".f90"): | ||
| if mod_info and self._doesnt_need_preprocessing(mod_info.filename): | ||
| return mod_info | ||
| old_mod_info = mod_info | ||
| # Are any of the files that we've already seen a good match? | ||
| mod_info = self._find_module_in_files(mod_lower, | ||
| self._visited_files.values()) | ||
| if mod_info and mod_info.filename.endswith(".f90"): | ||
| if mod_info and self._doesnt_need_preprocessing(mod_info.filename): | ||
| return mod_info | ||
| old_mod_info = mod_info | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.