MLECO-3036: Update to use Pathlib in Python scripts
* Pathlib used in Python scripts over os
* Bug fix for build_default.py
* Minor code style updates
Signed-off-by: Richard Burton <richard.burton@arm.com>
Change-Id: I5fc2e582a84443c3fb79250eb711b960d63ed8fd
diff --git a/scripts/py/check_update_resources_downloaded.py b/scripts/py/check_update_resources_downloaded.py
index 44e9bd9..021f1b1 100644
--- a/scripts/py/check_update_resources_downloaded.py
+++ b/scripts/py/check_update_resources_downloaded.py
@@ -13,11 +13,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
import json
-import os
import sys
import hashlib
from argparse import ArgumentParser
+from pathlib import Path
def get_md5sum_for_file(filepath: str) -> str:
@@ -51,11 +52,9 @@
set_up_script_path (string): Specifies the path to set_up_default_resources.py file.
"""
- metadata_file_path = os.path.join(
- resource_downloaded_dir, "resources_downloaded_metadata.json"
- )
+ metadata_file_path = Path(resource_downloaded_dir) / "resources_downloaded_metadata.json"
- if os.path.isfile(metadata_file_path):
+ if metadata_file_path.is_file():
with open(metadata_file_path) as metadata_json:
metadata_dict = json.load(metadata_json)
@@ -95,8 +94,8 @@
required=True)
args = parser.parse_args()
- # Check validity of script path
- if not os.path.isfile(args.setup_script_path):
+ # Check validity of script path.
+ if not Path(args.setup_script_path).is_file():
raise ValueError(f'Invalid script path: {args.setup_script_path}')
# Check the resources are downloaded as expected