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

Replace use of os.path with pathlib #156

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

Icosahunter
Copy link
Collaborator

No description provided.

@Icosahunter
Copy link
Collaborator Author

Tested on Linux (Solus) for basic functionality

@CyanVoxel CyanVoxel added the refactor Code that needs to be restructured or cleaned up label May 10, 2024
@CyanVoxel CyanVoxel added this to the Alpha 9.3.x milestone May 10, 2024
@yedpodtrzitko
Copy link
Collaborator

good job, this was really needed 👍

@Icosahunter
Copy link
Collaborator Author

@yedpodtrzitko Thanks for the comments, I think I've resolved most of them. I'll have to test with the changes and ruff-format it again.

@yedpodtrzitko yedpodtrzitko mentioned this pull request May 11, 2024
@Icosahunter
Copy link
Collaborator Author

Fixed some issues that cropped up with the modularized GUI files.

@Icosahunter
Copy link
Collaborator Author

I think all the basics are working now, tested creating/opening library, adding tags/fields, and removing unlinked files (on Solus Linux)

@CyanVoxel
Copy link
Member

@CyanVoxel it would be nice to merge the mypy PRs sooner or later, errors like this #156 (comment) will be caught automatically.

I'll get that going soon here

@CyanVoxel CyanVoxel mentioned this pull request May 16, 2024
@CyanVoxel
Copy link
Member

Just a heads up, I'll be pulling #142 (a rewrite of #88) before this, which will cause some additional conflicts - I apologize in advance.

qim = ImageQt.ImageQt(final)
final.save(f'/home/icosahunter/Documents/test/{filepath.stem}.png')
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

whoops, I'll need to fix that 🤦‍♂️

@Icosahunter
Copy link
Collaborator Author

Tested basic functionality on my Linux distro (Solus) and seems to be working. At one point I did get a segfault... but it didn't happen in later testing.

else os.path.normpath(f"{results_filepath}")
)
if os.path.exists(full_results_path):
full_results_path = Path(results_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
full_results_path = Path(results_path)
full_results_path = Path(results_filepath)

at this moment methods without any type annotations in their declaration arent checked (which is the case of refresh_dupe_files() here), so this undefined variable isnt caught.
Adding either the return type, or type for the param results_filepath would help here.

with rawpy.imread(filepath) as raw:
rgb = raw.postprocess()
image = Image.new(
"L", (rgb.shape[1], rgb.shape[0]), color="black"
)
elif extension in VIDEO_TYPES:
elif filepath.suffix in VIDEO_TYPES:
video = cv2.VideoCapture(filepath)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
video = cv2.VideoCapture(filepath)
video = cv2.VideoCapture(str(filepath))

cv2.VideoCapture expects a string here, and throws an error when given a Path object such as:

[PreviewPanel][ERROR] Couldn't Render thumbnail for F:\Example 4\Folder A\yoink\video.mp4 (because of OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function 'VideoCapture'
> Overload resolution failed:
>  - Can't convert object to 'str' for 'filename'
>  - VideoCapture() missing required argument 'apiPreference' (pos 2)
>  - Argument 'index' is required to be an integer
>  - VideoCapture() missing required argument 'apiPreference' (pos 2)
)

Can be reproduced by checking the console log after clicking on a video file in the library. I see that the other instances outside of ts_cli.py are also using this cast.

self.dimensions_label.setText(
f"{extension.upper()} • {format_size(os.stat(filepath).st_size)}\n{image.width} x {image.height} px"
f"{filepath.suffix.upper()} • {format_size(os.stat(filepath).st_size)}\n{image.width} x {image.height} px"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"{filepath.suffix.upper()}{format_size(os.stat(filepath).st_size)}\n{image.width} x {image.height} px"
f"{filepath.suffix.upper()[1:]}{format_size(os.stat(filepath).st_size)}\n{image.width} x {image.height} px"

Removes leading "." from filetype display

)
else:
self.dimensions_label.setText(f"{extension.upper()}")
self.dimensions_label.setText(f"{filepath.suffix.upper()}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.dimensions_label.setText(f"{filepath.suffix.upper()}")
self.dimensions_label.setText(f"{filepath.suffix.upper()[1:]}")

Removes leading "." from filetype display

@@ -535,7 +534,7 @@ def update_widgets(self):
DecompressionBombError,
) as e:
self.dimensions_label.setText(
f"{extension.upper()} • {format_size(os.stat(filepath).st_size)}"
f"{filepath.suffix.upper()} • {format_size(os.stat(filepath).st_size)}"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"{filepath.suffix.upper()}{format_size(os.stat(filepath).st_size)}"
f"{filepath.suffix.upper()[1:]}{format_size(os.stat(filepath).st_size)}"

Removes leading "." from filetype display (wish I could comment on all these different lines at once)

@@ -289,8 +286,8 @@ def render(
math.ceil(adj_size / pixel_ratio),
math.ceil(final.size[1] / pixel_ratio),
),
extension,
_filepath.suffix,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_filepath.suffix,
_filepath.suffix[1:],

Removes leading "." from filetype display on thumbnails

)

else:
self.updated.emit(timestamp, QPixmap(), QSize(*base_size), extension)
self.updated.emit(timestamp, QPixmap(), QSize(*base_size), _filepath.suffix)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.updated.emit(timestamp, QPixmap(), QSize(*base_size), _filepath.suffix)
self.updated.emit(timestamp, QPixmap(), QSize(*base_size), _filepath.suffix[1:])

Removes leading "." from filetype display on thumbnails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code that needs to be restructured or cleaned up
Projects
Status: Pending Merge
Development

Successfully merging this pull request may close these issues.

None yet

3 participants