Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions khiops/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def train_predictor(

# Return the paths of the JSON report and modelling dictionary file
if target_variable != "":
current_dir = fs.parent_path(analysis_report_file_path)
current_dir = fs.get_parent_path(analysis_report_file_path)
report_file_name, _ = os.path.splitext(
os.path.basename(analysis_report_file_path)
)
Expand Down Expand Up @@ -1320,7 +1320,7 @@ def train_recoder(
_run_task("train_recoder", task_args)

# Return the paths of the JSON report and modelling dictionary file
current_dir = fs.parent_path(analysis_report_file_path)
current_dir = fs.get_parent_path(analysis_report_file_path)
report_file_name, _ = os.path.splitext(os.path.basename(analysis_report_file_path))

modeling_dictionary_file_path = fs.get_child_path(
Expand Down
2 changes: 1 addition & 1 deletion khiops/core/coclustering_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class CoclusteringDimension:
Contains the dimensions of the variables involved in the
instances x variables coclustering model.
This model includes two dimensions: one for instances and one for variable
parts (`isVarPart` set to ``True`` for this dimension).
parts (``isVarPart`` set to ``True`` for this dimension).
clusters : list of `CoclusteringCluster`
Clusters of this dimension's hierarchy. Note that includes intermediary
clusters.
Expand Down
170 changes: 88 additions & 82 deletions khiops/core/internals/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,81 @@

# pylint: enable=invalid-name

#######################
## Private functions ##
#######################


def _parent_path(path):
r"""Returns the parent of the specified path

Notes
-----
This function always returns a posix path ("/" as separator). For example for the
windows path::

C:\Program Files\khiops

this method returns::

C:/Program Files
"""
return Path(path).parent.as_posix()


def _parent_uri_info(uri_info):
"""Creates the parent for the input URI info

Parameters
----------
uri_info : `urllib.parse.ParseResult`
URI info structure (output of `urllib.parse.urlparse`)

Returns
-------
`urllib.parse.ParseResult`
URI info structure for the parent URI

"""
return uri_info._replace(path=_parent_path(uri_info.path))


def _child_path(path, child_name):
r"""Creates a path with a child appended

Notes
-----
This function always returns a posix path ("/" as separator). For example for the
windows path and child name::

parent: C:\Program Files
child: khiops

this method returns::
C:/Program Files/khiops
"""
return Path(path).joinpath(child_name).as_posix()


def _child_uri_info(uri_info, child_name):
r"""Creates a URI info with a path with child appended

Parameters
----------
uri_info : `urllib.parse.ParseResult`
URI info structure (output of `urllib.parse.urlparse`)

child_name : str
Name of the new childe node

Returns
-------
`urllib.parse.ParseResult`
URI info structure for the child URI
"""
return uri_info._replace(path=_child_path(uri_info.path, child_name))


######################
## Helper Functions ##
######################
Expand Down Expand Up @@ -138,76 +213,6 @@ def create_resource(uri_or_path):
return LocalFilesystemResource(uri_or_path)


def parent_path(path):
r"""Returns the parent of the specified path

Notes
-----
This function always return a posix path ("/" as separator). For example for the
windows path::

C:\Program Files\khiops

this method returns::

C:/Program Files
"""
return Path(path).parent.as_posix()


def parent_uri_info(uri_info):
"""Creates the parent for the input URI info

Parameters
----------
uri_info : `urllib.parse.ParseResult`
URI info structure (output of `urllib.parse.urlparse`)

Returns
-------
`urllib.parse.ParseResult`
URI info structure for the parent URI

"""
return uri_info._replace(path=parent_path(uri_info.path))


def child_path(path, child_name):
r"""Creates a path with a child appended

Notes
-----
This function always return a posix path ("/" as separator). For example for the
windows path and child name::

parent: C:\Program Files
child: khiops

this method returns::
C:/Program Files/khiops
"""
return Path(path).joinpath(child_name).as_posix()


def child_uri_info(uri_info, child_name):
r"""Creates a URI info with a path with child appended

Parameters
----------
uri_info : `urllib.parse.ParseResult`
URI info structure (output of `urllib.parse.urlparse`)

child_name : str
Name of the new childe node

Returns
-------
`urllib.parse.ParseResult`
URI info structure for the child URI
"""
return uri_info._replace(path=child_path(uri_info.path, child_name))


##############
## Main API ##
##############
Expand Down Expand Up @@ -373,7 +378,7 @@ def get_child_path(uri_or_path, child_name):


def get_parent_path(uri_or_path):
"""Returns the specified parent path of this URI
"""Returns the parent path of this URI

Parameters
----------
Expand Down Expand Up @@ -523,7 +528,7 @@ def create_child(self, file_name):
return create_resource(os.path.join(self.path, file_name))

def create_parent(self):
return create_resource(parent_path(self.path))
return create_resource(_parent_path(self.path))


class GoogleCloudStorageResource(FilesystemResource):
Expand Down Expand Up @@ -592,10 +597,10 @@ def make_dir(self):
)

def create_child(self, file_name):
return create_resource(child_uri_info(self.uri_info, file_name).geturl())
return create_resource(_child_uri_info(self.uri_info, file_name).geturl())

def create_parent(self):
return create_resource(parent_uri_info(self.uri_info).geturl())
return create_resource(_parent_uri_info(self.uri_info).geturl())


# Avoid pylint complaining on dynamic class returned by boto3 API
Expand Down Expand Up @@ -752,10 +757,10 @@ def make_dir(self):
)

def create_child(self, file_name):
return create_resource(child_uri_info(self.uri_info, file_name).geturl())
return create_resource(_child_uri_info(self.uri_info, file_name).geturl())

def create_parent(self):
return create_resource(parent_uri_info(self.uri_info).geturl())
return create_resource(_parent_uri_info(self.uri_info).geturl())


# pylint: enable=no-member
Expand Down Expand Up @@ -806,10 +811,10 @@ def __init__(self, uri):
)

def create_child(self, file_name):
return create_resource(child_uri_info(self.uri_info, file_name).geturl())
return create_resource(_child_uri_info(self.uri_info, file_name).geturl())

def create_parent(self, file_name): # pylint: disable=unused-argument
return create_resource(parent_uri_info(self.uri_info).geturl())
return create_resource(_parent_uri_info(self.uri_info).geturl())

def _uri_parts(self):
return [part for part in self.uri_info.path.split("/") if len(part) > 0]
Expand All @@ -828,7 +833,7 @@ class AzureStorageFileResource(AzureStorageResourceMixin, FilesystemResource):

For shared Files, the URI pattern of a resource is the following :
https://<storage-account-name>.file.core.windows.net/<share name>/...
<0 to n folder name(s)>/<file name>
<0 to n folder name(s)>/<file name>.
The first name after the netloc is the "share name" not a simple "folder name".

By default, this resource reads the configuration from standard location
Expand Down Expand Up @@ -913,8 +918,9 @@ def copy_to_local(self, local_path):

def list_dir(self):
"""List the files (not the directories) of the current directory
Notes:
This is not a recursive listing operation

.. note::
This is not a recursive listing operation.
"""

return [
Expand Down Expand Up @@ -957,7 +963,7 @@ class AzureStorageBlobResource(AzureStorageResourceMixin, FilesystemResource):

For blobs, the URI pattern of a resource is the following:
https://<storage-account-name>.blob.core.windows.net/<container name>/...
<0 to n virtual folder name(s)>/<blob name>
<0 to n virtual folder name(s)>/<blob name>.
The "virtual folder names" are part of the blob name but can help simulate
a folder hierarchy.
The first name after the netloc is the "container name" not a simple
Expand Down
Loading