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

Allow config_file to be a path-like object #128

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Feb 12, 2024

Currently XmiWrapper.initialize(config_file) only accepts str type. Attempting with a path-like object looks like this:

from pathlib import Path
sim_dir = Path("/path/to/sim")

obj = CustomXmiWrapper()
obj.initialize(sim_dir / "config.yaml")

File D:\src\xmipy\xmipy\xmiwrapper.py:140 in initialize
self._execute_function(self.lib.initialize, config_file.encode())

AttributeError: 'WindowsPath' object has no attribute 'encode'

This PR enables config_file to accept path-like objects too, using the preferred os.fsencode method to convert it to bytes.

Other changes in this PR change typing hints Path with PathLike, as there are several other classes that enable path-like interfaces.

Unfortunately, there is not easy place to add a test for this enhancement. Suggestions welcome!

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4bd60ee) 87.50% compared to head (4ec0c3c) 87.52%.

@@             Coverage Diff             @@
##           develop     #128      +/-   ##
===========================================
+ Coverage    87.50%   87.52%   +0.02%     
===========================================
  Files            7        7              
  Lines          520      521       +1     
===========================================
+ Hits           455      456       +1     
  Misses          65       65              
Files Coverage Δ
xmipy/xmiwrapper.py 87.33% <100.00%> (+0.03%) ⬆️

Copy link
Contributor

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

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

Thanks!

@Hofer-Julian Hofer-Julian merged commit 6ab5966 into Deltares:develop Feb 20, 2024
13 checks passed
@mwtoews mwtoews deleted the pathlib-config-file branch March 5, 2024 20:39
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.

None yet

2 participants