Skip to content

Conversation

PProfizi
Copy link
Contributor

@PProfizi PProfizi commented Mar 8, 2022

#186
Add support for pathlib.Path and other os.PathLike objects as inputs for file paths.

  • using in conftest.py:
from pathlib import Path
@pytest.fixture(params=[str, Path])
def allkindofcomplexity(request):
    """Resolve the path of the "allKindOfComplexity.rst" result file."""
    return request.param(examples.download_all_kinds_of_complexity())

to detect where tests fail due to a Path object being given instead of a string.

  • modifying for them all to pass
  • reverting the conftest and adding several selected tests where a Path is indeed given as input

PProfizi added 2 commits March 8, 2022 11:21
- modifications and updated docstrings, no tests
- modified Operator.connect() and updated docstring, no tests. Removed prior direct changes to operators
@PProfizi PProfizi requested a review from cbellot000 March 8, 2022 16:34
PProfizi added 3 commits March 9, 2022 09:34
…sts types.

Several tests in test_pathsupport.py covering most (all?) points of entry for paths.
Modified test_elements.py test_descriptor_with_int_value which was getting allkindofcomplexity for no apparent reason.
@PProfizi PProfizi marked this pull request as ready for review March 9, 2022 09:16
@PProfizi PProfizi requested a review from cbellot000 March 9, 2022 09:16
Parameters
----------
server_folder_path : str
server_folder_path : str or os.PathLike
Copy link
Contributor

Choose a reason for hiding this comment

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

@PProfizi could you please download the built doc out of the github actions and make sure that the API documentation of what you changed looks good? Because I'm afraid the "or" will not, since we always use ","

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000
Ok I'll change that. I started using "or" because a lot of times there was already "str, optional" and adding a coma seemed more confusing to me (like: "str, os.PathLike, optional").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 I found an example of docstring similar to what I did here:

fields_container (ansys.grpc.dpf.collection_pb2.Collection or FieldsContainer, optional)

in

class ansys.dpf.core.custom_fields_container.ElShapeFieldsContainer(fields_container=None, server=None)

server = None
parts = []
for a in args:
if isinstance(a, str) and len(a) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

you can make it simpler with:

if isinstance(a, (str, Path)) and len(str(a)) > 0:
    parts.append(str(a))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is for an empty Path, its str representation is "." which is not of length==0, thus my choice of doing a separate test. If I understood correctly, this is to check the path is not empty (so an empty string OR an empty Path then?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, didnt ping you when replying @cbellot000

Copy link
Contributor

Choose a reason for hiding this comment

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

or we could do:

if isinstance(a, (str, Path)) and Path(a) != Path(""):
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jfthuong works for me! Modifying now.

@PProfizi PProfizi merged commit f56da6a into master Mar 10, 2022
@PProfizi PProfizi deleted the fix/Issue#186_PathLike_support branch March 10, 2022 09:23
@PProfizi PProfizi self-assigned this Jun 9, 2022
@PProfizi PProfizi linked an issue Jun 9, 2022 that may be closed by this pull request
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.

[Enhancement] Paths arguments should support pathlib.Path

3 participants