Skip to content

Commit

Permalink
Workaround for generated torch.ops modules
Browse files Browse the repository at this point in the history
  • Loading branch information
imakunin committed Oct 20, 2023
1 parent 7f3b3e3 commit fe9ae70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
16 changes: 10 additions & 6 deletions pylzy/lzy/env/explorer/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
get_requirements_to_meta_packages,
get_name_from_requirement_string,
check_distribution_is_meta_package,
check_url_is_local_file,
check_url_is_local_file, is_wellknown_fake_module,
)


Expand Down Expand Up @@ -78,28 +78,32 @@ def _classify_modules(
"""
Here we are dividing modules into two piles:
those which are part of some distribution and those which are not.
Also here we are noting distributions with binary modules.
Also, here we are noting distributions with binary modules.
"""
for module in modules:
module_name = module.__name__
top_level: str = module_name.split('.')[0]
filename = getattr(module, '__file__', None)

# Modules without __file__ doesn't represent specific file at the disk
# so we a generally doesn't interested about it.
# Modules without __file__ doesn't represent specific file at the disk,
# so we are generally not interested about it.
# It can be namespace modules or strange virtual modules as the `six.moves.*`.
# It's totally okay that we are skipping it and don't require any warning,
# because we should process such distributions by other signes.
# because we should process such distributions by other properties.
if not filename:
continue

# We also doesn't interested in standard modules
# We also not interested in standard modules
if (
top_level in self.stdlib_module_names or
top_level in self.builtin_module_names
):
continue

# ... and fake modules
if is_wellknown_fake_module(top_level, filename):
continue

distribution = self.files_to_distributions.get(filename)
if distribution and not self._check_distribution_is_editable(distribution):
distributions.add(distribution)
Expand Down
9 changes: 8 additions & 1 deletion pylzy/lzy/env/explorer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_files_to_distributions() -> Dict[str, Distribution]:

def check_distribution_is_meta_package(distribution: Distribution) -> bool:
if not distribution.files:
# NB: .egg-info packages and some apt-packages doensn't have
# NB: .egg-info packages and some apt-packages doesn't have
# a dist-info directory and importlib.metadata fails to generate
# files list
return False
Expand Down Expand Up @@ -171,3 +171,10 @@ def get_requirements_to_meta_packages() -> Dict[str, List[Distribution]]:
result[name].append(distribution)

return dict(result)


def is_wellknown_fake_module(top_level_module_name: str, module_filename: str) -> bool:
if top_level_module_name == 'torch':
if module_filename in ['torch.ops', '_ops.py', '_classes.py']:
return True
return False
2 changes: 1 addition & 1 deletion pylzy/lzy/version/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.15.0
1.15.0rc3

0 comments on commit fe9ae70

Please sign in to comment.