Skip to content

Commit bcb0f72

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Add builders defined in packages only when TFDS PUBLIC is visible
PiperOrigin-RevId: 713279260
1 parent 606754a commit bcb0f72

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

tensorflow_datasets/core/registered.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ def list_imported_builders() -> list[str]:
422422
builder_name
423423
for builder_name, builder_cls in _DATASET_REGISTRY.items()
424424
if _is_builder_available(builder_cls)
425-
] + list(_get_existing_dataset_packages(constants.DATASETS_TFDS_SRC_DIR))
425+
]
426+
if visibility.DatasetType.TFDS_PUBLIC.is_available():
427+
all_builders += list(
428+
_get_existing_dataset_packages(constants.DATASETS_TFDS_SRC_DIR)
429+
)
426430
return sorted(all_builders)
427431

428432

tensorflow_datasets/core/visibility_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Tests for tensorflow_datasets.core.visibility."""
17-
1816
import tensorflow_datasets as tfds
1917
from tensorflow_datasets.core import visibility
2018

@@ -28,3 +26,9 @@ def test_visibility():
2826
# `absl.app` should detect the TFDS script and restrict the visibility
2927
# to TFDS public by default.
3028
assert visibility._current_available == {visibility.DatasetType.TFDS_PUBLIC}
29+
assert 'mnist' in tfds.list_builders()
30+
assert 'abstract_reasoning' in tfds.list_builders()
31+
# Remove all visibility and check that the datasets are not available.
32+
with visibility.set_availables_tmp([]):
33+
assert 'mnist' not in tfds.list_builders()
34+
assert 'abstract_reasoning' not in tfds.list_builders()

0 commit comments

Comments
 (0)