Skip to content

Commit 43e681e

Browse files
committed
Remove .egg support from pycode ModuleAnalyser
Python eggs are a now-obsolete binary distribution format.
1 parent f435fc0 commit 43e681e

8 files changed

Lines changed: 1 addition & 87 deletions

File tree

sphinx/pycode/__init__.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
from __future__ import annotations
44

5-
import re
65
import tokenize
76
from collections import OrderedDict
87
from importlib import import_module
98
from os import path
109
from typing import TYPE_CHECKING, Any
11-
from zipfile import ZipFile
1210

1311
from sphinx.errors import PycodeError
1412
from sphinx.pycode.parser import Parser
@@ -66,11 +64,6 @@ def get_module_source(modname: str) -> tuple[str | None, str | None]:
6664
filename += 'w'
6765
elif not filename.lower().endswith(('.py', '.pyw')):
6866
raise PycodeError('source is not a .py file: %r' % filename)
69-
elif ('.egg' + path.sep) in filename:
70-
pat = '(?<=\\.egg)' + re.escape(path.sep)
71-
eggpath, _ = re.split(pat, filename, 1)
72-
if path.isfile(eggpath):
73-
return filename, None
7467

7568
if not path.isfile(filename):
7669
raise PycodeError('source file is not present: %r' % filename)
@@ -91,23 +84,9 @@ def for_file(cls, filename: str, modname: str) -> ModuleAnalyzer:
9184
obj = cls(string, modname, filename)
9285
cls.cache['file', filename] = obj
9386
except Exception as err:
94-
if '.egg' + path.sep in filename:
95-
obj = cls.cache['file', filename] = cls.for_egg(filename, modname)
96-
else:
97-
raise PycodeError('error opening %r' % filename, err) from err
87+
raise PycodeError('error opening %r' % filename, err) from err
9888
return obj
9989

100-
@classmethod
101-
def for_egg(cls, filename: str, modname: str) -> ModuleAnalyzer:
102-
SEP = re.escape(path.sep)
103-
eggpath, relpath = re.split('(?<=\\.egg)' + SEP, filename)
104-
try:
105-
with ZipFile(eggpath) as egg:
106-
code = egg.read(relpath).decode()
107-
return cls.for_string(code, modname, filename)
108-
except Exception as exc:
109-
raise PycodeError('error opening %r' % filename, exc) from exc
110-
11190
@classmethod
11291
def for_module(cls, modname: str) -> ModuleAnalyzer:
11392
if ('module', modname) in cls.cache:

tests/roots/test-pycode-egg/conf.py

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

tests/roots/test-pycode-egg/index.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.
-1.33 KB
Binary file not shown.

tests/roots/test-pycode-egg/src/sample.py

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

tests/roots/test-pycode-egg/src/setup.py

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

tests/test_ext_autodoc.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,29 +2018,6 @@ def test_autodoc_TYPE_CHECKING(app):
20182018
]
20192019

20202020

2021-
@pytest.mark.sphinx('html', testroot='pycode-egg')
2022-
def test_autodoc_for_egged_code(app):
2023-
options = {"members": None,
2024-
"undoc-members": None}
2025-
actual = do_autodoc(app, 'module', 'sample', options)
2026-
assert list(actual) == [
2027-
'',
2028-
'.. py:module:: sample',
2029-
'',
2030-
'',
2031-
'.. py:data:: CONSTANT',
2032-
' :module: sample',
2033-
' :value: 1',
2034-
'',
2035-
' constant on sample.py',
2036-
'',
2037-
'',
2038-
'.. py:function:: hello(s)',
2039-
' :module: sample',
2040-
'',
2041-
]
2042-
2043-
20442021
@pytest.mark.sphinx('html', testroot='ext-autodoc')
20452022
def test_singledispatch(app):
20462023
options = {"members": None}

tests/test_pycode.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,6 @@ def test_ModuleAnalyzer_for_module(rootdir):
5050
sys.path.pop(0)
5151

5252

53-
def test_ModuleAnalyzer_for_file_in_egg(rootdir):
54-
try:
55-
path = rootdir / 'test-pycode-egg' / 'sample-0.0.0-py3.7.egg'
56-
sys.path.insert(0, path)
57-
58-
import sample
59-
analyzer = ModuleAnalyzer.for_file(sample.__file__, 'sample')
60-
docs = analyzer.find_attr_docs()
61-
assert docs == {('', 'CONSTANT'): ['constant on sample.py', '']}
62-
finally:
63-
sys.path.pop(0)
64-
65-
66-
def test_ModuleAnalyzer_for_module_in_egg(rootdir):
67-
try:
68-
path = rootdir / 'test-pycode-egg' / 'sample-0.0.0-py3.7.egg'
69-
sys.path.insert(0, path)
70-
71-
analyzer = ModuleAnalyzer.for_module('sample')
72-
docs = analyzer.find_attr_docs()
73-
assert docs == {('', 'CONSTANT'): ['constant on sample.py', '']}
74-
finally:
75-
sys.path.pop(0)
76-
77-
7853
def test_ModuleAnalyzer_find_tags():
7954
code = ('class Foo(object):\n' # line: 1
8055
' """class Foo!"""\n'

0 commit comments

Comments
 (0)