sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.35k stars 460 forks source link

Replace use of module_list and OptionalExtension by extending find_python_sources #29701

Closed mkoeppe closed 4 years ago

mkoeppe commented 4 years ago

We add two new features to find_python_sources: finding Cython extensions, and filtering by "distributions".

We remove the use of module_list, finding Cython extensions instead in the source tree. (This is prepared by #29706 and follow-up tickets by moving Extension options to directives in the source files.)

We remove OptionalExtensions as follows. We map installed packages to "distributions" (for example, tdlib -> sage-tdlib) and then filter by distribution.

Follow-up tickets:

CC: @kiwifb @isuruf @videlec @dcoudert @dimpase @kliem @vbraun

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 55c3fbc

Reviewer: Jonathan Kliem

Issue created by migration from https://trac.sagemath.org/ticket/29701

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from d62da15 to 06a3609

kliem commented 4 years ago
comment:36

As I have capacities I started test for only this ticket:

https://github.com/kliem/sage/pull/18/checks

kliem commented 4 years ago
comment:37

There is that annoying failure of sageinspect again

ubuntu-bionic, minimal (for example, but looks like it is anywhere)

File "src/sage/misc/sageinspect.py", line 28, in sage.misc.sageinspect
Failed example:
    sage_getsource(sage.rings.rational)[5:]
Expected:
    'Rational Numbers...'
Got:
    'tutils: libraries = ntl\nr"""\nRational Numbers\n\nAUTHORS:\n\n- William Stein (2005): first version\n\n- William Stein (2006-02-22): floor and ceil (pure fast GMP versions).\n\n- Gonzalo Tornaria and William Stein (2006-03-02): greatly improved\n  python/GMP conversion; hashing\n\n- William Stein and Naqi Jaffery (2006-03-06): height, sqrt examples,\n  and improve behavior of sqrt.\n\n- David Harvey (2006-09-15): added nth_root\n\n- Pablo De Napoli (2007-04-01): corrected the implementations of\n  multiplicative_order, is_one; optimized __nonzero__ ; documented:\n  lcm,gcd\n\n- John Cremona (2009-05-15): added support for local and global\n  logarithmic heights.\n\n- Travis Scrimshaw (2012-10-18): Added doctests for full coverage.\n\n- Vincent Delecroix (2013): continued fraction\n\n- Vincent Delecroix (2017-05-03): faster integer-rational comparison\n\n- Vincent Klein (2017-05-11): add __mpq__() to class Rational\n\n- Vincent Klein (2017-05-22): Rational constructor support gmpy2.mpq\n  or gmpy2.mpz parameter. Add __mpz__ to class Rational.\n\nTESTS::\n\n    sage: a = -2/3\n    sage: a == loads(dumps(a))\n    True\n"""\n\n# ****************************************************************************\n#       Copyright (C) 2004, 2006 William Stein <wstein@gmail.com>\n#       Copyright (C) 2017 Vincent Delecroix <20100.delecroix@gmail.com>\n#\n#  Distributed under the terms of the GNU General Public License (GPL)\n#  as published by the Free Software Foundation; either version 2 of\n#  the License, or (at your option) any later version.\n#                  https://www.gnu.org/licenses/\n# ****************************************************************************\n\ncimport cython\nfrom cpython cimport *\nfrom cpython.object cimport Py_EQ, Py_NE\n\nfrom cysignals.signals cimport sig_on, sig_off\n\nimport operator\nimport fractions\n\nfrom sage.misc.mathml import mathml\nfrom sage.arith.long cimport pyobject_to_long, integer_check_long_py\nfrom sage.cpython.string cimport char_to_str, str_to_bytes\n\nimport sage.misc.misc as misc\nfrom sage.structure.sage_object cimport SageObject\nfrom sage.structure.richcmp cimport rich_to_bool_sgn\nimport sage.rings.rational_field\n\ncimport sage.rings.integer as integer\nfrom .integer cimport Integer\n\nfrom cypari2.paridecl cimport *\nfrom cypari2.gen cimport Gen as pari_gen\nfrom sage.libs.pari.convert_gmp cimport INT_to_mpz, INTFRAC_to_mpq, new_gen_from_mpq_t\n\nfrom .integer_ring import ZZ\nfrom sage.arith.rational_reconstruction cimport mpq_rational_reconstruction\n\nfrom sage.structure.coerce cimport is_numpy_type\n\nfrom sage.libs.gmp.pylong cimport mpz_set_pylong\n\nfrom sage.structure.coerce cimport coercion_model\nfrom sage.structure.element cimport Element\nfrom sage.structure.element import coerce_binop\nfrom sage.structure.parent cimport Parent\nfrom sage.categories.morphism cimport Morphism\nfrom sage.categories.map cimport Map\n\n\n\nimport sage.rings.real_mpfr\nimport sage.rings.real_double\nfrom libc.stdint cimport uint64_t\nfrom sage.libs.gmp.binop cimport mpq_add_z, mpq_mul_z, mpq_div_zz\n\nfrom cpython.int cimport PyInt_AS_LONG\n\ncimport sage.rings.fast_arith\nimport  sage.rings.fast_arith\n\ncdef sage.rings.fast_arith.arith_int ai\nai = sage.rings.fast_arith.arith_int()\n\ncdef object numpy_long_interface = {\'typestr\': \'=i4\' if sizeof(long) == 4 else \'=i8\' }\ncdef object numpy_int64_interface = {\'typestr\': \'=i8\'}\ncdef object numpy_object_interface = {\'typestr\': \'|O\'}\ncdef object numpy_double_interface = {\'typestr\': \'=f8\'}\n\nfrom libc.math cimport ldexp\nfrom sage.libs.gmp.all cimport *\n\ncimport gmpy2\ngmpy2.import_gmpy2()\n\n\ncdef class Rational(sage.structure.element.FieldElement)\n'
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

43a9b16src/sage/misc/sageinspect.py: Fix up doctest that depends on a modified source file
a5bc828src/sage/misc/sageinspect.py: Fixup fixup
1baaa68src/sage/misc/sageinspect.py: Remove unused import
174626cMerge branch 't/29786/move_extension_options_from_src_module_list_py_to__distutils___directives_in_the_individual_files__part_4__sage_rings_' into t/29701/replace_use_of_module_list_optionalextension
a56dc35Merge tag '9.2.beta1' into t/29702/public/move_all_code_from_src_setup_py__src_fpickle_setup_py_to_sage_setup
034a7f7Merge branch 'public/move_all_code_from_src_setup_py__src_fpickle_setup_py_to_sage_setup' of git://trac.sagemath.org/sage into t/29701/replace_use_of_module_list_optionalextension
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 06a3609 to 034a7f7

mkoeppe commented 4 years ago
comment:39

Thanks for catching this. I have merged in the latest branches of the dependencies. The updated #29786 where this error came from should fix this.

kliem commented 4 years ago
comment:40

I was wondering, where this error came from now. Good to know that it is entirely harmless.

Replying to @mkoeppe:

Thanks for catching this. I have merged in the latest branches of the dependencies. The updated #29786 where this error came from should fix this.

kliem commented 4 years ago
comment:41

LGTM.

kliem commented 4 years ago

Reviewer: Jonathan Kliem

mkoeppe commented 4 years ago
comment:43

Thank you!

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

d3c608bMerge tag '9.2.beta3' into t/29701/replace_use_of_module_list_optionalextension
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 034a7f7 to d3c608b

mkoeppe commented 4 years ago
comment:45

Merged 9.2.beta3

mkoeppe commented 4 years ago
comment:47

Volker, is there something missing on this ticket that keeps it from being merged?

vbraun commented 4 years ago

Changed dependencies from #29702 (#29411), #29786, #29790, #29791 to #29702, #29786, #29790, #29791

vbraun commented 4 years ago
comment:49

29411 isn't merged (the release script can only check whether a ticket has been merged if you think about it; Do not depend on invalid/duplicate/meta-tickets, or anything else that doesn't actually contribute commits). Also (#29411) isn't supported as dependency, whatever the parens are supposed to mean.

dimpase commented 4 years ago
comment:50

29411 is a real ticket with 9.2 as milestone, marked as closed, with a branch which looks like a merged branch. Is it the same kind of issue as with #21226 ?

mkoeppe commented 4 years ago
comment:51

Thanks for cleaning up the dependency list.

Unfortunately the format does not seem to be documented anywhere.

(#29411 is a regular merged ticket. You merged it in 0bcd001f760ff724832c32b4f65fa575fd82e000)

vbraun commented 4 years ago
comment:52

Yes, in this case it was the parens.

vbraun commented 4 years ago
comment:53
sage -t --long --warn-long 40.4 --random-seed=0 src/sage_setup/clean.py
**********************************************************************
File "src/sage_setup/clean.py", line 83, in sage_setup.clean._find_stale_files
Failed example:
    python_packages, python_modules = find_python_sources(
        SAGE_SRC, ['sage', 'sage_setup'])
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 715, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1139, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage_setup.clean._find_stale_files[3]>", line 2, in <module>
        SAGE_SRC, ['sage', 'sage_setup'])
    ValueError: too many values to unpack (expected 2)
**********************************************************************
File "src/sage_setup/clean.py", line 92, in sage_setup.clean._find_stale_files
Failed example:
    stale_iter = _find_stale_files(SAGE_LIB, python_packages, python_modules, [], extra_files)
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 715, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1139, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage_setup.clean._find_stale_files[6]>", line 1, in <module>
        stale_iter = _find_stale_files(SAGE_LIB, python_packages, python_modules, [], extra_files)
    NameError: name 'python_packages' is not defined
**********************************************************************
File "src/sage_setup/clean.py", line 95, in sage_setup.clean._find_stale_files
Failed example:
    for f in stale_iter:
        if f.endswith(skip_extensions): continue
        if '/ext_data/' in f: continue
        print('Found stale file: ' + f)
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 715, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/release/Sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1139, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage_setup.clean._find_stale_files[9]>", line 1, in <module>
        for f in stale_iter:
    NameError: name 'stale_iter' is not defined
**********************************************************************
1 item had failures:
   3 of  11 in sage_setup.clean._find_stale_files
    [17 tests, 3 failures, 0.03 s]
----------------------------------------------------------------------
sage -t --long --warn-long 40.4 --random-seed=0 src/sage_setup/clean.py  # 3 doctests failed
----------------------------------------------------------------------
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from d3c608b to 55c3fbc

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

fcad518Merge tag '9.2.beta7' into t/29701/replace_use_of_module_list_optionalextension
55c3fbcsrc/sage_setup/clean.py: Fix doctest
mkoeppe commented 4 years ago

Changed dependencies from #29702, #29786, #29790, #29791 to none

kliem commented 4 years ago
comment:57

Back to positive.

mkoeppe commented 4 years ago
comment:58

Thanks!

vbraun commented 4 years ago
comment:59
[dochtml] Build finished. The built documents can be found in /home/release/Sage/local/share/doc/sage/inventory/en/reference/manifolds
[dochtml] [algebras ] updating environment: 0 added, 5 changed, 0 removed
[dochtml] Warning: Could not import sage.graphs.graph_generators cannot import name 'distance_regular' from 'sage.graphs' (/home/release/Sage/local/lib/python3.7/site-packages/sage/graphs/__init__.py)
[dochtml] [arithgrou] The inventory files are in local/share/doc/sage/inventory/en/reference/arithgroup.
[dochtml] Build finished. The built documents can be found in /home/release/Sage/local/share/doc/sage/inventory/en/reference/arithgroup
[dochtml] Error building the documentation.
[dochtml] Traceback (most recent call last):
[dochtml]   File "/home/release/Sage/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
[dochtml]     "__main__", mod_spec)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/runpy.py", line 85, in _run_code
[dochtml]     exec(code, run_globals)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__main__.py", line 2, in <module>
[dochtml]     main()
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 1721, in main
[dochtml]     builder()
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 328, in _wrapper
[dochtml]     getattr(get_builder(document), 'inventory')(*args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 553, in _wrapper
[dochtml]     self._build_everything_except_bibliography(lang, format, *args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 539, in _build_everything_except_bibliography
[dochtml]     build_many(build_ref_doc, non_references)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 281, in build_many
[dochtml]     _build_many(target, args, processes=NUM_THREADS)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/utils.py", line 283, in build_many
[dochtml]     raise worker_exc.original_exception
[dochtml] ImportError: cannot import name 'distance_regular' from 'sage.graphs' (/home/release/Sage/local/lib/python3.7/site-packages/sage/graphs/__init__.py)
[dochtml] 
[dochtml]     Note: incremental documentation builds sometimes cause spurious
[dochtml]     error messages. To be certain that these are real errors, run
[dochtml]     "make doc-clean" first and try again.
make[3]: *** [Makefile:1816: doc-html] Error 1
make[3]: Leaving directory '/home/release/Sage/build/make'
make[2]: *** [Makefile:1707: all-start] Error 2
make[2]: Leaving directory '/home/release/Sage/build/make'
kiwifb commented 4 years ago
comment:60

Replying to @vbraun:

[dochtml] Build finished. The built documents can be found in /home/release/Sage/local/share/doc/sage/inventory/en/reference/manifolds
[dochtml] [algebras ] updating environment: 0 added, 5 changed, 0 removed
[dochtml] Warning: Could not import sage.graphs.graph_generators cannot import name 'distance_regular' from 'sage.graphs' (/home/release/Sage/local/lib/python3.7/site-packages/sage/graphs/__init__.py)
[dochtml] [arithgrou] The inventory files are in local/share/doc/sage/inventory/en/reference/arithgroup.
[dochtml] Build finished. The built documents can be found in /home/release/Sage/local/share/doc/sage/inventory/en/reference/arithgroup
[dochtml] Error building the documentation.
[dochtml] Traceback (most recent call last):
[dochtml]   File "/home/release/Sage/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
[dochtml]     "__main__", mod_spec)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/runpy.py", line 85, in _run_code
[dochtml]     exec(code, run_globals)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__main__.py", line 2, in <module>
[dochtml]     main()
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 1721, in main
[dochtml]     builder()
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 328, in _wrapper
[dochtml]     getattr(get_builder(document), 'inventory')(*args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 553, in _wrapper
[dochtml]     self._build_everything_except_bibliography(lang, format, *args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 539, in _build_everything_except_bibliography
[dochtml]     build_many(build_ref_doc, non_references)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/__init__.py", line 281, in build_many
[dochtml]     _build_many(target, args, processes=NUM_THREADS)
[dochtml]   File "/home/release/Sage/local/lib/python3.7/site-packages/sage_setup/docbuild/utils.py", line 283, in build_many
[dochtml]     raise worker_exc.original_exception
[dochtml] ImportError: cannot import name 'distance_regular' from 'sage.graphs' (/home/release/Sage/local/lib/python3.7/site-packages/sage/graphs/__init__.py)
[dochtml] 
[dochtml]     Note: incremental documentation builds sometimes cause spurious
[dochtml]     error messages. To be certain that these are real errors, run
[dochtml]     "make doc-clean" first and try again.
make[3]: *** [Makefile:1816: doc-html] Error 1
make[3]: Leaving directory '/home/release/Sage/build/make'
make[2]: *** [Makefile:1707: all-start] Error 2
make[2]: Leaving directory '/home/release/Sage/build/make'

Are you sure? I thought it would have come from either #30240 or #30260 since they both touch "distance_regular".

mkoeppe commented 4 years ago
comment:61

30260 is broken. It is confused about whether it wants sage.graphs.distance_regular or sage.graphs.generators.distance_regular

dimpase commented 4 years ago
comment:63

Replying to @mkoeppe:

30260 is broken. It is confused about whether it wants sage.graphs.distance_regular or sage.graphs.generators.distance_regular

it used to be broken, but IMHO it's fixed by #30240 comment:32

kiwifb commented 4 years ago
comment:64

Replying to @dimpase:

Replying to @mkoeppe:

30260 is broken. It is confused about whether it wants sage.graphs.distance_regular or sage.graphs.generators.distance_regular

it used to be broken, but IMHO it's fixed by #30240 comment:32

Unfortunately Volker merged before that.

mkoeppe commented 4 years ago
comment:65

30240 does not even have #30260 as a dependency...

b44cef29-61c4-4aab-a2e6-dc3c8c58c1be commented 4 years ago
comment:66

Replying to @mkoeppe:

30240 does not even have #30260 as a dependency...

Should it? #30260 is a later ticket and it depends on #30240, but #30240 doesn't rely on #30260. I apologise for the confusion but when #30240 went from "positive review" to "needs work" and I forgot to update #30260.

mkoeppe commented 4 years ago
comment:67

Replying to @Ivo-Maffei:

Replying to @mkoeppe:

30240 does not even have #30260 as a dependency...

Should it? #30260 is a later ticket and it depends on #30240, but #30240 doesn't rely on #30260. I apologise for the confusion but when #30240 went from "positive review" to "needs work" and I forgot to update #30260.

That's alright -- thanks for the fast reaction and fix!

vbraun commented 4 years ago
comment:68
sage -t --long --warn-long 42.4 --random-seed=0 src/sage_setup/find.py
**********************************************************************
File "src/sage_setup/find.py", line 215, in sage_setup.find.find_extra_files
Failed example:
    extras["sage/ext/interpreters"]
Expected:
    ['.../src/sage/ext/interpreters/wrapper_cdf.pxd', ...wrapper_cdf.h...]
Got:
    ['/home/release/Sage/src/sage/ext/interpreters/wrapper_cc.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_cc.pyx',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_cdf.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_cdf.pyx',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_el.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_el.pyx',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_py.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_py.pyx',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_rdf.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_rdf.pyx',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_rr.pxd',
     '/home/release/Sage/src/sage/ext/interpreters/wrapper_rr.pyx']
**********************************************************************
1 item had failures:
   1 of   7 in sage_setup.find.find_extra_files
    [36 tests, 1 failure, 0.27 s]
----------------------------------------------------------------------
sage -t --long --warn-long 42.4 --random-seed=0 src/sage_setup/find.py  # 1 doctest failed
----------------------------------------------------------------------
vbraun commented 4 years ago
comment:69

Might have been from #29950

mkoeppe commented 4 years ago
comment:70

Yes, it's #29950 that broke it.

vbraun commented 4 years ago

Changed branch from u/mkoeppe/replace_use_of_module_list_optionalextension to 55c3fbc