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

Prefix non public submodules with _ #1689

Merged
merged 4 commits into from
Dec 5, 2023
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: "asdf/(extern||_jsonschema)/.*"
exclude: "asdf/(_extern||_jsonschema)/.*"
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion asdf/_block/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import yaml

from asdf import compression as mcompression
from asdf import _compression as mcompression
from asdf import constants, util

from .exceptions import BlockIndexError
Expand Down
2 changes: 1 addition & 1 deletion asdf/_block/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asdf import compression as mcompression
from asdf import _compression as mcompression
from asdf.config import get_config


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion asdf/_tests/core/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import yaml

import asdf
from asdf.core._integration import get_extensions, get_json_schema_resource_mappings
from asdf._core._integration import get_extensions, get_json_schema_resource_mappings


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tempfile
import threading

from asdf.extern.RangeHTTPServer import RangeHTTPRequestHandler
from asdf._extern.RangeHTTPServer import RangeHTTPRequestHandler

__all__ = ["HTTPServer", "RangeHTTPServer"]

Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/test_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest

from asdf import config_context
from asdf._entry_points import get_extensions
from asdf._tests._helpers import assert_no_warnings, assert_tree_match, yaml_to_asdf
from asdf.asdf import AsdfFile, open_asdf
from asdf.entry_points import get_extensions
from asdf.exceptions import AsdfWarning
from asdf.extension import ExtensionProxy
from asdf.versioning import AsdfVersion
Expand Down
14 changes: 7 additions & 7 deletions asdf/_tests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

import asdf
from asdf import compression, config_context, generic_io
from asdf import _compression, config_context, generic_io
from asdf._tests import _helpers as helpers
from asdf.extension import Compressor, Extension

Expand Down Expand Up @@ -71,27 +71,27 @@ def test_invalid_compression():
with pytest.raises(ValueError, match=r"Invalid compression type: foo"):
ff.set_array_compression(tree["science_data"], "foo")
with pytest.raises(ValueError, match=r"Unknown compression type: .*"):
compression._get_compressor("foo")
_compression._get_compressor("foo")


def test_get_compressed_size():
assert compression.get_compressed_size(b"0" * 1024, "zlib") < 1024
assert _compression.get_compressed_size(b"0" * 1024, "zlib") < 1024


def test_decompress_too_long_short():
fio = io.BytesIO()
compression.compress(fio, b"0" * 1024, "zlib")
_compression.compress(fio, b"0" * 1024, "zlib")
size = fio.tell()
fio.seek(0)
blocks = lambda us: [fio.read(us)] # noqa: E731
fio.read_blocks = blocks
compression.decompress(fio, size, 1024, "zlib")
_compression.decompress(fio, size, 1024, "zlib")
fio.seek(0)
with pytest.raises(ValueError, match=r"Decompressed data wrong size"):
compression.decompress(fio, size, 1025, "zlib")
_compression.decompress(fio, size, 1025, "zlib")
fio.seek(0)
with pytest.raises(ValueError, match=r"memoryview assignment: lvalue and rvalue have different structures"):
compression.decompress(fio, size, 1023, "zlib")
_compression.decompress(fio, size, 1023, "zlib")


def test_zlib(tmp_path):
Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import asdf
from asdf import get_config
from asdf.core._integration import get_json_schema_resource_mappings
from asdf._core._integration import get_json_schema_resource_mappings
from asdf.extension import ExtensionProxy
from asdf.resource import ResourceMappingProxy

Expand Down
22 changes: 11 additions & 11 deletions asdf/_tests/test_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import importlib_metadata as metadata
import pytest

from asdf import entry_points
from asdf import _entry_points
from asdf._version import version as asdf_package_version
from asdf.exceptions import AsdfWarning
from asdf.extension import ExtensionProxy
Expand All @@ -20,15 +20,15 @@ def mock_entry_points():

@pytest.fixture(autouse=True)
def _monkeypatch_entry_points(monkeypatch, mock_entry_points):
def _entry_points(*, group):
def patched_entry_points(*, group):
for candidate_group, name, func_name in mock_entry_points:
if candidate_group == group:
point = metadata.EntryPoint(name=name, group=group, value=func_name)
vars(point).update(dist=metadata.distribution("asdf"))

yield point

monkeypatch.setattr(entry_points, "entry_points", _entry_points)
monkeypatch.setattr(_entry_points, "entry_points", patched_entry_points)


def resource_mappings_entry_point_successful():
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_get_resource_mappings(mock_entry_points):
"asdf._tests.test_entry_points:resource_mappings_entry_point_successful",
),
)
mappings = entry_points.get_resource_mappings()
mappings = _entry_points.get_resource_mappings()
assert len(mappings) == 2
for m in mappings:
assert isinstance(m, ResourceMappingProxy)
Expand All @@ -71,7 +71,7 @@ def test_get_resource_mappings(mock_entry_points):
("asdf.resource_mappings", "failing", "asdf._tests.test_entry_points:resource_mappings_entry_point_failing"),
)
with pytest.warns(AsdfWarning, match=r"Exception: NOPE"):
mappings = entry_points.get_resource_mappings()
mappings = _entry_points.get_resource_mappings()
assert len(mappings) == 0

mock_entry_points.clear()
Expand All @@ -83,7 +83,7 @@ def test_get_resource_mappings(mock_entry_points):
),
)
with pytest.warns(AsdfWarning, match=r"TypeError: Resource mapping must implement the Mapping interface"):
mappings = entry_points.get_resource_mappings()
mappings = _entry_points.get_resource_mappings()
assert len(mappings) == 2


Expand Down Expand Up @@ -130,7 +130,7 @@ def test_get_extensions(mock_entry_points):
mock_entry_points.append(
("asdf.extensions", "successful", "asdf._tests.test_entry_points:extensions_entry_point_successful"),
)
extensions = entry_points.get_extensions()
extensions = _entry_points.get_extensions()
assert len(extensions) == 2
for e in extensions:
assert isinstance(e, ExtensionProxy)
Expand All @@ -142,7 +142,7 @@ def test_get_extensions(mock_entry_points):
("asdf.extensions", "failing", "asdf._tests.test_entry_points:extensions_entry_point_failing"),
)
with pytest.warns(AsdfWarning, match=r"Exception: NOPE"):
extensions = entry_points.get_extensions()
extensions = _entry_points.get_extensions()
assert len(extensions) == 0

mock_entry_points.clear()
Expand All @@ -153,16 +153,16 @@ def test_get_extensions(mock_entry_points):
AsdfWarning,
match=r"TypeError: Extension must implement the Extension interface",
):
extensions = entry_points.get_extensions()
extensions = _entry_points.get_extensions()
assert len(extensions) == 2

mock_entry_points.clear()
mock_entry_points.append(("asdf_extensions", "legacy", "asdf._tests.test_entry_points:LegacyExtension"))
extensions = entry_points.get_extensions()
extensions = _entry_points.get_extensions()
assert len(extensions) == 0 # asdf_extensions is no longer supported

mock_entry_points.clear()
mock_entry_points.append(("asdf.extensions", "failing", "asdf._tests.test_entry_points:FauxLegacyExtension"))
with pytest.warns(AsdfWarning, match=r"TypeError"):
extensions = entry_points.get_extensions()
extensions = _entry_points.get_extensions()
assert len(extensions) == 0
2 changes: 1 addition & 1 deletion asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from packaging.version import Version

