Skip to content

Commit fe3e331

Browse files
committed
#3482 Remove sphinx.stringify_annotations use
1 parent 320a000 commit fe3e331

8 files changed

Lines changed: 9 additions & 118 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ jobs:
119119
# Uncomment the below to use the submodule version of fparser rather
120120
# than the latest release from pypi.
121121
# pip install external/fparser
122-
# We need to install sphinx to get correct doc testing
123-
pip install .[doc]
124122
pip install .[test,treesitter]
125123
- name: Lint with flake8
126124
run: |

doc/developer_guide/pip_requirements.txt

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/psyclone/docstring_parser.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,8 @@ def create_docstring_data(args: List[str], desc: str,
534534
535535
:returns: An object representing the input arg and desc.
536536
'''
537-
# Import here to disable circular dependency if Sphinx isn't available.
538-
try:
539-
# pylint: disable=import-outside-toplevel
540-
from sphinx.util.typing import stringify_annotation
541-
except ImportError:
542-
# pylint: disable=import-outside-toplevel
543-
from psyclone.utils import stringify_annotation
537+
# pylint: disable=import-outside-toplevel
538+
from psyclone.utils import stringify_annotation
544539
# If its a param then we can create an ArgumentData for this.
545540
if args[0] == "param":
546541
if len(args) == 2:

src/psyclone/psyGen.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@
5151
from typing import Any, Dict, Optional, Union
5252
import warnings
5353

54-
try:
55-
from sphinx.util.typing import stringify_annotation
56-
except ImportError:
57-
# No Sphinx available so use our own, simpler version.
58-
from psyclone.utils import stringify_annotation
5954

6055
from psyclone.configuration import Config, LFRIC_API_NAMES, GOCEAN_API_NAMES
6156
from psyclone.core import AccessType
@@ -70,6 +65,7 @@
7065
ArgumentInterface, ArrayType, ContainerSymbol, DataSymbol, ScalarType,
7166
UnresolvedType, ImportInterface, RoutineSymbol)
7267
from psyclone.psyir.symbols.symbol_table import SymbolTable
68+
from psyclone.utils import stringify_annotation
7369

7470
# The types of 'intent' that an argument to a Fortran subroutine
7571
# may have

src/psyclone/tests/docstring_parser_test.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -596,35 +596,6 @@ def docstring_object2(param4):
596596
assert basedata3.desc is not None
597597

598598

599-
def test_no_sphinx():
600-
'''
601-
Test that we can still create docstring information if sphinx is
602-
not installed.
603-
604-
'''
605-
# Unload the docstring_parser
606-
# Trick the import into thinking sphinx.util.typing is unavailable
607-
with patch.dict(sys.modules):
608-
del sys.modules['psyclone.docstring_parser']
609-
sys.modules['sphinx.util.typing'] = None
610-
sys.modules['sphinx'] = None
611-
# pylint: disable=import-outside-toplevel
612-
from psyclone.docstring_parser import (
613-
create_docstring_data, ArgumentData
614-
)
615-
616-
def test_function(param: DocstringData):
617-
'''Empty function to test import.'''
618-
619-
data = create_docstring_data(["param", "param"],
620-
"empty", test_function)
621-
# This uses the PSyclone version of stringify_annotation so we get a
622-
# different datatype expression
623-
assert isinstance(data, ArgumentData)
624-
assert (data.datatype ==
625-
"<class 'psyclone.docstring_parser.DocstringData'>")
626-
627-
628599
def test_subarguments():
629600
'''
630601
Test that we can add sub arguments to a docstring data as expected.

src/psyclone/tests/psyGen_test.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -375,33 +375,6 @@ def apply(self, node, valid2: int = 1):
375375
assert options.get('options', None) is None
376376

377377

378-
def test_transformation_get_valid_options_no_sphinx():
379-
'''Test that the get_valid_options method behaves in the expected
380-
way when sphinx isn't available.'''
381-
# Test that importing stringify_annotations works without sphinx.
382-
# Trick the import into thinking sphinx.util.typing is unavailable
383-
with patch.dict(sys.modules, {'sphinx.util.typing': None}):
384-
# Unload the previously imported Transformation class
385-
# pylint: disable=import-outside-toplevel
386-
del sys.modules['psyclone.psyGen']
387-
from psyclone.psyGen import Transformation
388-
389-
class TestTrans(Transformation):
390-
'''Utility transformation to test methods of the abstract
391-
Transformation class.'''
392-
393-
def apply(self, node, valid: bool = True, untyped=False):
394-
'''Apply method of TestTrans.'''
395-
396-
options = TestTrans.get_valid_options()
397-
assert options['valid'].default
398-
assert options['valid'].type is bool
399-
assert options['valid'].typename == "<class 'bool'>"
400-
assert options['untyped'].default is False
401-
assert options['untyped'].type is None
402-
assert options['untyped'].typename is None
403-
404-
405378
def test_transformation_validate_options():
406379
'''Test that the validate_options function behaves as expected'''
407380
class TestTrans(Transformation):

src/psyclone/tests/utils_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def func(temp: bool, temp2: Union[bool, int]):
346346
# For first parameter temp
347347
if "temp" == k:
348348
anno = stringify_annotation(v.annotation)
349-
assert "<class 'bool'>" == anno
349+
assert "bool" == anno
350350

351351
# For second parameter temp2
352352
if "temp2" == k:

src/psyclone/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
'''This module provides generic utility functions.'''
3939

40-
from typing import Type, TYPE_CHECKING, Union
40+
from typing import Type, TYPE_CHECKING, Union, TypeAliasType
4141
from collections import OrderedDict
4242
import sys
4343
from psyclone.errors import InternalError
@@ -79,15 +79,16 @@ def a_or_an(string):
7979
return "a"
8080

8181

82-
def stringify_annotation(annotation) -> str:
82+
def stringify_annotation(annotation: Union[Type, TypeAliasType]) -> str:
8383
''' Simple PSyclone method to turn a Python type annotation to a string
8484
when sphinx is not available.
8585
86-
:param annotation: The type annotation to convert to a string.
87-
:type annotation: TypeAliasType
86+
:param annotation: the type annotation to convert to a string.
8887
8988
:returns: The string representation of annotation.
9089
'''
90+
if isinstance(annotation, type):
91+
return annotation.__name__
9192
return str(annotation)
9293

9394

0 commit comments

Comments
 (0)