This repository was archived by the owner on Oct 20, 2020. It is now read-only.
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:
84
84
85
85
if os .path .isfile (ns_pkg_init_filepath ):
86
86
raise ValueError ("%s already contains an __init__.py file." % dir_path )
87
+ if not os .path .exists (dir_path ):
88
+ os .makedirs (dir_path )
87
89
with open (ns_pkg_init_filepath , "w" ) as ns_pkg_init_f :
88
90
# See https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
89
91
ns_pkg_init_f .write (
Original file line number Diff line number Diff line change @@ -131,5 +131,13 @@ def test_empty_case(self):
131
131
self .assertEqual (actual , set ())
132
132
133
133
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
+
134
142
if __name__ == "__main__" :
135
143
unittest .main ()
You can’t perform that action at this time.
0 commit comments