You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Yasuhito FUTATSUKI <fu...@poem.co.jp> on 2020/01/02 20:34:48 UTC

[PATCH] Avoid DeprecationWarning on make check with Python >= 3.5

Hi,
As I saw Nathan add note about DeprecationWarning in run_test.py on
Subversion's Python 3 Support Status page yesterday, I've made a patch
to avoid warning.

I didn't read context around the code changed, I only rewrited it as the
example code[1] do.

[1] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly

I've run it on Python 3.7.1 and it seems it can run Python test units
without DeprecationWarning.

Could anyone review this?

Thanks,
-- 
Yasuhito FUTATSUKI <fu...@yf.bsdclub.org> / <fu...@poem.co.jp>

Re: [PATCH] Avoid DeprecationWarning on make check with Python >= 3.5

Posted by Yasuhito FUTATSUKI <fu...@poem.co.jp>.
On 2020/01/04 3:07, Nathan Hartman wrote:
> On Thu, Jan 2, 2020 at 3:36 PM Yasuhito FUTATSUKI <fu...@poem.co.jp> wrote:

> The patch looks good. Daniel ran tests with Python 3.5.3, so I ran the
> tests with Python 2.7.16.
> 
> I think it should be committed.

Thank you Daniel, Nathan for the reviews and tests. 

I've committed it, in r1872308.

Cheers,
-- 
Yasuhito FUTATSUKI <fu...@yf.bsdclub.org> / <fu...@poem.co.jp>

Re: [PATCH] Avoid DeprecationWarning on make check with Python >= 3.5

Posted by Nathan Hartman <ha...@gmail.com>.
On Thu, Jan 2, 2020 at 3:36 PM Yasuhito FUTATSUKI <fu...@poem.co.jp> wrote:
>
> Hi,
> As I saw Nathan add note about DeprecationWarning in run_test.py on
> Subversion's Python 3 Support Status page yesterday, I've made a patch
> to avoid warning.
>
> I didn't read context around the code changed, I only rewrited it as the
> example code[1] do.
>
> [1] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
>
> I've run it on Python 3.7.1 and it seems it can run Python test units
> without DeprecationWarning.
>
> Could anyone review this?

Hello Yasuhito,

Thank you for addressing that.

The patch looks good. Daniel ran tests with Python 3.5.3, so I ran the
tests with Python 2.7.16.

I think it should be committed.

Cheers,
Nathan

Re: [PATCH] Avoid DeprecationWarning on make check with Python >= 3.5

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Yasuhito FUTATSUKI wrote on Fri, Jan 03, 2020 at 05:34:48 +0900:
> +++ build/run_tests.py	(working copy)
> @@ -64,6 +64,11 @@
> +if sys.version_info < (3, 5):
> +  import imp
> +else:
> +  import importlib.util

Add a comment here explaining the reason for this?  E.g., —

    # The imp module is deprecated since Python 3.4; the replacement we use,
    # module_from_spec(), is available since Python 3.5.

> @@ -821,10 +826,15 @@
>        if sys.version_info < (3, 0):
>          prog_mod = imp.load_module(progbase[:-3], open(progabs, 'r'), progabs,
>                                     ('.py', 'U', imp.PY_SOURCE))
> -      else:
> +      elif sys.version_info < (3, 5):
>          prog_mod = imp.load_module(progbase[:-3],
>                                     open(progabs, 'r', encoding="utf-8"),
>                                     progabs, ('.py', 'U', imp.PY_SOURCE))
> +      else:
> +         spec = importlib.util.spec_from_file_location(progbase[:-3], progabs)
> +         prog_mod = importlib.util.module_from_spec(spec) 
> +         sys.modules[progbase[:-3]] = prog_mod
> +         spec.loader.exec_module(prog_mod)

Looks good to me.  I looked at the docstrings of the called functions and
I don't see any reason not to use the code example as-is.

All tests pass, Python 3.5.3 on Linux.

Cheers,

Daniel