Repository navigation
import_srpm: allow to pass a url as source file - #740
Conversation
72275f4 to
09f205c
Compare
|
@glehmann ready for re-review? |
09f205c to
40a9d07
Compare
|
@glehmann you pushed after my last question but didn't answer nor ask for a re-review. Thus the PR stalled. What's the current status? |
40a9d07 to
1f5fc97
Compare
|
The changes were meant to be minimal, hence the lack of temp file removal. |
| source_rpm = args.source_rpm | ||
| is_remote_rpm = is_url(source_rpm) | ||
|
|
||
| with TemporaryDirectory() if is_remote_rpm else nullcontext() as temp_dir: |
There was a problem hiding this comment.
I believe that you could still keep the changes minimal as initially intended by avoiding the use of a context manager. You could use atexit.register(temp_dir.cleanup) to ensure it's cleaned up even in case of a raised exception. Unless I missed something obvious.
Not a blocker comment.
There was a problem hiding this comment.
I think it's cleaner that way, so I'd prefer to keep the context manager.
The diff is hard to read in github, but with better diff viewers, it's easy to see that it's mostly indentation changes :)
There was a problem hiding this comment.
To make such diffs more readable, a good way is to split things in different commits. Here that could be "add a nullcontext ctxmanager" as a first step.
There was a problem hiding this comment.
So because github is bad at showing this kind of diff, I'm supposed to think about how the diff will be displayed in github and split my work in multiple commits? That seems a bit excessive to me.
Also note that the reviewer would still have to actually look at the diff which indents the code, to make sure nothing is changed.
There was a problem hiding this comment.
Note I'm not talking about GH (because we all know how bad they are 😉), but about reviewing with standard git tools.
| source_rpm = args.source_rpm | ||
| is_remote_rpm = is_url(source_rpm) | ||
|
|
||
| with TemporaryDirectory() if is_remote_rpm else nullcontext() as temp_dir: |
There was a problem hiding this comment.
To make such diffs more readable, a good way is to split things in different commits. Here that could be "add a nullcontext ctxmanager" as a first step.
| except Exception: | ||
| parser.error("Git repository seems to have local modifications.") |
There was a problem hiding this comment.
That is an unrelated change that does not belong to this commit. Likely a fix for a real bug, since the original code really looks strange:
except:
raise
parser.error("Git repository seems to have local modifications.")| except Exception: | ||
| has_changes = True |
There was a problem hiding this comment.
This too is a separate fix
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1f5fc97 to
c404730
Compare
| with TemporaryDirectory() if is_remote_rpm else nullcontext() as temp_dir: | ||
| if is_remote_rpm: | ||
| # get the src.rpm locally, and continue with the actual file | ||
| local_filename = f'{temp_dir}/{os.path.basename(source_rpm)}' | ||
| urlretrieve(source_rpm, local_filename) | ||
| source_rpm = local_filename |
There was a problem hiding this comment.
The non-remote case could possibly be simplified: there seems to be no need to use a context manager at all in that case, if all the actions inside the with block are for the other case:
| with TemporaryDirectory() if is_remote_rpm else nullcontext() as temp_dir: | |
| if is_remote_rpm: | |
| # get the src.rpm locally, and continue with the actual file | |
| local_filename = f'{temp_dir}/{os.path.basename(source_rpm)}' | |
| urlretrieve(source_rpm, local_filename) | |
| source_rpm = local_filename | |
| if is_remote_rpm: | |
| with TemporaryDirectory() as temp_dir: | |
| # get the src.rpm locally, and continue with the actual file | |
| local_filename = f'{temp_dir}/{os.path.basename(source_rpm)}' | |
| urlretrieve(source_rpm, local_filename) | |
| source_rpm = local_filename |
There was a problem hiding this comment.
I don't think it would work: the TemporaryDirectory context manager would delete the directory when exiting the with block, but we still need what this dir contains later in the code
There was a problem hiding this comment.
mb, looks like I read that with too little context :(
This way we don't even have to manually download the srpm.