Skip to content

Commit

Permalink
style: fix lint after pylint upgrade (#170)
Browse files Browse the repository at this point in the history
* Fix linting after upgrading to pylint2.11

* Fix encoding in open call
  • Loading branch information
Olivier Cervello authored and lvaylet committed Nov 25, 2022
1 parent d5d89a9 commit a894984
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions slo_generator/backends/cloud_service_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def build_slo(window, slo_config): # pylint: disable=R0912,R0915
return slo

def get_slo(self, window, slo_config):
"""Get SLO object from Cloud Service Monitoring API.
"""Get SLO object from Cloud Service Monssitoring API.
Args:
service_id (str): Service identifier.
Expand Down Expand Up @@ -666,7 +666,7 @@ def convert_duration_to_string(duration):
if duration_seconds.is_integer():
duration_str = int(duration_seconds)
else:
duration_str = "{:0.3f}".format(duration_seconds)
duration_str = f'{duration_seconds:0.3f}'
return str(duration_str) + 's'

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions slo_generator/backends/dynatrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ def request(self,
}
if name:
url += f'/{name}'
params_str = "&".join(
"%s=%s" % (k, v) for k, v in params.items() if v is not None)
params_str = '&'.join(
f'{key}={val}' for key, val in params.items() if val is not None)
url += f'?{params_str}'
LOGGER.debug(f'Running "{method}" request to {url} ...')
if method in ['put', 'post']:
Expand Down
5 changes: 2 additions & 3 deletions slo_generator/exporters/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def export(self, data, **config):
dataset_id,
table_id,
schema=TABLE_SCHEMA)
row_ids = "%s%s%s%s%s" % (data['service_name'], data['feature_name'],
data['slo_name'], data['timestamp_human'],
data['window'])
row_ids_fmt = '{service_name}{feature_name}{slo_name}{timestamp_human}{window}' # pylint: disable=line-too-long # noqa: E501
row_ids = row_ids_fmt.format(**data)

# Format user metadata if needed
json_data = {k: v for k, v in data.items() if k in schema_fields}
Expand Down
10 changes: 5 additions & 5 deletions slo_generator/migrations/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def do_migrate(source,
extra = '(replaced)' if target_path_str == source_path_str else ''
click.secho(
f"{RIGHT_ARROW} {GREEN}{target_path_str}{ENDC} [{version}] {extra}")
with target_path.open('w') as conf:
with target_path.open('w', encoding='utf8') as conf:
yaml.round_trip_dump(
slo_config_v2,
conf,
Expand All @@ -165,7 +165,7 @@ def do_migrate(source,
click.secho('=' * 50)
shared_config_path = target / 'config.yaml'
shared_config_path_str = shared_config_path.relative_to(cwd)
with shared_config_path.open('w') as conf:
with shared_config_path.open('w', encoding='utf8') as conf:
click.secho(
f'Writing slo-generator config to {shared_config_path_str} ...',
fg='cyan',
Expand Down Expand Up @@ -317,8 +317,8 @@ def slo_config_v1tov2(slo_config,
return None

# Get fields from old config
slo_metadata_name = '{service_name}-{feature_name}-{slo_name}'.format(
**slo_config)
slo_metadata_name_fmt = '{service_name}-{feature_name}-{slo_name}'
slo_metadata_name = slo_metadata_name_fmt.format(**slo_config)
slo_description = slo_config.pop('slo_description')
slo_target = slo_config.pop('slo_target')
service_level_indicator = slo_config['backend'].pop('measurement', {})
Expand Down Expand Up @@ -420,7 +420,7 @@ def report_v2tov1(report):

# If a key in the default label mapping is passed, use the default
# label mapping
elif key in METRIC_LABELS_COMPAT.keys():
elif key in METRIC_LABELS_COMPAT:
mapped_report.update({METRIC_LABELS_COMPAT[key]: value})

# Otherwise, write the label as is
Expand Down
6 changes: 4 additions & 2 deletions slo_generator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def replace_env_vars(content, ctx):
return content

if path:
with Path(path).open() as config:
with Path(path).open(encoding='utf8') as config:
content = config.read()
if ctx:
content = replace_env_vars(content, ctx)
Expand Down Expand Up @@ -198,7 +198,9 @@ def get_human_time(timestamp, timezone=None):
dt_tz = dt_utc.replace(tzinfo=to_zone)
timeformat = '%Y-%m-%dT%H:%M:%S.%f%z'
date_str = datetime.strftime(dt_tz, timeformat)
date_str = "{0}:{1}".format(date_str[:-2], date_str[-2:])
core_str = date_str[:-2]
tz_str = date_str[-2:]
date_str = f'{core_str}:{tz_str}'
return date_str


Expand Down

0 comments on commit a894984

Please sign in to comment.