diff options
| author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-03-05 15:43:43 +0000 |
|---|---|---|
| committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-03-05 19:03:06 +0000 |
| commit | 43e681e88ff304f8fab4f8858087c1398bec7a35 (patch) | |
| tree | 72fd248db535f990b1721e42baa28ef8f6b640aa | |
| parent | f435fc05e68654a0cb1f36aecaf5100fcf171ee8 (diff) | |
| download | sphinx-git-43e681e88ff304f8fab4f8858087c1398bec7a35.tar.gz | |
Remove ``.egg`` support from pycode ``ModuleAnalyser``
Python eggs are a now-obsolete binary distribution format.
| -rw-r--r-- | sphinx/pycode/__init__.py | 23 | ||||
| -rw-r--r-- | tests/roots/test-pycode-egg/conf.py | 5 | ||||
| -rw-r--r-- | tests/roots/test-pycode-egg/index.rst | 2 | ||||
| -rw-r--r-- | tests/roots/test-pycode-egg/sample-0.0.0-py3.7.egg | bin | 1365 -> 0 bytes | |||
| -rw-r--r-- | tests/roots/test-pycode-egg/src/sample.py | 6 | ||||
| -rw-r--r-- | tests/roots/test-pycode-egg/src/setup.py | 4 | ||||
| -rw-r--r-- | tests/test_ext_autodoc.py | 23 | ||||
| -rw-r--r-- | tests/test_pycode.py | 25 |
8 files changed, 1 insertions, 87 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index 29a62e94a..64e8bff4e 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -2,13 +2,11 @@ from __future__ import annotations -import re import tokenize from collections import OrderedDict from importlib import import_module from os import path from typing import TYPE_CHECKING, Any -from zipfile import ZipFile from sphinx.errors import PycodeError from sphinx.pycode.parser import Parser @@ -66,11 +64,6 @@ class ModuleAnalyzer: filename += 'w' elif not filename.lower().endswith(('.py', '.pyw')): raise PycodeError('source is not a .py file: %r' % filename) - elif ('.egg' + path.sep) in filename: - pat = '(?<=\\.egg)' + re.escape(path.sep) - eggpath, _ = re.split(pat, filename, 1) - if path.isfile(eggpath): - return filename, None if not path.isfile(filename): raise PycodeError('source file is not present: %r' % filename) @@ -91,24 +84,10 @@ class ModuleAnalyzer: obj = cls(string, modname, filename) cls.cache['file', filename] = obj except Exception as err: - if '.egg' + path.sep in filename: - obj = cls.cache['file', filename] = cls.for_egg(filename, modname) - else: - raise PycodeError('error opening %r' % filename, err) from err + raise PycodeError('error opening %r' % filename, err) from err return obj @classmethod - def for_egg(cls, filename: str, modname: str) -> ModuleAnalyzer: - SEP = re.escape(path.sep) - eggpath, relpath = re.split('(?<=\\.egg)' + SEP, filename) - try: - with ZipFile(eggpath) as egg: - code = egg.read(relpath).decode() - return cls.for_string(code, modname, filename) - except Exception as exc: - raise PycodeError('error opening %r' % filename, exc) from exc - - @classmethod def for_module(cls, modname: str) -> ModuleAnalyzer: if ('module', modname) in cls.cache: entry = cls.cache['module', modname] diff --git a/tests/roots/test-pycode-egg/conf.py b/tests/roots/test-pycode-egg/conf.py deleted file mode 100644 index af0c14e26..000000000 --- a/tests/roots/test-pycode-egg/conf.py +++ /dev/null @@ -1,5 +0,0 @@ -import os -import sys - -sys.path.insert(0, os.path.abspath('sample-0.0.0-py3.7.egg')) -extensions = ['sphinx.ext.autodoc'] diff --git a/tests/roots/test-pycode-egg/index.rst b/tests/roots/test-pycode-egg/index.rst deleted file mode 100644 index affc7912a..000000000 --- a/tests/roots/test-pycode-egg/index.rst +++ /dev/null @@ -1,2 +0,0 @@ -test-pycode-egg -=============== diff --git a/tests/roots/test-pycode-egg/sample-0.0.0-py3.7.egg b/tests/roots/test-pycode-egg/sample-0.0.0-py3.7.egg Binary files differdeleted file mode 100644 index 719dbea51..000000000 --- a/tests/roots/test-pycode-egg/sample-0.0.0-py3.7.egg +++ /dev/null diff --git a/tests/roots/test-pycode-egg/src/sample.py b/tests/roots/test-pycode-egg/src/sample.py deleted file mode 100644 index 2ecf577f6..000000000 --- a/tests/roots/test-pycode-egg/src/sample.py +++ /dev/null @@ -1,6 +0,0 @@ -#: constant on sample.py -CONSTANT = 1 - - -def hello(s): - print('Hello %s' % s) diff --git a/tests/roots/test-pycode-egg/src/setup.py b/tests/roots/test-pycode-egg/src/setup.py deleted file mode 100644 index 1dfb1de29..000000000 --- a/tests/roots/test-pycode-egg/src/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -from setuptools import setup - -setup(name='sample', - py_modules=['sample']) diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 69ec09bae..64347bbc6 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -2018,29 +2018,6 @@ def test_autodoc_TYPE_CHECKING(app): ] -@pytest.mark.sphinx('html', testroot='pycode-egg') -def test_autodoc_for_egged_code(app): - options = {"members": None, - "undoc-members": None} - actual = do_autodoc(app, 'module', 'sample', options) - assert list(actual) == [ - '', - '.. py:module:: sample', - '', - '', - '.. py:data:: CONSTANT', - ' :module: sample', - ' :value: 1', - '', - ' constant on sample.py', - '', - '', - '.. py:function:: hello(s)', - ' :module: sample', - '', - ] - - @pytest.mark.sphinx('html', testroot='ext-autodoc') def test_singledispatch(app): options = {"members": None} diff --git a/tests/test_pycode.py b/tests/test_pycode.py index 993743a2b..92a8a19e9 100644 --- a/tests/test_pycode.py +++ b/tests/test_pycode.py @@ -50,31 +50,6 @@ def test_ModuleAnalyzer_for_module(rootdir): sys.path.pop(0) -def test_ModuleAnalyzer_for_file_in_egg(rootdir): - try: - path = rootdir / 'test-pycode-egg' / 'sample-0.0.0-py3.7.egg' - sys.path.insert(0, path) - - import sample - analyzer = ModuleAnalyzer.for_file(sample.__file__, 'sample') - docs = analyzer.find_attr_docs() - assert docs == {('', 'CONSTANT'): ['constant on sample.py', '']} - finally: - sys.path.pop(0) - - -def test_ModuleAnalyzer_for_module_in_egg(rootdir): - try: - path = rootdir / 'test-pycode-egg' / 'sample-0.0.0-py3.7.egg' - sys.path.insert(0, path) - - analyzer = ModuleAnalyzer.for_module('sample') - docs = analyzer.find_attr_docs() - assert docs == {('', 'CONSTANT'): ['constant on sample.py', '']} - finally: - sys.path.pop(0) - - def test_ModuleAnalyzer_find_tags(): code = ('class Foo(object):\n' # line: 1 ' """class Foo!"""\n' |
