Skip to content

Commit

Permalink
Fix deprecated symbol loading in zipped deployments (#39)
Browse files Browse the repository at this point in the history
torchfix currentyl uses standard filesystem methods to find and load the
deprecated symbols data from disk. When running flake8 as zipped
deployments, this fails because the data is not accessible as a standard
filesystem path.

This replaces the filesystem usage with stdlib `pkgutil.get_data()` [1]
that is capable of resolving the data file within the zip deployment,
and loading that data using the correct internal mechanisms.

1: https://docs.python.org/3/library/pkgutil.html#pkgutil.get_data
  • Loading branch information
amyreese authored Apr 17, 2024
1 parent 3387070 commit 04bab2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion torchfix/torchfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

__version__ = "0.4.0"

DEPRECATED_CONFIG_PATH = Path(__file__).absolute().parent / "deprecated_symbols.yaml"
DEPRECATED_CONFIG_PATH = "deprecated_symbols.yaml"

DISABLED_BY_DEFAULT = ["TOR3", "TOR4", "TOR9"]

Expand Down
7 changes: 4 additions & 3 deletions torchfix/visitors/deprecated_symbols/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import libcst as cst
import pkgutil
import yaml
from typing import Optional
from collections.abc import Sequence
Expand All @@ -21,9 +22,9 @@ def __init__(self, deprecated_config_path=None):
def read_deprecated_config(path=None):
deprecated_config = {}
if path is not None:
with open(path) as f:
for item in yaml.load(f, yaml.SafeLoader):
deprecated_config[item["name"]] = item
data = pkgutil.get_data("torchfix", path)
for item in yaml.load(data, yaml.SafeLoader):
deprecated_config[item["name"]] = item
return deprecated_config

super().__init__()
Expand Down

0 comments on commit 04bab2c

Please sign in to comment.