Skip to content

Commit

Permalink
os.path -> pathlib.Path, change in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PauAndrio committed Mar 24, 2020
1 parent 9c0e080 commit 472039a
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 151 deletions.
2 changes: 1 addition & 1 deletion biobb_common/command_wrapper/cmd_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def launch(self):

out, err = process.communicate()
if self.out_log is None:
print ("Exit, code {}".format(process.returncode))
print("Exit, code {}".format(process.returncode))
process.wait()

# Write output to log
Expand Down
124 changes: 63 additions & 61 deletions biobb_common/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@

import yaml
import json
import os
from os.path import join as opj
import logging
from pathlib import Path
from biobb_common.tools import file_utils as fu

class ConfReader():

class ConfReader:
"""Configuration file loader for yaml format files.
Args:
config (str): Path to the configuration [YAML|JSON] file or JSON string.
system (str): System name from the systems section in the configuration file.
"""

def __init__(self, config=None, system=None):
def __init__(self, config: str = None, system: str = None):
if not config:
config = "{}"
self.config = config
Expand All @@ -58,7 +59,7 @@ def __init__(self, config=None, system=None):

def _read_config(self):
try:
config_file = os.path.abspath(self.config)
config_file = str(Path(self.config).resolve())
with open(config_file, 'r') as stream:
if config_file.lower().endswith((".yaml",".yml")):
return yaml.safe_load(stream)
Expand All @@ -67,13 +68,13 @@ def _read_config(self):
except:
return json.loads(self.config)

def get_working_dir_path(self):
def get_working_dir_path(self) -> str:
if self.system:
return self.properties[self.system].get('working_dir_path')

return self.properties.get('working_dir_path' )
return self.properties.get('working_dir_path')

