-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use os.path.join for file path handling #53
Open
thomasZen
wants to merge
2
commits into
experimental
Choose a base branch
from
feature/osPathForFilePathHandling
base: experimental
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−69
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,14 @@ | |
2024-06-15 - Fix for breaking change in `configparser`; now using | ||
`ConfigParser` instead of `RawConfigParser` | ||
""" | ||
import os.path | ||
|
||
# --------------------------------------------------------------------- | ||
__author__ = "[email protected]" | ||
|
||
# fmt: off | ||
# --------------------------------------------------------------------- | ||
QDSpy_path = os.path.dirname(__file__) | ||
QDSpy_versionStr = "QDSpy v0.92 beta" | ||
QDSpy_copyrightStr = "(c) 2013-24 Thomas Euler" | ||
QDSpy_appID = u"QDSpy3.v090beta.thomas_euler.eulerlab.de" | ||
|
@@ -26,7 +29,7 @@ | |
QDSpy_loop_sleep_s = 0.01 | ||
|
||
QDSpy_isUseSound = False | ||
QDSpy_pathSounds = ".\\Sounds\\" | ||
QDSpy_pathSounds = os.path.join(QDSpy_path, "Sounds") + os.path.sep | ||
QDSpy_soundStimStart = "stim_start.mp3" | ||
QDSpy_soundStimEnd = "stim_end.mp3" | ||
QDSpy_soundError = "error.mp3" | ||
|
@@ -72,7 +75,7 @@ | |
QDSpy_cPickleFileExt = ".pickle" | ||
QDSpy_fileVersionID = 8 | ||
QDSpy_stimFileExt = ".py" | ||
QDSpy_pathStimuli = ".\\Stimuli\\" | ||
QDSpy_pathStimuli = os.path.join(QDSpy_path, "Stimuli") + os.path.sep | ||
QDSpy_autorunStimFileName = "__autorun" | ||
QDSpy_autorunDefFileName = "__autorun_default_DO_NOT_DELETE" | ||
|
||
|
@@ -87,10 +90,10 @@ | |
|
||
QDSpy_vidAllowedVideoExts = [".avi"] | ||
|
||
QDSpy_pathApplication = ".\\" | ||
QDSpy_iniFileName = "QDSpy.ini" | ||
QDSpy_pathApplication = QDSpy_path | ||
QDSpy_iniFileName = os.path.join(QDSpy_path, "QDSpy.ini") | ||
|
||
QDSpy_pathLogFiles = ".\\Logs\\" | ||
QDSpy_pathLogFiles = os.path.join(QDSpy_path, "Logs") + os.path.sep | ||
QDSpy_logFileExtension = ".log" | ||
QDSpy_doLogTimeStamps = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,12 @@ | |
__author__ = "[email protected]" | ||
|
||
import os.path | ||
import platform | ||
import configparser | ||
import QDSpy_stim as stm | ||
import QDSpy_global as glo | ||
import QDSpy_file_support as fsu | ||
import Libraries.log_helper as _log | ||
import Graphics.renderer_opengl as rdr | ||
|
||
PLATFORM_WINDOWS = platform.system() == "Windows" | ||
|
||
# --------------------------------------------------------------------- | ||
# Movie object class | ||
# --------------------------------------------------------------------- | ||
|
@@ -159,17 +155,9 @@ def load(self, _fName, _testOnly=False): | |
tempStr = (os.path.splitext(os.path.basename(_fName)))[0] | ||
self.fExtImg = os.path.splitext(_fName)[1].lower() | ||
self.isTestOnly = _testOnly | ||
|
||
if PLATFORM_WINDOWS: | ||
tempDir = os.path.dirname(_fName) | ||
if len(tempDir) > 0: | ||
tempDir += "\\" | ||
self.fNameDesc = tempDir + tempStr + glo.QDSpy_movDescFileExt | ||
self.fNameImg = _fName | ||
else: | ||
tempDir = os.getcwd() | ||
self.fNameDesc = fsu.repairPath(tempDir + tempStr) + glo.QDSpy_movDescFileExt | ||
self.fNameImg = fsu.repairPath(tempDir + tempStr) + self.fExtImg | ||
tempDir = os.path.dirname(_fName) | ||
self.fNameDesc = os.path.join(tempDir, tempStr) + glo.QDSpy_movDescFileExt | ||
self.fNameImg = _fName | ||
|
||
if self.fExtImg in glo.QDSpy_movAllowedMovieExts: | ||
return self.__loadMontage() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Very minor point] If you are switching to
os.path.join
everywhere, I think you can drop adding theos.path.sep
at the end, as it will be added any time you join a path onto this path.Also, if you are just starting on the task of reworking path management, I'd choose pathlib over os.path, as the former is easier to work with. Just my opinion though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure if at any points in the code that I missed we still use string concatenation (I searched for
\\
in the code and adapted all those occurrences, but there might be some I missed that make the asusmption that every path in the global.py file ends with a path separator.I only adjusted the code so far that my initial use case worked on Linux, which lead to the error in the PR description, and spend some effort to make the code consistent wrt to path concatenation. I would leave it at that, though. Also if you'd want to spend more time on it, feel free to directly adjust this PR to use pathlib.
Did you happen to use this branch? If so did it work, and did you use it on Windows or Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear both,
sorry for replying so late.
Path management can be really annoying and I agree with the need of a better solution.
However, I am not too happy with the solution you suggested @thomasZen because I expect side effects on the Windows users. I haven't tested the changes yet, but instead suggest a different procedure:
(1) The reason I introduced
QDSpy_file_support.py
was to have all path/file related functions in one place, where one can take care of OS-specific differences. Therefore, I suggest to change the functions there instead and adding support functions if needed, instead on patching the code. E.g., instead of addingos.path.join()
using a function inQDSpy_file_support.py
, where we can implement the function either withpathlib
oros.path
. (see below) This way, we prevent mixing the libraries and stay flexible.(2) I agree with @kevindoran in that
pathlib
is likely the better choice. I used it for a different project and had surprisingly free problems with paths on three different systems (Windows, Linux, and a proprietary DOS-like OS).I can try to make a suggestion based on
experimental
and your changes @thomasZen and then you can test, o.k.?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds good. I'm happy with testing anything on Linux.
Also feel free to delete this PR and branch once it's no longer needed.