File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ def add_pkgutil_style_namespace_pkg_init(dir_path: str) -> None:
8484
8585 if os .path .isfile (ns_pkg_init_filepath ):
8686 raise ValueError ("%s already contains an __init__.py file." % dir_path )
87+ if not os .path .exists (dir_path ):
88+ os .makedirs (dir_path )
8789 with open (ns_pkg_init_filepath , "w" ) as ns_pkg_init_f :
8890 # See https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
8991 ns_pkg_init_f .write (
Original file line number Diff line number Diff line change @@ -131,5 +131,13 @@ def test_empty_case(self):
131131 self .assertEqual (actual , set ())
132132
133133
134+ class TestaddPkgutilStyleNamespacePkgInit (unittest .TestCase ):
135+ def test_missing_directory_is_created (self ):
136+ directory = TempDir ()
137+ missing_directory = pathlib .Path (directory .root ()) / "missing_directory"
138+ namespace_pkgs .add_pkgutil_style_namespace_pkg_init (str (missing_directory ))
139+ self .assertTrue (missing_directory .is_dir ())
140+
141+
134142if __name__ == "__main__" :
135143 unittest .main ()
You can’t perform that action at this time.
0 commit comments