Skip to content

Allow management command to ignore missing file #191

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

Merged
merged 5 commits into from
May 15, 2018

Conversation

marojenka
Copy link

@marojenka marojenka commented Apr 15, 2018

QOL fix allowing rendervariations command to process missing files by logging error instead of complete break.

@codecov
Copy link

codecov bot commented Apr 15, 2018

Codecov Report

Merging #191 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #191      +/-   ##
==========================================
+ Coverage   96.49%   96.59%   +0.09%     
==========================================
  Files           5        5              
  Lines         257      264       +7     
==========================================
+ Hits          248      255       +7     
  Misses          9        9
Impacted Files Coverage Δ
stdimage/management/commands/rendervariations.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e762dd1...4ad30f4. Read the comment docs.

@marojenka
Copy link
Author

aaaand it contains a misprint and error that does not exist in python2. So prob not such a good idea.

@marojenka
Copy link
Author

marojenka commented Apr 15, 2018

python2 incompatibility bothers me but I don't see any other clean way to do it.
Probably IOSError should work in fresh py2 and it actually make sense since different kind if problems might rise while working with files right? 🤔
So sure py2 isn't supported at this point but if the rest of the project is working under py2 FileNotFoundError can be replaced by IOSError.
Cheers.

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

Cool @marojenka , good work!

I left you some comments about a couple small things. My bigger request would be to add a test ;)

if not igrnore_missing:
raise
else:
logger.error(str(e))
Copy link
Owner

Choose a reason for hiding this comment

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

Please don't use the logger here. The command should write to stderr.
If you would want to log an exception, you should actually log exception and always provide your own message. The original exception and stack trace will be included anyways. You're log should provide additional information to why the exception was not raised.

Copy link
Owner

Choose a reason for hiding this comment

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

Anyhow, in this case please write to self.stderr.

Copy link
Author

Choose a reason for hiding this comment

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

I kinda was too used to trowing everything to the logger without additional thought. Yeah, I will change that a bit later.

@@ -8,6 +9,8 @@

from stdimage.utils import render_variations

logger = logging.getLogger()
Copy link
Owner

Choose a reason for hiding this comment

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

I explain further down why I don't think using a logger is a good idea. But as a side note here:
I would recommend to use the package name. That way people have only a single logger per package, that they can configure in their projects.

Copy link
Owner

Choose a reason for hiding this comment

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

I also don't know the default, I think you are getting the root logger here, where I think you wanted __name__. Anyhow, check my comment further down about stderr.

Copy link
Author

Choose a reason for hiding this comment

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

yeah u are right, I just missed that.
quality code

@@ -24,8 +27,16 @@ def add_arguments(self, parser):
default=False,
help='Replace existing files.')

parser.add_argument('--igrnore-missing',
Copy link
Owner

Choose a reason for hiding this comment

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

I would recommend to add a short version too, -i.

action='store_true',
dest='igrnore_missing',
default=False,
help='Do not rise exception on missing file '
Copy link
Owner

Choose a reason for hiding this comment

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

s/rise/raise/

Copy link
Owner

Choose a reason for hiding this comment

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

How about something that does not include a negation:
Ignore and skip missing file errors.

Up in the help you might want to document, that the command will exit with non-zero exit code if a file is not found.

render_variations(**kwargs)
except FileNotFoundError as e:
if not igrnore_missing:
raise
Copy link
Owner

Choose a reason for hiding this comment

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

I would recommend to cast to a CommandError and provide a more descriptive error message, eg:

raise CommandError("Original file was not found, terminating command. Use --ignore-missing to skip this error.") from e

@marojenka
Copy link
Author

marojenka commented Apr 16, 2018

My bigger request would be to add a test

I did some test 024a340#diff-59262c12118a93348565a41ab7f6ce42R86
not enough?

the rest are reasonable comments, thanks.

@codingjoe
Copy link
Owner

I did some test 024a340#diff-59262c12118a93348565a41ab7f6ce42R86
not enough?

That doesn't look bad, but the commit is not in your PR.

the rest are reasonable comments, thanks.

thx, I try my best :)

@marojenka
Copy link
Author

It's my last (badly named) commit in this request tho
https://github.com/codingjoe/django-stdimage/pull/191/commits

Logger is removed from rendervaraiations command.  CommandError is
raised (saving original error stack) when source file is missing and
nothing is done if --ignore-missing option is set.
Add short version of --ignore-missing option: -i. Add test for it.
@marojenka
Copy link
Author

it was some time but here is my changes to your comments.
I added shorted option -i, added it to the test (really important), ditched logger, raised CommandError.
M, forgot documentation.

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

👏 great work! thanks

@codingjoe codingjoe merged commit 217985b into codingjoe:master May 15, 2018
@codingjoe
Copy link
Owner

Released in 3.2.0

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.

2 participants