try:
- from importlib import metadata as importlib_metadata # py3.8+ stdlib
+ try:
+ from importlib import metadata as importlib_metadata # py3.8+ stdlib
+ except ImportError:
+ import importlib_metadata # py3.7- shim
+ __version__ = importlib_metadata.version(__package__)
except ImportError:
- import importlib_metadata # py3.7- shim
-__version__ = importlib_metadata.version(__package__)
+ # No importlib_metadata. This shouldn't normally happen, but some people prefer not installing
+ # packages via pip at all, instead using PYTHONPATH directly or copying the package files into
+ # `lib/pythonX.Y/site-packages`. Although not a recommended way, we still try to support it.
+ __version__ = "unknown"
from .hdl import *
except ImportError:
importlib_metadata = None # not installed
try:
- from importlib import resources as importlib_resources
try:
- importlib_resources.files # py3.9+ stdlib
- except AttributeError:
- import importlib_resources # py3.8- shim
+ from importlib import resources as importlib_resources
+ try:
+ importlib_resources.files # py3.9+ stdlib
+ except AttributeError:
+ import importlib_resources # py3.8- shim
+ except ImportError:
+ import importlib_resources # py3.6- shim
except ImportError:
- import importlib_resources # py3.6- shim
+ importlib_resources = None
from ._toolchain import has_tool, require_tool
@classmethod
def available(cls):
- if importlib_metadata is None:
+ if importlib_metadata is None or importlib_resources is None:
return False
try:
importlib_metadata.version(cls.YOSYS_PACKAGE)