def get_prop_dic(self, prefix=None, global_log=None):
def get_prop_dic(self, prefix: str = None, global_log: logging.Logger = None):
"""get_prop_dic() returns the properties dictionary where keys are the
step names in the configuration YAML file and every value contains another
nested dictionary containing the keys and values of each step properties section.
Expand All @@ -100,83 +101,84 @@ def get_prop_dic(self, prefix=None, global_log=None):
if 'paths' in self.properties or 'properties' in self.properties:
prop_dic = dict()
if self.system:
prop_dic['path']=os.path.join(self.properties[self.system]['working_dir_path'], prefix)
prop_dic['path'] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix))
else:
prop_dic['path']=os.path.join(self.properties['working_dir_path'],prefix)
prop_dic['step']= None
prop_dic['prefix']= prefix
prop_dic['global_log']= global_log
prop_dic['system']= self.system
prop_dic['path'] = str(Path(self.properties['working_dir_path']).joinpath(prefix))
prop_dic['step'] = None
prop_dic['prefix'] = prefix
prop_dic['global_log'] = global_log
prop_dic['system'] = self.system
if self.system:
prop_dic.update(self.properties[self.system].copy())
else:
prop_dic['working_dir_path']=self.properties.get('working_dir_path')
prop_dic['restart']= self.properties.get('restart', False)
prop_dic['remove_tmp']= self.properties.get('remove_tmp', True)
prop_dic['working_dir_path'] = self.properties.get('working_dir_path')
prop_dic['restart'] = self.properties.get('restart', False)
prop_dic['remove_tmp'] = self.properties.get('remove_tmp', True)

if 'properties' in self.properties and isinstance(self.properties['properties'], dict):
prop_dic.update(self.properties['properties'].copy())
if self.system:
if self.properties[self.system].get('log_level', None):
prop_dic['log_level']= self.properties[self.system]['log_level']
prop_dic['log_level'] = self.properties[self.system]['log_level']
else:
if self.properties.get('log_level', None):
prop_dic['log_level']= self.properties['log_level']
prop_dic['log_level'] = self.properties['log_level']
# There is step name
else:
for key in self.properties:
if isinstance(self.properties[key], dict):
if 'paths' in self.properties[key] or 'properties' in self.properties[key]:
prop_dic[key] = dict()
if self.system:
prop_dic[key]['path']=os.path.join(self.properties[self.system]['working_dir_path'], prefix, key)
prop_dic[key]['path'] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix, key))
else:
prop_dic[key]['path']=os.path.join(self.properties['working_dir_path'],prefix, key)
prop_dic[key]['step']= key
prop_dic[key]['prefix']= prefix
prop_dic[key]['global_log']= global_log
prop_dic[key]['system']= self.system
prop_dic[key]['path'] = str(Path(self.properties['working_dir_path']).joinpath(prefix, key))
prop_dic[key]['step'] = key
prop_dic[key]['prefix'] = prefix
prop_dic[key]['global_log'] = global_log
prop_dic[key]['system'] = self.system
if self.system:
prop_dic[key].update(self.properties[self.system].copy())
else:
prop_dic[key]['working_dir_path']=self.properties.get('working_dir_path')
prop_dic[key]['can_write_console_log']=self.properties.get('can_write_console_log', True)
prop_dic[key]['restart']= self.properties.get('restart', False)
prop_dic[key]['remove_tmp']= self.properties.get('remove_tmp', True)
prop_dic[key]['working_dir_path'] = self.properties.get('working_dir_path')
prop_dic[key]['can_write_console_log'] = self.properties.get('can_write_console_log', True)
prop_dic[key]['restart'] = self.properties.get('restart', False)
prop_dic[key]['remove_tmp'] = self.properties.get('remove_tmp', True)

if ('properties' in self.properties[key]) and isinstance(self.properties[key]['properties'], dict):
if self.system:
if self.properties[self.system].get('log_level', None):
prop_dic[key]['log_level']= self.properties[self.system]['log_level']
prop_dic[key]['can_write_console_log']=self.properties[self.system].get('can_write_console_log', True)
prop_dic[key]['log_level'] = self.properties[self.system]['log_level']
prop_dic[key]['can_write_console_log'] = self.properties[self.system].get('can_write_console_log', True)
else:
if self.properties.get('log_level', None):
prop_dic[key]['log_level']= self.properties['log_level']
prop_dic[key]['can_write_console_log']=self.properties.get('can_write_console_log', True)
prop_dic[key]['log_level'] = self.properties['log_level']
prop_dic[key]['can_write_console_log'] = self.properties.get('can_write_console_log', True)
prop_dic[key].update(self.properties[key]['properties'].copy())

# There is no step name and there is no properties or paths key return input
if not prop_dic:
prop_dic = dict()
prop_dic.update(self.properties)
if self.system:
prop_dic['path']=os.path.join(self.properties[self.system]['working_dir_path'], prefix)
prop_dic['path'] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix))
else:
prop_dic['path']=os.path.join(self.properties['working_dir_path'],prefix)
prop_dic['step']= None
prop_dic['prefix']= prefix
prop_dic['global_log']= global_log
prop_dic['system']= self.system
prop_dic['path'] = str(Path(self.properties['working_dir_path']).joinpath(prefix))
prop_dic['step'] = None
prop_dic['prefix'] = prefix
prop_dic['global_log'] = global_log
prop_dic['system'] = self.system
if self.system:
prop_dic.update(self.properties[self.system].copy())
else:
prop_dic['working_dir_path']=self.properties.get('working_dir_path')
prop_dic['can_write_console_log']=self.properties.get('can_write_console_log', True)
prop_dic['restart']= self.properties.get('restart', False)
prop_dic['remove_tmp']= self.properties.get('remove_tmp', True)
prop_dic['working_dir_path'] = self.properties.get('working_dir_path')
prop_dic['can_write_console_log'] = self.properties.get('can_write_console_log', True)
prop_dic['restart'] = self.properties.get('restart', False)
prop_dic['remove_tmp'] = self.properties.get('remove_tmp', True)

return prop_dic

def get_paths_dic(self, prefix=None):
def get_paths_dic(self, prefix: str = None):
"""get_paths_dic() returns the paths dictionary where keys are the
step names in the configuration YAML file and every value contains another
nested dictionary containing the keys and values of each step paths section.
Expand All @@ -192,36 +194,36 @@ def get_paths_dic(self, prefix=None):
"""
prop_dic = dict()
prefix = '' if prefix is None else prefix.strip()
step=False
#Filtering just paths
#Properties without step name
step = False
# Filtering just paths
# Properties without step name
if 'paths' in self.properties:
step=False
prop_dic=self.properties['paths'].copy()
step = False
prop_dic = self.properties['paths'].copy()

#Properties with name
# Properties with name
else:
step=True
step = True
for key in self.properties:
if isinstance(self.properties[key], dict):
if 'paths' in self.properties[key]:
prop_dic[key]=self.properties[key]['paths'].copy()
prop_dic[key] = self.properties[key]['paths'].copy()
else:
prop_dic[key] = {}

#Solving dependencies and adding workflow and step path
#Properties without step name: Do not solving dependencies
# Solving dependencies and adding workflow and step path
# Properties without step name: Do not solving dependencies
if not step:
for key2, value in prop_dic.items():
if isinstance(value, str) and value.startswith('file:'):
prop_dic[key2] = value.split(':')[1]
else:
if self.system:
prop_dic[key2] = opj(self.properties[self.system]['working_dir_path'], prefix, key, value)
prop_dic[key2] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix, key, value))
else:
prop_dic[key2] = opj(self.properties['working_dir_path'], prefix, value)
prop_dic[key2] = str(Path(self.properties['working_dir_path']).joinpath(prefix, value))

#Properties with step name
# Properties with step name
else:
for key in prop_dic:
for key2, value in prop_dic[key].items():
Expand All @@ -230,15 +232,15 @@ def get_paths_dic(self, prefix=None):
dependency_step=value.split('/')[1]
value = prop_dic[value.split('/')[1]][value.split('/')[2]]
if self.properties.get(self.system):
prop_dic[key][key2] = opj(self.properties[self.system]['working_dir_path'], prefix, dependency_step, value)
prop_dic[key][key2] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix, dependency_step, value))
else:
prop_dic[key][key2] = opj(self.properties['working_dir_path'], prefix, dependency_step, value)
prop_dic[key][key2] = str(Path(self.properties['working_dir_path']).joinpath(prefix, dependency_step, value))
elif isinstance(value, str) and value.startswith('file:'):
prop_dic[key][key2] = value.split(':')[1]
else:
if self.system:
prop_dic[key][key2] = opj(self.properties[self.system]['working_dir_path'], prefix, key, value)
prop_dic[key][key2] = str(Path(self.properties[self.system]['working_dir_path']).joinpath(prefix, key, value))
else:
prop_dic[key][key2] = opj(self.properties['working_dir_path'], prefix, key, value)
prop_dic[key][key2] = str(Path(self.properties['working_dir_path']).joinpath(prefix, key, value))

return prop_dic
Binary file added biobb_common/docs/source/_static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions biobb_common/docs/source/_static/theme_overrides.css
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/* override table width restrictions as found on https://github.com/getpelican/pelican/issues/1311 */
.wy-table-responsive table td, .wy-table-responsive table th {
/* !important prevents the common CSS stylesheets from
overriding this as on RTD they are loaded after this stylesheet */
white-space: normal !important;
}

.wy-table-responsive {
overflow: visible !important;
}
a { color:#dcbc3c; }
a:hover { color:#29b3b6; }
a:visited { color:#9e8830; }

.highlight { background: #fffae4; }

.wy-table-responsive table td, .wy-table-responsive table th { white-space: normal !important; }
.wy-table-responsive { overflow: visible !important; }

.wy-menu-vertical a:active { background-color: #29b3b6; }

.wy-nav-content { max-width: 1200px; margin: unset; }

.wy-side-nav-search { background-color: #29b3b6; }
.wy-side-nav-search>a:hover { background:none; }
.wy-side-nav-search>div.version { color:rgba(255, 255, 255, 1); }

/* !!! */
.ethical-rtd.ethical-dark-theme { display: none; }

.icon:before { display:none; }
3 changes: 3 additions & 0 deletions biobb_common/docs/source/_static/theme_overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(document).ready(function(){
$('.icon.icon-home').html('<img src="_static/logo.png" class="logo" alt="Logo">');
});
6 changes: 4 additions & 2 deletions biobb_common/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# serve to show the default.

import sys
import os
from pathlib import Path

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../../'))
# Replacing os.path.abspath by pathlib.Path
sys.path.insert(0, str(Path('../../').resolve()))

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -126,6 +127,7 @@
# -- Options for HTML output ----------------------------------------------
def setup(app):
app.add_stylesheet('theme_overrides.css')
app.add_js_file('theme_overrides.js')


# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down
Loading

0 comments on commit 472039a

Please sign in to comment.