Skip to content

Commit

Permalink
Remove srctools.__version__ in favour of using importlib.metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Sep 3, 2024
1 parent 3674e8a commit f5c8c22
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
try:
release = os.environ['READTHEDOCS_VERSION_NAME']
except KeyError:
import srctools
release = srctools.__version__
import importlib.metadata
release = importlib.metadata.version('srctools')


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'srctools',
'cython', 'c', 'cpp',
version: '2.3.14',
version: '2.4.0',
)

fs = import('fs')
Expand Down
21 changes: 9 additions & 12 deletions src/srctools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@
import io
import itertools as _itertools
import os as _os
import sys as _sys
import warnings

from useful_types import SupportsKeysAndGetItem


__version__: str
if not TYPE_CHECKING:
try:
from ._version import __version__
except ImportError:
__version__ = '<unknown>'
else:
# Discard the now-useless module. Use globals so static analysis ignores this.
del _sys.modules[globals().pop('_version').__name__]

__all__ = [
'__version__',
'Vec', 'FrozenVec', 'parse_vec_str', 'lerp',
'Angle', 'FrozenAngle', 'Matrix', 'FrozenMatrix',

Expand Down Expand Up @@ -594,6 +582,7 @@ def __exit__(

if TYPE_CHECKING:
Property = Keyvalues #: :deprecated: Use srctools.Keyvalues.
__version__: str #: :deprecated: Use importlib.metadata instead.
else:
def __getattr__(name: str) -> object:
if name == 'Property':
Expand All @@ -603,6 +592,14 @@ def __getattr__(name: str) -> object:
stacklevel=2,
)
return Keyvalues
elif name == '__version__':
warnings.warn(
'Use importlib.metadata instead.',
DeprecationWarning,
stacklevel=2,
)
from importlib.metadata import version
return version('srctools')
raise AttributeError(name)

try:
Expand Down
1 change: 0 additions & 1 deletion src/srctools/_version.input.py

This file was deleted.

6 changes: 1 addition & 5 deletions src/srctools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pure_python = files(
'_shaderdb.py',
'binformat.py',
'bsp.py',
'choreo.py',
'cmdseq.py',
'const.py',
'dmx.py',
Expand Down Expand Up @@ -37,11 +38,6 @@ pure_python += files(
'fgd.lzma',
)

pure_python += vcs_tag(
input: '_version.input.py',
output: '_version.py',
).full_path()

py.install_sources(pure_python, subdir: 'srctools')

subdir('_pyinstaller')
Expand Down

0 comments on commit f5c8c22

Please sign in to comment.