From d3599722bed85049ade6c3722a9254c177948712 Mon Sep 17 00:00:00 2001 From: Pau Andrio Date: Thu, 17 Oct 2024 18:49:55 +0200 Subject: [PATCH] [Typing](ALL): Update typing from python 3.8 style to python 3.9 --- .github/env.yaml | 2 +- biobb_cp2k/cp2k/cp2k_prep.py | 57 ++++++++++++++++++------------------ biobb_cp2k/cp2k/cp2k_run.py | 4 +-- setup.py | 16 +++++----- 4 files changed, 39 insertions(+), 40 deletions(-) diff --git a/.github/env.yaml b/.github/env.yaml index 1cbf069..aadfa2f 100644 --- a/.github/env.yaml +++ b/.github/env.yaml @@ -4,5 +4,5 @@ channels: - bioconda - anaconda dependencies: - - biobb_common ==4.2.0 + - biobb_common ==5.0.0 - cp2k ==7.1.0 diff --git a/biobb_cp2k/cp2k/cp2k_prep.py b/biobb_cp2k/cp2k/cp2k_prep.py index 530df32..f7fa0b8 100755 --- a/biobb_cp2k/cp2k/cp2k_prep.py +++ b/biobb_cp2k/cp2k/cp2k_prep.py @@ -3,6 +3,7 @@ """Module containing the Cp2kPrep class and the command line interface.""" import argparse from typing import Optional +from typing import Any import os import collections.abc from pathlib import Path @@ -127,9 +128,9 @@ def iterdict(self, d, depth, fileout_h): print(' ' * depth, k.upper(), v, file=fileout_h) # global dict3 = {} - def parse_rec_def(self, cp2k_in_array, index, stop): - dict = {} - dict2 = {} + def parse_rec_def(self, cp2k_in_array: list[Any], index: int, stop: str) -> dict[Any, Any]: + dict_var: dict[Any, Any] = {} + dict_var2: dict[Any, Any] = {} depth = 0 rec = False for line in cp2k_in_array[index:]: @@ -142,7 +143,7 @@ def parse_rec_def(self, cp2k_in_array, index, stop): vals = line.lstrip().split() if depth < 0: - return dict + return dict_var elif '&' in line: depth = depth + 1 if depth == 1: @@ -150,41 +151,41 @@ def parse_rec_def(self, cp2k_in_array, index, stop): key = vals[0].replace('&', '') if (key == 'KIND'): key_name = key + "-" + vals[1] - if dict.get(key): - dict[key].append(self.parse_rec_def(cp2k_in_array, index, key_name)) + if dict_var.get(key): + dict_var[key].append(self.parse_rec_def(cp2k_in_array, index, key_name)) else: - dict[key] = [] - dict[key].append(self.parse_rec_def(cp2k_in_array, index, key_name)) + dict_var[key] = [] + dict_var[key].append(self.parse_rec_def(cp2k_in_array, index, key_name)) else: rec = True - dict[key] = self.parse_rec_def(cp2k_in_array, index, key) + dict_var[key] = self.parse_rec_def(cp2k_in_array, index, key) if len(vals) > 1 and key != 'KIND': - # print(stop + " Add dict[key]['name'] = " + str(vals[1].strip())) - dict[key]['name'] = vals[1].strip() + # print(stop + " Add dict_var[key]['name'] = " + str(vals[1].strip())) + dict_var[key]['name'] = vals[1].strip() elif not rec: vals = line.lstrip().split() - # print(stop + " Add dict[" + str(vals[0]) + "] = " + str(vals[1].strip())) + # print(stop + " Add dict_var[" + str(vals[0]) + "] = " + str(vals[1].strip())) if (stop == 'COORD'): - if dict2.get('coords_list'): - dict2['coords_list'].append({vals[0]: vals[1:]}) + if dict_var2.get('coords_list'): + dict_var2['coords_list'].append({vals[0]: vals[1:]}) else: - dict2['coords_list'] = [] - dict2['coords_list'].append({vals[0]: vals[1:]}) + dict_var2['coords_list'] = [] + dict_var2['coords_list'].append({vals[0]: vals[1:]}) - dict = dict2['coords_list'] + dict_var = dict_var2['coords_list'] # type: ignore elif (len(vals) == 2): if (stop.startswith('KIND-')): key2, name = stop.split('-') - dict['name'] = name - dict[vals[0]] = vals[1].strip() + dict_var['name'] = name + dict_var[vals[0]] = vals[1].strip() else: - dict[vals[0]] = vals[1:] + dict_var[vals[0]] = vals[1:] - return dict + return dict_var def parse_pdb(self, pdb_file): - dict = {} + dict_var = {} # coord = {} coord = [] cell = {} @@ -237,11 +238,11 @@ def parse_pdb(self, pdb_file): cell['ABC'] = [str(box_x), str(box_y), str(box_z)] - dict['coord'] = coord - # dict['coords'] = coords - dict['cell'] = cell + dict_var['coord'] = coord + # dict_var['coords'] = coords + dict_var['cell'] = cell - return dict + return dict_var def merge(self, a, b): for key_b in b: @@ -273,7 +274,7 @@ def merge(self, a, b): return a def replace_coords(self, a, b): - # dict['force_eval'] = {'subsys' : {'coord' : coord } } + # dict_var['force_eval'] = {'subsys' : {'coord' : coord } } print("BioBB_CP2K, replacing coordinates...") for key in a: if key.upper() == 'FORCE_EVAL': @@ -364,7 +365,7 @@ def launch(self): print("Will take just the input_inp_path.") elif (self.simulation_type): # path_cp2k_in = PurePath(myself.__file__).parent - path_cp2k_in = Path(os.getenv("CONDA_PREFIX")).joinpath('cp2k_aux') + path_cp2k_in = Path(os.getenv("CONDA_PREFIX", "")).joinpath('cp2k_aux') if (self.simulation_type == 'energy'): self.io_dict["in"]["input_inp_path"] = str(Path(path_cp2k_in).joinpath("cp2k_in/cp2k_energy.inp")) elif (self.simulation_type == 'geom_opt'): diff --git a/biobb_cp2k/cp2k/cp2k_run.py b/biobb_cp2k/cp2k/cp2k_run.py index eb19332..2f0b21a 100755 --- a/biobb_cp2k/cp2k/cp2k_run.py +++ b/biobb_cp2k/cp2k/cp2k_run.py @@ -123,7 +123,7 @@ def launch(self): # set path to the CP2K parameter data files if not self.param_path: # os.environ["CP2K_DATA_DIR"] = str(PurePath(myself.__file__).parent.joinpath('cp2k_data')) - os.environ["CP2K_DATA_DIR"] = str(Path(os.getenv("CONDA_PREFIX")).joinpath('cp2k_aux').joinpath('cp2k_data')) + os.environ["CP2K_DATA_DIR"] = str(Path(os.getenv("CONDA_PREFIX", "")).joinpath('cp2k_aux').joinpath('cp2k_data')) else: if not Path(PurePath(self.param_path)).exists(): fu.log(self.__class__.__name__ + ': Unexisting %s folder, exiting' % self.param_path, self.out_log) @@ -167,7 +167,7 @@ def launch(self): else: out_files.append(self.tmp_folder + '/' + file) - fu.zip_list(self.output, out_files, self.out_log) + fu.zip_list(str(self.output), out_files, self.out_log) # Copy outputs from temporary folder to output path shutil.copy2(self.output, PurePath(self.io_dict["out"]["output_outzip_path"])) diff --git a/setup.py b/setup.py index e5df868..5c2b88b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="biobb_cp2k", - version="4.2.0", + version="5.0.0", author="Biobb developers", author_email="adam.hospital@irbbarcelona.org", description="Biobb_cp2k is a BioBB category for CP2K QM package.", @@ -20,21 +20,19 @@ packages=setuptools.find_packages(exclude=['docs', 'test']), package_data={'biobb_cp2k': ['py.typed']}, include_package_data=True, - install_requires=['biobb_common==4.2.0'], - python_requires='>=3.8', + install_requires=['biobb_common==5.0.0'], + python_requires='>=3.9', entry_points={ "console_scripts": [ "cp2k_run = biobb_cp2k.cp2k.cp2k_run:main", "cp2k_prep = biobb_cp2k.cp2k.cp2k_prep:main" ] }, - classifiers=( - "Development Status :: 3 - Alpha", - "Programming Language :: Python :: 3.8", + classifiers=[ + "Development Status :: 5 - Production/Stable", "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", "License :: OSI Approved :: Apache Software License", "Operating System :: MacOS :: MacOS X", - "Operating System :: POSIX", - ), + "Operating System :: POSIX" + ], )