[package] remove PackageExporter.file_structure (#57339)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57339

After the `intern` changes, we will no longer eager write to the package
archive so `file_structure` as written doesn't make much sense.

Differential Revision: D28114187

Test Plan: Imported from OSS

Reviewed By: anjali411

Pulled By: suo

fbshipit-source-id: 875595db933e9d1b2fdde907b086889cc977e92f
This commit is contained in:
Michael Suo
2021-05-05 17:54:20 -07:00
committed by Facebook GitHub Bot
parent f326f7dda8
commit a3cba770b5
2 changed files with 26 additions and 41 deletions

View File

@ -28,6 +28,9 @@ class TestMisc(PackageTestCase):
export_plain = dedent(
"""\
├── .data
│ ├── extern_modules
│ └── version
├── main
│ └── main
├── obj
@ -73,25 +76,27 @@ class TestMisc(PackageTestCase):
he.save_pickle("obj", "obj.pkl", obj)
he.save_text("main", "main", "my string")
export_file_structure = he.file_structure()
# remove first line from testing because WINDOW/iOS/Unix treat the buffer differently
self.assertEqual(
dedent("\n".join(str(export_file_structure).split("\n")[1:])),
export_plain,
)
export_file_structure = he.file_structure(
include=["**/subpackage.py", "**/*.pkl"]
)
self.assertEqual(
dedent("\n".join(str(export_file_structure).split("\n")[1:])),
export_include,
)
buffer.seek(0)
hi = PackageImporter(buffer)
import_file_structure = hi.file_structure(exclude="**/*.storage")
file_structure = hi.file_structure()
# remove first line from testing because WINDOW/iOS/Unix treat the buffer differently
self.assertEqual(
dedent("\n".join(str(import_file_structure).split("\n")[1:])),
dedent("\n".join(str(file_structure).split("\n")[1:])),
export_plain,
)
file_structure = hi.file_structure(
include=["**/subpackage.py", "**/*.pkl"]
)
self.assertEqual(
dedent("\n".join(str(file_structure).split("\n")[1:])),
export_include,
)
file_structure = hi.file_structure(exclude="**/*.storage")
self.assertEqual(
dedent("\n".join(str(file_structure).split("\n")[1:])),
import_exclude,
)
@ -106,9 +111,12 @@ class TestMisc(PackageTestCase):
obj = package_a.subpackage.PackageASubpackageObject()
he.save_pickle("obj", "obj.pkl", obj)
export_file_structure = he.file_structure()
self.assertTrue(export_file_structure.has_file("package_a/subpackage.py"))
self.assertFalse(export_file_structure.has_file("package_a/subpackage"))
buffer.seek(0)
importer = PackageImporter(buffer)
file_structure = importer.file_structure()
self.assertTrue(file_structure.has_file("package_a/subpackage.py"))
self.assertFalse(file_structure.has_file("package_a/subpackage"))
def test_is_from_package(self):
"""is_from_package should work for objects and modules"""

View File

@ -26,7 +26,6 @@ from ._importlib import _normalize_path
from ._mangling import is_mangled
from ._package_pickler import create_pickler
from ._stdlib import is_stdlib_module
from .file_structure_representation import Directory, _create_directory_from_file_list
from .find_file_dependencies import find_files_source_depends_on
from .glob_group import GlobGroup, GlobPattern
from .importer import Importer, OrderedImporter, sys_importer
@ -186,28 +185,6 @@ class PackageExporter:
dependencies,
)
def file_structure(
self, *, include: "GlobPattern" = "**", exclude: "GlobPattern" = ()
) -> Directory:
"""Creates and returns a :class:`Directory` file structure representation of package's zipfile.
Args:
include (Union[List[str], str]): An optional string e.g. "my_package.my_subpackage", or optional list of strings
for the names of the files to be inluded in the zipfile representation. This can also be
a glob-style pattern, as described in :meth:`mock`
exclude (Union[List[str], str]): An optional pattern that excludes files whose name match the pattern.
Returns:
:class:`Directory`
"""
return _create_directory_from_file_list(
self.zip_file.archive_name(),
self.zip_file.get_all_written_records(),
include,
exclude,
)
def get_unique_id(self) -> str:
"""Get an id. This id is guaranteed to only be handed out once for this package."""
ret = str(self._unique_id)