Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
create missing directory when creating package init file (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-fleischmann authored Apr 21, 2020
1 parent 825ca18 commit 9c03622
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extract_wheels/lib/namespace_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def add_pkgutil_style_namespace_pkg_init(dir_path: str) -> None:

if os.path.isfile(ns_pkg_init_filepath):
raise ValueError("%s already contains an __init__.py file." % dir_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
with open(ns_pkg_init_filepath, "w") as ns_pkg_init_f:
# See https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
ns_pkg_init_f.write(
Expand Down
8 changes: 8 additions & 0 deletions extract_wheels/lib/namespace_pkgs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,13 @@ def test_empty_case(self):
self.assertEqual(actual, set())


class TestaddPkgutilStyleNamespacePkgInit(unittest.TestCase):
def test_missing_directory_is_created(self):
directory = TempDir()
missing_directory = pathlib.Path(directory.root()) / "missing_directory"
namespace_pkgs.add_pkgutil_style_namespace_pkg_init(str(missing_directory))
self.assertTrue(missing_directory.is_dir())


if __name__ == "__main__":
unittest.main()

1 comment on commit 9c03622

@alexeagle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, good news, your commit is going upstream to rules_python!

Could you please confirm you're okay with your work being upstreamed by replying @googlebot I consent. on
bazelbuild/rules_python#348

Please sign in to comment.