m2r icon indicating copy to clipboard operation
m2r copied to clipboard

Deprecation Warning: add_source_parser

Open connectedblue opened this issue 5 years ago • 9 comments

During the build process, the following warning is emitted:

/opt/conda/lib/python3.7/site-packages/m2r.py:652: RemovedInSphinx30Warning: app.add_source_parser() does not support suffix argument. Use app.add_source_suffix() instead.

Looks like some functionality will be removed in the next version of sphinx. I found this on version 2.2.1

connectedblue avatar Dec 03 '19 15:12 connectedblue

When attempting to fix this, could adding of .md be put in a try ... except ... statement or some other check if already added?

Currently M2R fails if recommonmark is also included in Sphinx's conf.py under extensions with:

Extension error:
source_suffix '.md' is already registered

NumesSanguis avatar Jan 07 '20 08:01 NumesSanguis

Still seeing this warning with Sphinx 2.4.1:

$ make html
Running Sphinx v2.4.1
/Users/charles/codes/dbio/kharon/vp/lib/python3.6/site-packages/m2r.py:652: RemovedInSphinx30Warning: app.add_source_parser() does not support suffix argument. Use app.add_source_suffix() instead.
  app.add_source_parser('.md', M2RParser)
...

chmreid avatar Feb 13 '20 20:02 chmreid

As a workaround, add this to your conf.py:

def monkeypatch(cls):
    """ decorator to monkey-patch methods """
    def decorator(f):
        method = f.__name__
        old_method = getattr(cls, method)
        setattr(cls, method, lambda self, *args, **kwargs: f(old_method, self, *args, **kwargs))
    return decorator

# workaround until https://github.com/miyakogi/m2r/pull/55 is merged
@monkeypatch(sphinx.registry.SphinxComponentRegistry)
def add_source_parser(_old_add_source_parser, self, *args, **kwargs):
    # signature is (parser: Type[Parser], **kwargs), but m2r expects
    # the removed (str, parser: Type[Parser], **kwargs).
    if isinstance(args[0], str):
        args = args[1:]
    return _old_add_source_parser(self, *args, **kwargs)

eric-wieser avatar Apr 23 '20 09:04 eric-wieser

@miyakogi any chance to get a new release? This component is the only reason we are still using sphinx 2.

sobolevn avatar Jun 15 '20 08:06 sobolevn

Since I'm still seeing lots of clones on my fork (which I created to solve this issue) here goes a quick update: I've released it as m2r2 after changing some of the tooling for what I feel more comfortable with right now and building CD and testing pipelines.

CrossNox avatar Jul 12 '20 01:07 CrossNox

@CrossNox Thanks for the release!

I wonder if you could combine forces with @qhua948 (released as m2rr) to make a successor to m2r. It would be good to avoid too much proliferation (ideal would be if @miyakogi would add some additional maintainers).

If combining doesn't work out, you should rename your fork to 'm2r2'. It might be good to enable issues there too if it's going to diverge from this repo significantly. It's a little confusing to keep using this repo to discuss issues that might be fixed in one of the forks.

sbliven avatar Jul 13 '20 20:07 sbliven

@sbliven I sure hope we could work together on this. I didn't learn of that release until I commented somewhere about the update, my bad. I wouldn't count on @miyakogi adding collabs, they don't seem to have been active for a long time.

100% agree on that last bit! I am pretty sure github redirects clones if I change the repo's name, but i wanna test it just in case. I wouldn't wanna break the pipelines for people using it, but I guess it's still gonna happen.

Edit: I've enabled issues (no clue why they weren't already enabled) and renamed the repo to avoid any confusion.

CrossNox avatar Jul 13 '20 20:07 CrossNox

# Sphinx version: 3.1.2
# Python version: 3.6.11 (CPython)
# Docutils version: 0.15.2 release
# Jinja2 version: 2.11.2
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/sphinx/cmd/build.py", line 279, in build_main
    args.tags, args.verbosity, args.jobs, args.keep_going)
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/sphinx/application.py", line 244, in __init__
    self.setup_extension(extension)
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/sphinx/application.py", line 398, in setup_extension
    self.registry.load_extension(self, extname)
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/sphinx/registry.py", line 419, in load_extension
    metadata = setup(app)
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/m2r.py", line 652, in setup
    app.add_source_parser('.md', M2RParser)
  File "/opt/conda/envs/my-proj/lib/python3.6/site-packages/sphinx/application.py", line 1084, in add_source_parser
    self.registry.add_source_parser(*args, **kwargs)
TypeError: add_source_parser() takes 2 positional arguments but 3 were given

dazza-codes avatar Aug 04 '20 02:08 dazza-codes

@dazza-codes See the fork that was updated to fix this: https://github.com/CrossNox/m2r2

Thankfully they made it a different pip package officially, so it's a extremely nice fix.

dylan-thomas832 avatar Oct 16 '20 18:10 dylan-thomas832