Skip to content

Commit

Permalink
Merge pull request #1448 from pyiron/replace_deprecated_disutils
Browse files Browse the repository at this point in the history
Replace copy_tree from distutils by copytree from shutil because dist…
  • Loading branch information
samwaseda committed May 25, 2024
2 parents d736bb4 + 5b2ad9d commit 37a3d90
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
5 changes: 2 additions & 3 deletions pyiron_base/project/archiving/import_archive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import pandas
import numpy as np
from shutil import rmtree
from distutils.dir_util import copy_tree
from shutil import rmtree, copytree
import tarfile
from pyiron_base.project.archiving.shared import getdir
from pyiron_base.utils.instance import static_isinstance
Expand Down Expand Up @@ -57,7 +56,7 @@ def import_jobs(project_instance, archive_directory, df, compressed=True):
des = project_instance.path
# source folder; archive folder
src = os.path.abspath(archive_directory)
copy_tree(src, des)
copytree(src, des, dirs_exist_ok=True)
if compressed:
rmtree(src)

Expand Down
2 changes: 1 addition & 1 deletion pyiron_base/state/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
from configparser import ConfigParser
from pyiron_base.state.logger import logger
from pyiron_base.state.publications import publications
from pyiron_base.utils.strtobool import strtobool
from pathlib import Path
from pyiron_base.interfaces.singleton import Singleton
from typing import Union, Dict, List
from distutils.util import strtobool
from copy import deepcopy

__author__ = "Jan Janssen, Liam Huber"
Expand Down
39 changes: 39 additions & 0 deletions pyiron_base/utils/strtobool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

"""
Utility functions used in pyiron.
In order to be accessible from anywhere in pyiron, they *must* remain free of
any imports from pyiron!
"""

__author__ = "Joerg Neugebauer, Jan Janssen"
__copyright__ = (
"Copyright 2020, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "production"
__date__ = "Sep 1, 2017"


def strtobool(val: str):
"""Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
Originally part of `distutils.util.strtobool`, but copied and pasted as
`distutils` was going to be removed from python 3.12.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return 1
elif val in ("n", "no", "f", "false", "off", "0"):
return 0
else:
raise ValueError("invalid truth value %r" % (val,))
19 changes: 19 additions & 0 deletions tests/utils/test_strtobool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from pyiron_base.utils.strtobool import strtobool


class TestStrtobool(unittest.TestCase):
def test_letters(self):
for val in ("y", "yes", "t", "true", "on", "1"):
self.assertTrue(strtobool(val))
for val in ("Y", "YEs", "T", "tRue", "oN", "1"):
self.assertTrue(strtobool(val))
for val in ("n", "no", "f", "false", "off", "0"):
self.assertFalse(strtobool(val))
with self.assertRaises(ValueError):
strtobool("Vegetarians do not eat Bratwurst")


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

0 comments on commit 37a3d90

Please sign in to comment.