From ae982a2afbb199ed5b20e59d233b3a2a49d4e6a6 Mon Sep 17 00:00:00 2001 From: nuwang <2070605+nuwang@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:03:24 +0530 Subject: [PATCH 1/3] Add initializers to filesource options --- lib/galaxy/files/sources/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index d369fcfe4293..cc6c854a36c1 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -53,13 +53,18 @@ class FilesSourceProperties(TypedDict): class FilesSourceOptions: - """Options to control behaviour of filesource operations, such as realize_to and write_from""" + """Options to control behavior of file source operations, such as realize_to, write_from and list.""" + + # Indicates access to the FS operation with intent to write. + # Even if a file source is "writeable" some directories (or elements) may be restricted or read-only + # so those should be skipped while browsing with writeable=True. + writeable: Optional[bool] = False # Property overrides for values initially configured through the constructor. For example # the HTTPFilesSource passes in additional http_headers through these properties, which # are merged with constructor defined http_headers. The interpretation of these properties # are filesystem specific. - extra_props: Optional[FilesSourceProperties] + extra_props: Optional[FilesSourceProperties] = {} class SingleFileSource(metaclass=abc.ABCMeta): From bffb7a99c50aeaafe8f4314d844f23d602e8f010 Mon Sep 17 00:00:00 2001 From: nuwang <2070605+nuwang@users.noreply.github.com> Date: Fri, 9 Feb 2024 15:57:29 +0530 Subject: [PATCH 2/3] Use dataclass to initialize default values --- lib/galaxy/files/sources/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index cc6c854a36c1..24cf91f654e7 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -1,4 +1,5 @@ import abc +from dataclasses import dataclass, field import os import time from typing import ( @@ -52,6 +53,7 @@ class FilesSourceProperties(TypedDict): browsable: NotRequired[bool] +@dataclass class FilesSourceOptions: """Options to control behavior of file source operations, such as realize_to, write_from and list.""" @@ -64,7 +66,7 @@ class FilesSourceOptions: # the HTTPFilesSource passes in additional http_headers through these properties, which # are merged with constructor defined http_headers. The interpretation of these properties # are filesystem specific. - extra_props: Optional[FilesSourceProperties] = {} + extra_props: Optional[FilesSourceProperties] = field(default_factory=lambda: {}) class SingleFileSource(metaclass=abc.ABCMeta): From c7a5e4ff59cd93b3f336a6676c77524db51f0357 Mon Sep 17 00:00:00 2001 From: Nuwan Goonasekera <2070605+nuwang@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:41:45 +0530 Subject: [PATCH 3/3] Code review suggestion Co-authored-by: Marius van den Beek --- lib/galaxy/files/sources/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index 24cf91f654e7..40c2081d01c5 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -1,7 +1,10 @@ import abc -from dataclasses import dataclass, field import os import time +from dataclasses import ( + dataclass, + field, +) from typing import ( Any, ClassVar, @@ -66,7 +69,7 @@ class FilesSourceOptions: # the HTTPFilesSource passes in additional http_headers through these properties, which # are merged with constructor defined http_headers. The interpretation of these properties # are filesystem specific. - extra_props: Optional[FilesSourceProperties] = field(default_factory=lambda: {}) + extra_props: Optional[FilesSourceProperties] = field(default_factory=lambda: FilesSourceProperties()) class SingleFileSource(metaclass=abc.ABCMeta):