Skip to content

Commit

Permalink
Remove mkdtemp.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Oct 20, 2021
1 parent 6020389 commit d427476
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/manifests_workflow/input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update(self, min_klass, component_klass, keep=False):
known_versions = self.versions
logging.info(f"Known versions: {known_versions}")
main_versions = {}
with TemporaryDirectory.mkdtemp(keep=keep) as work_dir:
with TemporaryDirectory(keep=keep) as work_dir:
logging.info(f"Checking out components into {work_dir.name}")
os.chdir(work_dir.name)

Expand Down
2 changes: 1 addition & 1 deletion src/run_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
output_dir = os.path.join(os.getcwd(), "bundle")
os.makedirs(output_dir, exist_ok=True)

with TemporaryDirectory.mkdtemp() as work_dir:
with TemporaryDirectory() as work_dir:
logging.info(f"Bundling {build.name} ({build.architecture}) on {build.platform} into {output_dir} ...")

os.chdir(work_dir.name)
Expand Down
2 changes: 1 addition & 1 deletion src/run_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
console.configure(level=args.logging_level)
manifest = InputManifest.from_file(args.manifest)

with TemporaryDirectory.mkdtemp(keep=args.keep) as work_dir:
with TemporaryDirectory(keep=args.keep) as work_dir:
output_dir = os.path.join(os.getcwd(), "artifacts")

logging.info(f"Building in {work_dir.name}")
Expand Down
4 changes: 2 additions & 2 deletions src/run_bwc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
def main():
args = TestArgs()
console.configure(level=args.logging_level)
with TemporaryDirectory.mkdtemp(keep=args.keep) as work_dir:
logging.info("Switching to temporary work_dir: f{work_dir.name}")
with TemporaryDirectory(keep=args.keep) as work_dir:
logging.info(f"Switching to temporary work_dir: {work_dir.name}")
bundle_manifest = BundleManifest.from_s3(
args.s3_bucket,
args.build_id,
Expand Down
2 changes: 1 addition & 1 deletion src/run_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
console.configure(level=args.logging_level)
manifest = InputManifest.from_file(args.manifest)

with TemporaryDirectory(keep=True).mkdtemp() as work_dir:
with TemporaryDirectory(keep=True) as work_dir:
logging.info(f"Checking out into {work_dir.name}")

os.chdir(work_dir.name)
Expand Down
2 changes: 1 addition & 1 deletion src/run_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():

target = CiTarget(version=manifest.build.version, snapshot=args.snapshot)

with TemporaryDirectory.mkdtemp(keep=args.keep) as work_dir:
with TemporaryDirectory(keep=args.keep) as work_dir:
logging.info(f"Sanity-testing in {work_dir.name}")

os.chdir(work_dir.name)
Expand Down
2 changes: 1 addition & 1 deletion src/run_integ_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
for component in test_manifest.components:
if component.integ_test is not None:
integ_test_config[component.name] = component
with TemporaryDirectory.mkdtemp(keep=args.keep) as work_dir:
with TemporaryDirectory(keep=args.keep) as work_dir:
logging.info(f"Switching to temporary work_dir: {work_dir.name}")
test_recorder = TestRecorder(args.test_run_id, "integ-test", work_dir.name)
os.chdir(work_dir.name)
Expand Down
2 changes: 1 addition & 1 deletion src/run_perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_infra_repo_url():


def main():
with TemporaryDirectory.mkdtemp(keep=args.keep) as work_dir:
with TemporaryDirectory(keep=args.keep) as work_dir:
os.chdir(work_dir.name)
current_workspace = os.path.join(work_dir.name, "infra")
GitRepository(get_infra_repo_url(), "main", current_workspace)
Expand Down
4 changes: 0 additions & 4 deletions src/system/temporary_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,3 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
else:
logging.debug(f"Removing {self.name}")
shutil.rmtree(self.name)

@classmethod
def mkdtemp(cls, keep=False):
return cls(keep)
2 changes: 1 addition & 1 deletion tests/test_run_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_usage(self, *mocks):
@patch("run_assemble.TemporaryDirectory")
@patch("shutil.copy2")
def test_main(self, mock_copy, mock_temp, mock_recorder, mock_bundles, *mocks):
mock_temp.return_value.__enter__.return_value = tempfile.gettempdir()
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
mock_bundle = MagicMock(archive_path="path")
mock_bundles.create.return_value = mock_bundle

Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_usage(self):
@patch("run_build.Builder", return_value=MagicMock())
@patch("run_build.BuildRecorder", return_value=MagicMock())
@patch("run_build.GitRepository")
@patch("run_build.TemporaryDirectory.mkdtemp")
@patch("run_build.TemporaryDirectory")
def test_main(self, mock_temp, mock_repo, mock_recorder, mock_builder, *mocks):
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
repo = MagicMock(name="dummy")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_usage(self):

@patch("argparse._sys.argv", ["run_checkout.py", OPENSEARCH_MANIFEST])
@patch("run_checkout.GitRepository")
@patch("run_checkout.TemporaryDirectory.mkdtemp")
@patch("run_checkout.TemporaryDirectory")
def test_main(self, mock_temp, mock_repo):
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
mock_repo.return_value.__enter__.return_value = MagicMock(working_directory="dummy")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_usage(self):
@patch("argparse._sys.argv", ["run_ci.py", OPENSEARCH_MANIFEST])
@patch("run_ci.Ci", return_value=MagicMock())
@patch("run_ci.GitRepository", return_value=MagicMock(working_directory="dummy"))
@patch("run_ci.TemporaryDirectory.mkdtemp")
@patch("run_ci.TemporaryDirectory")
def test_main(self, mock_temp, mock_repo, mock_ci, *mocks):
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()

Expand Down
4 changes: 2 additions & 2 deletions tests/tests_assemble_workflow/test_bundle_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_get_manifest(self):
)

