Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Oct 11, 2020

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

@sourcery-ai sourcery-ai bot requested a review from tozhovez October 11, 2020 09:15
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Oct 11, 2020

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.46%.

Quality metrics Before After Change
Complexity 0.83 ⭐ 0.74 ⭐ -0.09 👍
Method Length 29.96 ⭐ 29.13 ⭐ -0.83 👍
Working memory 5.37 ⭐ 5.26 ⭐ -0.11 👍
Quality 89.60% 90.06% 0.46% 👍
Other metrics Before After Change
Lines 375 361 -14
Changed files Quality Before Quality After Quality Change
sites-checker/Infra/scripts/consul_client.py 83.58% ⭐ 84.10% ⭐ 0.52% 👍
sites-checker/SitesCheckerService/sites_checker_service.py 92.86% ⭐ 92.95% ⭐ 0.09% 👍
sites-checker/SitesCheckerService/api/health_check.py 97.87% ⭐ 97.90% ⭐ 0.03% 👍
sites-checker/SitesCheckerService/core/consul_client.py 83.13% ⭐ 83.64% ⭐ 0.51% 👍
sites-checker/SitesCheckerService/core/core_module.py 90.92% ⭐ 92.46% ⭐ 1.54% 👍
sites-checker/SitesCheckerService/core/postgres_client.py 87.92% ⭐ 88.25% ⭐ 0.33% 👍
sites-checker/SitesCheckerService/jobs/job_manager.py 97.75% ⭐ 98.26% ⭐ 0.51% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
sites-checker/Infra/scripts/consul_client.py ConsulClient.put 1 ⭐ 52 ⭐ 10 😞 75.17% ⭐ Extract out complex expressions
sites-checker/SitesCheckerService/core/consul_client.py ConsulClient.put 1 ⭐ 52 ⭐ 10 😞 75.17% ⭐ Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

Comment on lines -46 to +50
only_kv_data = []
_, data = self.consul_client.kv.get(key='', recurse=True)
for item in data:
only_kv_data.append({
return [{
"Key": item['Key'],
"Value": json.loads((item['Value'].decode('utf-8')))
})
return only_kv_data
} for item in data]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConsulClient.get_all refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -40 to -44
service_state = {
return {
'status_code': status_code,
}

return service_state
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SitesCheckerService.status refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

res_status = 200

return res_status
return 200
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HealthCheckController.check_health refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -46 to +50
only_kv_data = []
_, data = self.consul_client.kv.get(key='', recurse=True)
for item in data:
only_kv_data.append({
return [{
"Key": item['Key'],
"Value": json.loads((item['Value'].decode('utf-8')))
})
return only_kv_data
} for item in data]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConsulClient.get_all refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -20 to +23
consul_client = ConsulClient(host=os.getenv('CONSUL_HOST', '127.0.0.1'), prefix='sites-checker-service')
return consul_client
return ConsulClient(
host=os.getenv('CONSUL_HOST', '127.0.0.1'),
prefix='sites-checker-service',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_consul_client refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -29 to +33
postgres_client = PostgresClient(dsn=conf_service.postgres_url)
# TODO: check asyncio support
# await postgres_client.connect()
return postgres_client
return PostgresClient(dsn=conf_service.postgres_url)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_postgres_client refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -38 to -45
logger = get_logger(
return get_logger(
logger_name='SitesCheckerService',
logger_format=LoggingFormat.JSON,
logger_level=logging.INFO,
logger_output=LoggingOutput.STDOUT,
)

return logger
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_logger refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

for result in cursor.fetchall():
yield result
yield from cursor.fetchall()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostgresClient.select refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

Comment on lines -76 to +75
for result in cursor.fetchall():
yield result
yield from cursor.fetchall()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostgresClient.insert refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

job = self.scheduler.add_job(callback, 'date', args=args)
return job
return self.scheduler.add_job(callback, 'date', args=args)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function JobManager.run_once refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

@tozhovez tozhovez self-assigned this Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant