-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy path__init__.py
More file actions
225 lines (178 loc) · 6 KB
/
Copy path__init__.py
File metadata and controls
225 lines (178 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Astropy is a package intended to contain core functionality and some
common tools needed for performing astronomy and astrophysics research with
Python. It also provides an index for other astronomy packages and tools for
managing them.
"""
import sys
import warnings
from pathlib import Path
from astropy.utils.system_info import system_info
__all__ = [ # noqa: RUF100, RUF022
"__version__",
"__bibtex__",
# Subpackages (mostly lazy-loaded)
"config",
"constants",
"convolution",
"coordinates",
"cosmology",
"io",
"modeling",
"nddata",
"samp",
"stats",
"table",
"tests",
"time",
"timeseries",
"uncertainty",
"units",
"utils",
"visualization",
"wcs",
# Functions
"test",
"log",
"find_api_page",
"online_help",
"online_docs_root",
"conf",
"physical_constants",
"astronomical_constants",
"system_info",
]
def __getattr__(attr):
if attr in __all__:
from importlib import import_module
return import_module("astropy." + attr)
raise AttributeError(f"module 'astropy' has no attribute {attr!r}")
def __dir__():
return sorted(set(globals()).union(__all__))
from . import config as _config
from .version import version as __version__
class Conf(_config.ConfigNamespace):
"""
Configuration parameters for `astropy`.
"""
unicode_output = _config.ConfigItem(
False,
"When True, use Unicode characters when outputting values, and "
"displaying widgets at the console.",
)
use_color = _config.ConfigItem(
sys.platform != "win32",
"When True, use ANSI color escape sequences when writing to the console.",
aliases=["astropy.utils.console.USE_COLOR", "astropy.logger.USE_COLOR"],
)
max_lines = _config.ConfigItem(
None,
description=(
"Maximum number of lines in the display of pretty-printed "
"objects. If not provided, try to determine automatically from the "
"terminal size. Negative numbers mean no limit."
),
cfgtype="integer(default=None)",
aliases=["astropy.table.pprint.max_lines"],
)
max_width = _config.ConfigItem(
None,
description=(
"Maximum number of characters per line in the display of "
"pretty-printed objects. If not provided, try to determine "
"automatically from the terminal size. Negative numbers mean no "
"limit."
),
cfgtype="integer(default=None)",
aliases=["astropy.table.pprint.max_width"],
)
conf = Conf()
# Define a base ScienceState for configuring constants and units
from .utils.state import ScienceState
class base_constants_version(ScienceState):
"""
Base class for the real version-setters below.
"""
_value = "test"
_versions = dict(test="test")
@classmethod
def validate(cls, value):
if value not in cls._versions:
raise ValueError(f"Must be one of {list(cls._versions.keys())}")
return cls._versions[value]
@classmethod
def set(cls, value):
"""
Set the current constants value.
"""
import sys
if "astropy.units" in sys.modules:
raise RuntimeError("astropy.units is already imported")
if "astropy.constants" in sys.modules:
raise RuntimeError("astropy.constants is already imported")
return super().set(value)
class physical_constants(base_constants_version):
"""
The version of physical constants to use.
"""
# Maintainers: update when new constants are added
_value = "codata2022"
_versions = dict(
codata2022="codata2022",
codata2018="codata2018",
codata2014="codata2014",
codata2010="codata2010",
astropyconst80="codata2022",
astropyconst40="codata2018",
astropyconst20="codata2014",
astropyconst13="codata2010",
)
class astronomical_constants(base_constants_version):
"""
The version of astronomical constants to use.
"""
# Maintainers: update when new constants are added
_value = "iau2015"
_versions = dict(
iau2015="iau2015",
iau2012="iau2012",
astropyconst80="iau2015",
astropyconst40="iau2015",
astropyconst20="iau2015",
astropyconst13="iau2012",
)
# Create the test() function
from .tests.runner import TestRunner
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="The TestRunner")
test = TestRunner.make_test_runner_in(__path__[0])
# Set the bibtex entry to the article referenced in CITATION.
def _get_bibtex():
refs = (Path(__file__).parent / "CITATION").read_text().split("@ARTICLE")[1:]
return f"@ARTICLE{refs[0]}" if refs else ""
__citation__ = __bibtex__ = _get_bibtex()
from .logger import _init_log, _teardown_log
log = _init_log()
from types import ModuleType as __module_type__
from .utils.misc import find_api_page, online_docs_root, online_help
# Clean up top-level namespace--delete everything that isn't in __all__
# or is a magic attribute, and that isn't a submodule of this package
for varname in dir():
if not (
(varname.startswith("__") and varname.endswith("__"))
or varname in __all__
or (
varname[0] != "_"
and isinstance(locals()[varname], __module_type__)
and locals()[varname].__name__.startswith(__name__ + ".")
)
):
# The last clause in the above disjunction deserves explanation:
# When using relative imports like ``from .. import config``, the
# ``config`` variable is automatically created in the namespace of
# whatever module ``..`` resolves to (in this case astropy). This
# happens a few times just in the module setup above. This allows
# the cleanup to keep any public submodules of the astropy package
del locals()[varname]
del varname, __module_type__