from . import _compression as mcompression
from . import _display as display
from . import _node_info as node_info
from . import _version as version
from . import compression as mcompression
from . import constants, generic_io, reference, schema, treeutil, util, versioning, yamlutil
from ._block.manager import Manager as BlockManager
from ._helpers import validate_version
Expand Down
2 changes: 1 addition & 1 deletion asdf/commands/extension.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Implementation of command for reporting information about installed extensions.
"""
from asdf.entry_points import get_extensions
from asdf._entry_points import get_extensions

from .main import Command

Expand Down
8 changes: 4 additions & 4 deletions asdf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading
from contextlib import contextmanager

from . import entry_points, util, versioning
from . import _entry_points, util, versioning
from ._helpers import validate_version
from .extension import ExtensionProxy
from .resource import ResourceManager, ResourceMappingProxy
Expand Down Expand Up @@ -63,7 +63,7 @@ def resource_mappings(self):
if self._resource_mappings is None:
with self._lock:
if self._resource_mappings is None:
self._resource_mappings = entry_points.get_resource_mappings()
self._resource_mappings = _entry_points.get_resource_mappings()
return self._resource_mappings

def add_resource_mapping(self, mapping):
Expand Down Expand Up @@ -155,7 +155,7 @@ def extensions(self):
if self._extensions is None:
with self._lock:
if self._extensions is None:
self._extensions = entry_points.get_extensions()
self._extensions = _entry_points.get_extensions()
return self._extensions

def add_extension(self, extension):
Expand Down Expand Up @@ -371,7 +371,7 @@ def all_array_compression(self):
@all_array_compression.setter
def all_array_compression(self, value):
# local to avoid circular import
from asdf.compression import validate
from asdf._compression import validate

self._all_array_compression = validate(value)

Expand Down
2 changes: 1 addition & 1 deletion asdf/generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import numpy as np

from . import util
from ._extern import atomicfile
from .exceptions import DelimiterNotFoundError
from .extern import atomicfile
from .util import _patched_urllib_parse

__all__ = ["get_file", "get_uri", "resolve_uri", "relative_uri"]
Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ tests = [
'repository' = 'https://github.com/asdf-format/asdf'
'tracker' = 'https://github.com/asdf-format/asdf/issues'
[project.entry-points]
'asdf.extensions' = {asdf = 'asdf.core._integration:get_extensions'}
'asdf.resource_mappings' = {asdf = 'asdf.core._integration:get_json_schema_resource_mappings'}
'asdf.extensions' = {asdf = 'asdf._core._integration:get_extensions'}
'asdf.resource_mappings' = {asdf = 'asdf._core._integration:get_json_schema_resource_mappings'}
asdf_extensions = {builtin = 'asdf.extension._legacy:BuiltinExtension'}
console_scripts = {asdftool = 'asdf.commands.main:main'}
pytest11 = {asdf_schema_tester = 'pytest_asdf.plugin'}
Expand Down Expand Up @@ -90,7 +90,7 @@ force-exclude = '''
| \.git
| \.pytest_cache
| \.tox
| asdf/extern
| asdf/_extern
| asdf/_jsonschema
| build
| dist
Expand Down Expand Up @@ -126,7 +126,7 @@ omit = [
'asdf/*/*/tests/*',
'asdf/version.*',
'asdf/compat*',
'asdf/extern*',
'asdf/_extern*',
'asdf/_jsonschema/**',
# And again for running against installed version
'*/asdf/_astropy_init*',
Expand All @@ -141,7 +141,7 @@ omit = [
'*/asdf/*/*/tests/*',
'*/asdf/version.*',
'*/asdf/compat*',
'*/asdf/extern*',
'*/asdf/_extern*',
'*/asdf/_jsonschema/**',
]

Expand Down Expand Up @@ -176,18 +176,18 @@ extend-ignore = [
"S310", # URL open for permitted schemes
"RUF012", # mutable-class-default (typing related)
]
extend-exclude = ["asdf/extern/*", "asdf/_jsonschema/*", "docs/*"]
extend-exclude = ["asdf/_extern/*", "asdf/_jsonschema/*", "docs/*"]

[tool.ruff.per-file-ignores]
"test_*.py" = ["S101"]
"asdf/_tests/_helpers.py" = ["S101"]
"compatibility_tests/common.py" = ["S101"]

[tool.flynt]
exclude = ["asdf/extern/*", "asdf/_jsonschema/*"]
exclude = ["asdf/_extern/*", "asdf/_jsonschema/*"]

[tool.codespell]
skip="*.pdf,*.asdf,.tox,asdf/extern,asdf/_jsonschema,build,./tags,.git,docs/_build"
skip="*.pdf,*.asdf,.tox,asdf/_extern,asdf/_jsonschema,build,./tags,.git,docs/_build"
ignore-words-list="""
fo,afile,
"""
Loading