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

[MessagePassing] Fix OSError on read-only file systems #9032

Merged
merged 31 commits into from
Mar 8, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

- Fixed `OSError` on read-only file systems within `MessagePassing` ([#9032](https://github.com/pyg-team/pytorch_geometric/pull/9032))
- Fixed metaclass conflict in `Dataset` ([#8999](https://github.com/pyg-team/pytorch_geometric/pull/8999))
- Fixed import errors on `MessagePassing` modules with nested inheritance ([#8973](https://github.com/pyg-team/pytorch_geometric/pull/8973))

Expand Down
11 changes: 0 additions & 11 deletions torch_geometric/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,6 @@ def collect_param_data(

# Inspecting Method Bodies ################################################

@property
def can_read_source(self) -> bool:
r"""Returns :obj:`True` if able to read the source file of the
inspected class.
"""
try:
inspect.getfile(self._cls)
return True
except Exception:
return False

def get_source(self, cls: Optional[Type] = None) -> str:
r"""Returns the source code of :obj:`cls`."""
cls = cls or self._cls
Expand Down
9 changes: 4 additions & 5 deletions torch_geometric/nn/conv/message_passing.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(
jinja_prefix = f'{self.__module__}_{self.__class__.__name__}'
# Optimize `propagate()` via `*.jinja` templates:
if not self.propagate.__module__.startswith(jinja_prefix):
if self.inspector.can_read_source:
try:
module = module_from_template(
module_name=f'{jinja_prefix}_propagate',
template_path=osp.join(root_dir, 'propagate.jinja'),
Expand All @@ -190,15 +190,14 @@ def __init__(

self.__class__.propagate = module.propagate
self.__class__.collect = module.collect
else:
except Exception: # pragma: no cover
self.__class__._orig_propagate = self.__class__.propagate
self.__class__._jinja_propagate = self.__class__.propagate

# Optimize `edge_updater()` via `*.jinja` templates (if implemented):
if (self.inspector.implements('edge_update')
and not self.edge_updater.__module__.startswith(jinja_prefix)):
if self.inspector.can_read_source:

try:
module = module_from_template(
module_name=f'{jinja_prefix}_edge_updater',
template_path=osp.join(root_dir, 'edge_updater.jinja'),
Expand All @@ -216,7 +215,7 @@ def __init__(

self.__class__.edge_updater = module.edge_updater
self.__class__.edge_collect = module.edge_collect
else:
except Exception: # pragma: no cover
self.__class__._orig_edge_updater = self.__class__.edge_updater
self.__class__._jinja_edge_updater = (
self.__class__.edge_updater)
Expand Down
Loading