Skip to content

Sourcery refactored master branch #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,30 @@ def vlog(self, msg, *args):


pass_context = click.make_pass_decorator(Context, ensure = True)
cmd_folder = os.path.join(BASE_DIR + '/cli', 'commands')
cmd_folder = os.path.join(f'{BASE_DIR}/cli', 'commands')
Copy link
Author

Choose a reason for hiding this comment

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

Lines 28-28 refactored with the following changes:



class CLI(click.MultiCommand):

def list_commands(self, ctx):
rv = []
for filename in os.listdir(cmd_folder):
if filename.endswith('.py') and \
filename.startswith('cmd_'):
rv.append(filename[4:-3])
rv = [
filename[4:-3]
for filename in os.listdir(cmd_folder)
if filename.endswith('.py') and filename.startswith('cmd_')
]
Comment on lines -34 to +38
Copy link
Author

Choose a reason for hiding this comment

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

Function CLI.list_commands refactored with the following changes:

rv.sort()
return rv

def get_command(self, ctx, name):
try:
if sys.version_info[0] == 2:
name = name.encode('ascii', 'replace')
mod = __import__('cli.commands.cmd_' + name, locals = None, globals = None, fromlist = ['cli'])
mod = __import__(
f'cli.commands.cmd_{name}',
locals=None,
globals=None,
fromlist=['cli'],
)
Comment on lines -46 to +51
Copy link
Author

Choose a reason for hiding this comment

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

Function CLI.get_command refactored with the following changes:

except ImportError:
return
return mod.cli
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/cmd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def make_api(api_name: str, model):
f"class {api_name.capitalize()}View(Resource):\n"
f" pass")

with open(f'api/__init__.py', 'a+') as f:
with open('api/__init__.py', 'a+') as f:
Copy link
Author

Choose a reason for hiding this comment

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

Function make_api refactored with the following changes:

f.write(
f'from api.{api_name.capitalize()} import {api_name.capitalize()}View\n')
f.write(
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/cmd_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class {model_name.capitalize()}(Model):
pass
''')

with open(f'models/__init__.py', 'a+') as f:
with open('models/__init__.py', 'a+') as f:
Copy link
Author

Choose a reason for hiding this comment

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

Function make_model refactored with the following changes:

f.write(
f'from models.{model_name.capitalize()} import {model_name.capitalize()}\n')

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/cmd_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def list_():

output[rule.endpoint] = route

endpoint_padding = max(len(endpoint) for endpoint in output.keys()) + 2
endpoint_padding = max(len(endpoint) for endpoint in output) + 2
Copy link
Author

Choose a reason for hiding this comment

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

Function list_ refactored with the following changes:


for key in sorted(output):
if 'debugtoolbar' not in key and 'debug_toolbar' not in key:
Expand Down
4 changes: 3 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@

formatter = logging.Formatter(
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler = RotatingFileHandler(LOG_DIR + '/app.log', maxBytes = 1000000, backupCount = 5)
handler = RotatingFileHandler(
f'{LOG_DIR}/app.log', maxBytes=1000000, backupCount=5
)
Comment on lines -64 to +66
Copy link
Author

Choose a reason for hiding this comment

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

Lines 64-64 refactored with the following changes:

handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
Expand Down
4 changes: 1 addition & 3 deletions facilities/databases/DBMixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def __ne__(self, other):
Checks the inequality of two `UserMixin` objects using `get_id`.
"""
equal = self.__eq__(other)
if equal is NotImplemented:
return NotImplemented
return not equal
return NotImplemented if equal is NotImplemented else not equal
Copy link
Author

Choose a reason for hiding this comment

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

Function UserMixin.__ne__ refactored with the following changes:



class AnonymousUserMixin:
Expand Down
6 changes: 1 addition & 5 deletions facilities/mimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,4 @@ def get_mimes(extension=None):

def get_extensions(mime_type=None):
"""Returns possible extensions for the given mime_type"""
exts = []
for ext in _mime_types:
if mime_type in _mime_types[ext]:
exts.append(ext)
return exts
return [ext for ext in _mime_types if mime_type in _mime_types[ext]]
Copy link
Author

Choose a reason for hiding this comment

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

Function get_extensions refactored with the following changes:

5 changes: 2 additions & 3 deletions models/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class User(Model):
# __guarded__ = ['id', 'password', 'password_again']

def __repr__(self):
return '<User {}>'.format(self.username)
return f'<User {self.username}>'
Copy link
Author

Choose a reason for hiding this comment

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

Function User.__repr__ refactored with the following changes:


@property
def rolenames(self):
Expand All @@ -56,8 +56,7 @@ def rolenames(self):

@classmethod
def lookup(cls, username):
result = cls.query().where('username', username).first_or_fail()
if result:
if result := cls.query().where('username', username).first_or_fail():
Copy link
Author

Choose a reason for hiding this comment

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

Function User.lookup refactored with the following changes:

return result
else:
return None
Expand Down