def test_write_manifest(self):
with TemporaryDirectory.mkdtemp() as dest_dir:
with TemporaryDirectory() as dest_dir:
self.bundle_recorder.write_manifest(dest_dir.name)
manifest_path = os.path.join(dest_dir.name, "manifest.yml")
self.assertTrue(os.path.isfile(manifest_path))
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_get_manifest(self):
)

def test_write_manifest(self):
with TemporaryDirectory.mkdtemp() as dest_dir:
with TemporaryDirectory() as dest_dir:
self.bundle_recorder.write_manifest(dest_dir.name)
manifest_path = os.path.join(dest_dir.name, "manifest.yml")
self.assertTrue(os.path.isfile(manifest_path))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_build_workflow/test_build_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_get_manifest(self):
)

def test_write_manifest(self):
with TemporaryDirectory.mkdtemp() as dest_dir:
with TemporaryDirectory() as dest_dir:
mock = self.__mock(snapshot=False)
mock.target.output_dir = dest_dir.name
mock.write_manifest()
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_system/test_temporary_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

class TestTemporaryDirectory(unittest.TestCase):
def test_mkdtemp_keep_true(self):
with TemporaryDirectory.mkdtemp(keep=True) as work_dir:
with TemporaryDirectory(keep=True) as work_dir:
self.assertTrue(os.path.exists(work_dir.name))
self.assertTrue(os.path.exists(work_dir.name))

def test_mkdtemp_keep_false(self):
with TemporaryDirectory.mkdtemp() as work_dir:
with TemporaryDirectory() as work_dir:
self.assertTrue(os.path.exists(work_dir.name))
self.assertFalse(os.path.exists(work_dir.name))
2 changes: 1 addition & 1 deletion tests/tests_test_workflow/test_test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUp(self):
)

def test_checkout(self):
with TemporaryDirectory.mkdtemp() as tmpdir:
with TemporaryDirectory() as tmpdir:
subdir = os.path.join(tmpdir.name, ".github")
repo = self.test_component.checkout(subdir)
self.assertEqual(repo.url, "https://github.com/opensearch-project/.github")
Expand Down

0 comments on commit d427476

Please sign in to comment.