Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
ironpython3/Src/StdLib/Lib/importlib/__init__.py at python-stdlib · cppfool/ironpython3 · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
cppfool
/
ironpython3
Public
forked from
IronLanguages/ironpython3
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
python-stdlib
Breadcrumbs
ironpython3
/
Src
/
StdLib
/
Lib
/
importlib
/
__init__.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
151 lines (123 loc) · 4.87 KB
python-stdlib
Breadcrumbs
ironpython3
/
Src
/
StdLib
/
Lib
/
importlib
/
__init__.py
Copy path
Top
File metadata and controls
Code
Blame
151 lines (123 loc) · 4.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""A pure Python implementation of import."""
__all__
=
[
'__import__'
,
'import_module'
,
'invalidate_caches'
,
'reload'
]
# Bootstrap help #####################################################
# Until bootstrapping is complete, DO NOT import any modules that attempt
# to import importlib._bootstrap (directly or indirectly). Since this
# partially initialised package would be present in sys.modules, those
# modules would get an uninitialised copy of the source version, instead
# of a fully initialised version (either the frozen one or the one
# initialised below if the frozen one is not available).
import
_imp
# Just the builtin component, NOT the full Python module
import
sys
try
:
import
_frozen_importlib
as
_bootstrap
except
ImportError
:
from
.
import
_bootstrap
_bootstrap
.
_setup
(
sys
,
_imp
)
else
:
# importlib._bootstrap is the built-in import, ensure we don't create
# a second copy of the module.
_bootstrap
.
__name__
=
'importlib._bootstrap'
_bootstrap
.
__package__
=
'importlib'
_bootstrap
.
__file__
=
__file__
.
replace
(
'__init__.py'
,
'_bootstrap.py'
)
sys
.
modules
[
'importlib._bootstrap'
]
=
_bootstrap
# To simplify imports in test code
_w_long
=
_bootstrap
.
_w_long
_r_long
=
_bootstrap
.
_r_long
# Fully bootstrapped at this point, import whatever you like, circular
# dependencies and startup overhead minimisation permitting :)
import
types
import
warnings
# Public API #########################################################
from
.
_bootstrap
import
__import__
def
invalidate_caches
():
"""Call the invalidate_caches() method on all meta path finders stored in
sys.meta_path (where implemented)."""
for
finder
in
sys
.
meta_path
:
if
hasattr
(
finder
,
'invalidate_caches'
):
finder
.
invalidate_caches
()
def
find_loader
(
name
,
path
=
None
):
"""Return the loader for the specified module.
This is a backward-compatible wrapper around find_spec().
This function is deprecated in favor of importlib.util.find_spec().
"""
warnings
.
warn
(
'Use importlib.util.find_spec() instead.'
,
DeprecationWarning
,
stacklevel
=
2
)
try
:
loader
=
sys
.
modules
[
name
].
__loader__
if
loader
is
None
:
raise
ValueError
(
'{}.__loader__ is None'
.
format
(
name
))
else
:
return
loader
except
KeyError
:
pass
except
AttributeError
:
raise
ValueError
(
'{}.__loader__ is not set'
.
format
(
name
))
spec
=
_bootstrap
.
_find_spec
(
name
,
path
)
# We won't worry about malformed specs (missing attributes).
if
spec
is
None
:
return
None
if
spec
.
loader
is
None
:
if
spec
.
submodule_search_locations
is
None
:
raise
ImportError
(
'spec for {} missing loader'
.
format
(
name
),
name
=
name
)
raise
ImportError
(
'namespace packages do not have loaders'
,
name
=
name
)
return
spec
.
loader
def
import_module
(
name
,
package
=
None
):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
level
=
0
if
name
.
startswith
(
'.'
):
if
not
package
:
msg
=
(
"the 'package' argument is required to perform a relative "
"import for {!r}"
)
raise
TypeError
(
msg
.
format
(
name
))
for
character
in
name
:
if
character
!=
'.'
:
break
level
+=
1
return
_bootstrap
.
_gcd_import
(
name
[
level
:],
package
,
level
)
_RELOADING
=
{}
def
reload
(
module
):
"""Reload the module and return it.
The module must have been successfully imported before.
"""
if
not
module
or
not
isinstance
(
module
,
types
.
ModuleType
):
raise
TypeError
(
"reload() argument must be module"
)
try
:
name
=
module
.
__spec__
.
name
except
AttributeError
:
name
=
module
.
__name__
if
sys
.
modules
.
get
(
name
)
is
not
module
:
msg
=
"module {} not in sys.modules"
raise
ImportError
(
msg
.
format
(
name
),
name
=
name
)
if
name
in
_RELOADING
:
return
_RELOADING
[
name
]
_RELOADING
[
name
]
=
module
try
:
parent_name
=
name
.
rpartition
(
'.'
)[
0
]
if
parent_name
:
try
:
parent
=
sys
.
modules
[
parent_name
]
except
KeyError
:
msg
=
"parent {!r} not in sys.modules"
raise
ImportError
(
msg
.
format
(
parent_name
),
name
=
parent_name
)
else
:
pkgpath
=
parent
.
__path__
else
:
pkgpath
=
None
target
=
module
spec
=
module
.
__spec__
=
_bootstrap
.
_find_spec
(
name
,
pkgpath
,
target
)
methods
=
_bootstrap
.
_SpecMethods
(
spec
)
methods
.
exec
(
module
)
# The module may have replaced itself in sys.modules!
return
sys
.
modules
[
name
]
finally
:
try
:
del
_RELOADING
[
name
]
except
KeyError
:
pass
You can’t perform that action at this time.