#38 Fedora 31: compileall2 update, %python, %pycached
Merged 4 years ago by pviktori. Opened 4 years ago by churchyard.
rpms/ churchyard/python-rpm-macros f31-sync  into  f31

file modified
+24 -10
@@ -9,6 +9,10 @@ 

  packages -- for now, you'll have to deal with packages separately.)

  

  See module py_compile for details of the actual byte-compilation.

+ 

+ License:

+ Compileall2 is an enhanced copy of Python's compileall module

+ and it follows Python licensing. For more info see: https://www.python.org/psf/license/

  """

  import os

  import sys
@@ -39,8 +43,6 @@ 

      pyc_header_lenght = 8

      pyc_header_format = (pyc_struct_format, importlib.util.MAGIC_NUMBER)

  

- RECURSION_LIMIT = sys.getrecursionlimit()

- 

  __all__ = ["compile_dir","compile_file","compile_path"]

  

  def optimization_kwarg(opt):
@@ -56,7 +58,7 @@ 

          else:

              return dict()

  

- def _walk_dir(dir, maxlevels=RECURSION_LIMIT, quiet=0):

+ def _walk_dir(dir, maxlevels, quiet=0):

      if PY36 and quiet < 2 and isinstance(dir, os.PathLike):

          dir = os.fspath(dir)

      else:
@@ -81,7 +83,7 @@ 

              yield from _walk_dir(fullname, maxlevels=maxlevels - 1,

                                   quiet=quiet)

  

- def compile_dir(dir, maxlevels=RECURSION_LIMIT, ddir=None, force=False,

+ def compile_dir(dir, maxlevels=None, ddir=None, force=False,

                  rx=None, quiet=0, legacy=False, optimize=-1, workers=1,

                  invalidation_mode=None, stripdir=None,

                  prependdir=None, limit_sl_dest=None):
@@ -119,6 +121,8 @@ 

                  from concurrent.futures import ProcessPoolExecutor

              except ImportError:

                  workers = 1

+     if maxlevels is None:

+         maxlevels = sys.getrecursionlimit()

      files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels)

      success = True

      if workers is not None and workers != 1 and ProcessPoolExecutor is not None:
@@ -169,6 +173,11 @@ 

      limit_sl_dest: ignore symlinks if they are pointing outside of

                     the defined path.

      """

+ 

+     if ddir is not None and (stripdir is not None or prependdir is not None):

+         raise ValueError(("Destination dir (ddir) cannot be used "

+                           "in combination with stripdir or prependdir"))

+ 

      success = True

      if PY36 and quiet < 2 and isinstance(fullname, os.PathLike):

          fullname = os.fspath(fullname)
@@ -323,7 +332,7 @@ 

      parser = argparse.ArgumentParser(

          description='Utilities to support installing Python libraries.')

      parser.add_argument('-l', action='store_const', const=0,

-                         default=RECURSION_LIMIT, dest='maxlevels',

+                         default=None, dest='maxlevels',

                          help="don't recurse into subdirectories")

      parser.add_argument('-r', type=int, dest='recursion',

                          help=('control the maximum recursion level. '
@@ -345,16 +354,16 @@ 

                          default=None,

                          help=('part of path to left-strip from path '

                                'to source file - for example buildroot. '

-                               'if `-d` and `-s` options are specified, '

-                               'then `-d` takes precedence.'))

+                               '`-d` and `-s` options cannot be '

+                               'specified together.'))

      parser.add_argument('-p', metavar='PREPENDDIR',  dest='prependdir',

                          default=None,

                          help=('path to add as prefix to path '

                                'to source file - for example / to make '

                                'it absolute when some part is removed '

-                               'by `-s` option'

-                               'if `-d` and `-a` options are specified, '

-                               'then `-d` takes precedence.'))

+                               'by `-s` option. '

+                               '`-d` and `-p` options cannot be '

+                               'specified together.'))

      parser.add_argument('-x', metavar='REGEXP', dest='rx', default=None,

                          help=('skip files matching the regular expression; '

                                'the regexp is searched for in the full path '
@@ -404,6 +413,11 @@ 

      if args.opt_levels is None:

          args.opt_levels = [-1]

  

+     if args.ddir is not None and (

+         args.stripdir is not None or args.prependdir is not None

+     ):

+         parser.error("-d cannot be used in combination with -s or -p")

+ 

      # if flist is provided then load it

      if args.flist:

          try:

file modified
+9
@@ -15,6 +15,15 @@ 

  # See the comments in https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/22

  %__python /usr/bin/python

  

+ # Users can use %%python only if they redefined %%__python (e.g. to %%__python3)

+ %python() %{lua:\

+     __python = rpm.expand("%__python")\

+     if __python == "/usr/bin/python" then\

+         rpm.expand("%{error:Cannot use %%python if %%__python wasn't redefined to something other than /usr/bin/python.}")\

+     else\

+         print(__python)\

+     end\

+ }

  

  # python3_pkgversion specifies the version of Python 3 in the distro.  It can be

  # a specific version (e.g. 34 in Fedora EPEL7)

file modified
+15
@@ -37,3 +37,18 @@ 

  %py3_install_wheel() %{expand:\\\

    pip%{python3_version} install -I dist/%{1} --root %{buildroot} --no-deps

  }

+ 

+ # This only supports Python 3.5+ and will never work with Python 2.

+ # Hence, it has no Python version in the name.

+ %pycached() %{lua:

+   path = rpm.expand("%{?1}")

+   if (string.sub(path, "-3") ~= ".py") then

+     rpm.expand("%{error:%%pycached can only be used with paths explicitly ending with .py}")

+   else

+     print(path)

+     pyminor = path:match("/python3.(%d+)/") or "*"

+     dirname = path:match("(.*/)")

+     modulename = path:match(".*/([^/]+).py")

+     print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")

+   end

+ }

file modified
+8 -1
@@ -1,6 +1,6 @@ 

  Name:           python-rpm-macros

  Version:        3

- Release:        49%{?dist}

+ Release:        51%{?dist}

  Summary:        The unversioned Python RPM macros

  

  # macros: MIT, compileall2.py: PSFv2
@@ -78,6 +78,13 @@ 

  

  

  %changelog

+ * Sat Dec 28 2019 Miro Hrončok <mhroncok@redhat.com> - 3-51

+ - Define %%python, but make it work only if %%__python is redefined

+ - Add the %%pycached macro

+ 

+ * Tue Nov 26 2019 Lumír Balhar <lbalhar@redhat.com> - 3-50

+ - Update of bundled compileall2 module

+ 

  * Fri Sep 27 2019 Miro Hrončok <mhroncok@redhat.com> - 3-49

  - Define %%python2 and %%python3

  

no initial comment

+1.
Code looks good; Setuptools, Django, Numpy build without problems.

Pull-Request has been merged by pviktori

4 years ago

building. will create a buildroot override together with the update, so koschei can figure out problems.