Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configure option --with-sage-venv=SAGE_VENV to create venv there instead of in SAGE_LOCAL #29013

Closed
mkoeppe opened this issue Jan 14, 2020 · 141 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 14, 2020

#27824 made $SAGE_LOCAL a venv if a suitable system python3 is found.

In this ticket, we add support for installing builds of Sage with several python versions, sharing the non-Python packages in SAGE_LOCAL:

  • keeping install records for Python packages (recognized by having install-requires.txt or requirements.txt) in $SAGE_VENV/var/lib/sage/{installed,scripts,wheels}, separate from those of non-Python packages ($SAGE_LOCAL/var/lib/sage/{installed,scripts})
  • likewise for $SAGE_LOCAL/var/tmp/sage/build
  • here $SAGE_VENV defaults to $SAGE_LOCAL, but can be overridden to an arbitrary directory that will be used as the wheel-building venv, for example $SAGE_LOCAL/var/lib/sage/venv/$PYTHON_TAG.

Configuration:

  • This is activated by running, for example,
    ./configure --with-python=/usr/bin/python3.8 --with-sage-venv="$SAGE_LOCAL/var/lib/sage/venv/python3.8".

As of this ticket, we are able to establish the venv in an arbitrary configured directory instead of SAGE_LOCAL. This is already useful for #31396 to create a wheel-building venv that will not be packaged as part of SAGE_LOCAL.

In follow-up tickets, we gain the full functionality that facilitates testing with several Python versions without having to rebuild the Sage distribution. This depends on:

Follow-ups:

  • We also want to support ./configure --with-sage-venv=no which would suppress making any venv (./configure --with-sage-venv=none #30896)

  • Support the tricky case: When system python3 is not in use and SAGE_VENV != SAGE_LOCAL, then both a real $SAGE_LOCAL/bin/python3 needs to be built and a venv in SAGE_VENV created... or should python3 be installed in $SAGE_VENV?)

  • Optional: A file build/pkgs/SPKG/trees could override the install tree determination - this would allow us to for example install a package such as jupyter_core both into something like SAGE_NOTEBOOK_VENV and SAGE_VENV...

CC: @dimpase @jdemeyer @embray @vbraun @jhpalmieri

Component: build

Keywords: sd111

Author: Matthias Koeppe

Branch/Commit: d68e861

Reviewer: John Palmieri

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

@mkoeppe mkoeppe added this to the sage-9.1 milestone Jan 14, 2020
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Author: Matthias Koeppe

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Branch: public/29013-use-py3-venv

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:3

A simple change. Compiles from a fresh checkout and runs without problems on macOS.


New commits:

1363425In a python3 build, install all Python packages into a venv
a394268sage-pip-install: Use PYTHON=sage-python23

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Commit: a394268

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:4

In the branch #27824, the venv is created by slightly more complicated code in build/make/Makefile. This complexity is not necessary for the present ticket.

@dimpase
Copy link
Member

dimpase commented Jan 15, 2020

comment:5

Does this ticket make sense separately, or only as part of #27824 ?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:6

#27824 is the use case that I have in mind.
This ticket is a less intrusive change and should go through the betas first.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Dependencies: #29002

@jhpalmieri
Copy link
Member

comment:8

I tried building with this branch on OS X, and I got doctest failures:

sage -t --long src/sage/plot/plot.py  # 1 doctest failed
sage -t --long src/sage/matrix/matrix2.pyx  # 2 doctests failed
sage -t --long src/sage/finance/time_series.pyx  # 5 doctests failed
sage -t --long src/sage/misc/trace.py  # 4 doctests failed
sage -t --long src/sage/env.py  # 1 doctest failed
sage -t --long src/sage/repl/configuration.py  # 1 doctest failed
sage -t --long src/sage/schemes/affine/affine_homset.py  # 1 doctest failed

For example

File "src/sage/plot/plot.py", line 521, in sage.plot.plot
Failed example:
    os.system("sage -c \"if 'matplotlib' in sys.modules: sys.exit(1)\"") # long time
Expected:
    0
Got:
    Traceback (most recent call last):
      File "/Users/jpalmier/Desktop/Sage/sage_builds/TESTING/sage-9.1.beta0/local/bin/sage-eval", line 4, in <module>
        from sage.all import *
    ModuleNotFoundError: No module named 'sage'
    256

and

**********************************************************************
File "src/sage/matrix/matrix2.pyx", line 1127, in sage.matrix.matrix2.Matrix.pseudoinverse
Failed example:
    M.pseudoinverse()  # tol 1e-15
Expected:
    [0.0620518477661335 0.0206839492553778 0.0124103695532267]
    [ 0.124103695532267 0.0413678985107557 0.0248207391064534]
    [ 0.186155543298400 0.0620518477661335 0.0372311086596801]
Got:
    [0.0620518477661334 0.0206839492553778 0.0124103695532267]
    [ 0.124103695532267 0.0413678985107556 0.0248207391064534]
    [ 0.186155543298400 0.0620518477661335 0.0372311086596801]
Tolerance exceeded in 2 of 9:
    0.0620518477661335 vs 0.0620518477661334, tolerance 2e-15 > 1e-15
    0.0413678985107557 vs 0.0413678985107556, tolerance 3e-15 > 1e-15
**********************************************************************
File "src/sage/matrix/matrix2.pyx", line 1131, in sage.matrix.matrix2.Matrix.pseudoinverse
Failed example:
    M.pseudoinverse(algorithm="numpy")  # tol 1e-15
Expected:
    [0.0620518477661335 0.0206839492553778 0.0124103695532267]
    [ 0.124103695532267 0.0413678985107557 0.0248207391064534]
    [ 0.186155543298400 0.0620518477661335 0.0372311086596801]
Got:
    [0.0620518477661334 0.0206839492553778 0.0124103695532267]
    [ 0.124103695532267 0.0413678985107556 0.0248207391064534]
    [ 0.186155543298400 0.0620518477661335 0.0372311086596801]
Tolerance exceeded in 2 of 9:
    0.0620518477661335 vs 0.0620518477661334, tolerance 2e-15 > 1e-15
    0.0413678985107557 vs 0.0413678985107556, tolerance 3e-15 > 1e-15
**********************************************************************
1 item had failures:
   2 of  25 in sage.matrix.matrix2.Matrix.pseudoinverse
    [2472 tests, 2 failures, 9.06 s]

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:9

Thanks for testing!

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Changed dependencies from #29002 to #29002, #29022

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:10

Replying to @jhpalmieri:

sage -t --long src/sage/matrix/matrix2.pyx # 2 doctests failed

Not sure what's causing the numerical failures.

sage -t --long src/sage/env.py # 1 doctest failed

For this one, I have created #29022.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 15, 2020

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

d4fbe40_get_shared_lib_filename: Do not assume Python sysconfig paths are in SAGE_LOCAL

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 15, 2020

Changed commit from a394268 to d4fbe40

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 15, 2020

Changed commit from d4fbe40 to d1779cc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 15, 2020

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

bba08ecCreate module src/sage/env_config.py from src/sage/env_config.py.in, defining SAGE_LOCAL
d1779ccMerge branch 't/29022/create_module_src_sage_env_config_py_from_src_sage_env_config_py_in__defining_variables_for_use_in_sage_env' into t/29013/public/29013-use-py3-venv

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:13

Replying to @mkoeppe:

sage -t --long src/sage/env.py # 1 doctest failed

For this one, I have created #29022.

Fixed.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2020

comment:14

The numerical problems seems to happen because numpy does not find BLAS.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2020

comment:15

Actually, it does not find openblas or atlas, but it does find the "Accelerate framework":

accelerate_info:
  FOUND:
    extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
    define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]

  FOUND:
    extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
    define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 16, 2020

Changed commit from d1779cc to 93bae6f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 16, 2020

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

85147f9build/pkgs/numpy/lapack_conf.py: Add a [DEFAULT] section to site.cfg
93bae6fMerge branch 't/29025/numpy__site_cfg_needs_a__default__section' into t/29013/public/29013-use-py3-venv

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2020

comment:17

Merged #29025, fixes the numerical doctests.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2020

Changed dependencies from #29002, #29022 to #29002, #29022, #29025

@dimpase
Copy link
Member

dimpase commented Jan 16, 2020

comment:18

I see a problem with cryptominisat spkg on this branch (which otherwise builds and passes most tests (not related to this packages) on Gentoo)

sage -t --warn-long 88.1 src/sage/sat/solvers/cryptominisat.py
**********************************************************************
File "src/sage/sat/solvers/cryptominisat.py", line 49, in sage.sat.solvers.cryptominisat.CryptoMiniSat
Failed example:
    solver = CryptoMiniSat()                                  # optional - cryptominisat
Exception raised:
    Traceback (most recent call last):
      File "/mnt/opt/Sage/sage-dev/local/lib/sage/venv/sage/lib/python3.7/site-packages/sage/sat/solvers/cryptominisat.py", line 69, in __init__
        from pycryptosat import Solver
    ModuleNotFoundError: No module named 'pycryptosat'

I wonder whether it uses a convoluted way to create python extensions, which got broken.

@mkoeppe mkoeppe changed the title Support installation of Python packages into separate venvs depending on the python version Add configure option --with-sage-venv=SAGE_VENV to create venv there instead of in SAGE_LOCAL Apr 4, 2021
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 5, 2021

Changed commit from 92f1a1b to 9dcded5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 5, 2021

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

1942363build/pkgs/pynac/spkg-install.in: Back to PYTHON=python3
9dcded5src/bin/sage: Only do the check for an incomplete installation when run from the source tree

@jhpalmieri
Copy link
Member

comment:96

With ./configure --with-python=/usr/bin/python3 --with-sage-venv="`pwd`/local/var/lib/sage/venv/python3.8", I'm getting some doctest failures:

sage -t --long --warn-long 101.2 --random-seed=0 src/sage/misc/package.py  # 5 doctests failed

(because it doesn't find some Python packages). Also

sage -t --long --warn-long 101.2 --random-seed=0 src/sage_setup/find.py  # 2 doctests failed
sage -t --long --warn-long 101.2 --random-seed=0 src/sage_setup/clean.py  # 1 doctest failed

Details:

File "src/sage_setup/find.py", line 365, in sage_setup.find.installed_files_by_module
Failed example:
    f1
Expected:
    'sage/structure/__init__.py'
Got:
    '/Users/palmieri/Library/Caches/com.apple.python/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.8/lib/python3.8/site-packages/sage/structure/__init__.cpython-38.pyc'
**********************************************************************
File "src/sage_setup/find.py", line 367, in sage_setup.find.installed_files_by_module
Failed example:
    f2
Expected:
    'sage/structure/....pyc'
Got:
    'sage/structure/__init__.py'
**********************************************************************
File "src/sage_setup/clean.py", line 96, 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)
Expected nothing
Got:
    Found stale file: /Users/palmieri/Library/Caches/com.apple.python/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.8/lib/python3.8/site-packages/sage/all_cmdline.cpython-38.pyc
...
[followed by many many lines of "stale" files]

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 6, 2021

comment:97

The ones in find and clean are I think #31314.

For the failure in package I know what to do

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 6, 2021

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

6e0c19esage.misc.package.installed_packages: After SAGE_SPKG_INST, also go through SAGE_VENV_SPKG_INST

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 6, 2021

Changed commit from 9dcded5 to 6e0c19e

@jhpalmieri
Copy link
Member

comment:100

The sage_setup doctest failures have vanished, but I am seeing different problems with misc/package.py:

**********************************************************************
File "src/sage/misc/package.py", line 554, in sage.misc.package.package_manifest
Failed example:
    sagetex_manifest = package_manifest('sagetex')  # optional - build
Exception raised:
    Traceback (most recent call last):
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.package.package_manifest[1]>", line 1, in <module>
        sagetex_manifest = package_manifest('sagetex')  # optional - build
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/misc/package.py", line 570, in package_manifest
        with open(stamp_file) as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/installed/sagetex-3.5'
**********************************************************************
File "src/sage/misc/package.py", line 555, in sage.misc.package.package_manifest
Failed example:
    sagetex_manifest['package_name'] == 'sagetex'  # optional - build
Exception raised:
    Traceback (most recent call last):
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.package.package_manifest[2]>", line 1, in <module>
        sagetex_manifest['package_name'] == 'sagetex'  # optional - build
    NameError: name 'sagetex_manifest' is not defined
**********************************************************************
File "src/sage/misc/package.py", line 557, in sage.misc.package.package_manifest
Failed example:
    'files' in sagetex_manifest  # optional - build
Exception raised:
    Traceback (most recent call last):
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.rc1/local/var/lib/sage/venv/python3.9/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.package.package_manifest[3]>", line 1, in <module>
        'files' in sagetex_manifest  # optional - build
    NameError: name 'sagetex_manifest' is not defined
**********************************************************************

I guess the issue is that manifests are now written to two different places, depending on whether it's a Python package or not.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 6, 2021

comment:101

Right, I forgot about this function. It will need a slightly generalized interface

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 7, 2021

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

c5dd7baMerge tag '9.3.rc2' into t/29013/public/29013-use-py3-venv
f0fb082sage.misc.package.installed_packages: Refactor through new generator _spkg_inst_dirs
d68e861sage.misc.package.package_manifest: Go through all _spkg_inst_dirs()

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 7, 2021

Changed commit from 6e0c19e to d68e861

@jhpalmieri
Copy link
Member

comment:104

That fixes the package.py doctest for me, thank you. I'm not sure I fully understand how venvs are supposed to work. If I do ./configure --with-sage-venv=... && make and then separately do ./configure && make, I should get two builds (as far as Python packages are concerned), which I could conceivably switch between, right? Now if I do ./configure && make pysingular, then I can do import PySingular, but I switch to the other venv, I won't be able to. However, 'pysingular' in installed_packages() returns True regardless of whether I'm using the venv, since it searches both installation directories.

(a) Am I understanding the situation correctly? and

(b) is it worth trying to fix?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 7, 2021

comment:105

Replying to @jhpalmieri:

I'm not sure I fully understand how venvs are supposed to work. If I do ./configure --with-sage-venv=... && make and then separately do ./configure && make, I should get two builds (as far as Python packages are concerned), which I could conceivably switch between, right?

Yes, that's right. Separate for Python packages, sharing the non-Python packages, which are only in SAGE_LOCAL.

Now if I do ./configure && make pysingular, then I can do import PySingular, but I switch to the other venv, I won't be able to. However, 'pysingular' in installed_packages() returns True regardless of whether I'm using the venv, since it searches both installation directories.

OK, thanks for catching this. Yes, the sage.misc.package code does not handle this situation correctly. I would simply suggest to not mix builds that use with --with-sage-venv=... with builds that don't. You can switch between several venvs in this way.

@jhpalmieri
Copy link
Member

Reviewer: John Palmieri

@jhpalmieri
Copy link
Member

comment:106

Great, let's merge it, then.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 8, 2021

comment:107

Thank you!

@vbraun
Copy link
Member

vbraun commented May 27, 2021

Changed branch from public/29013-use-py3-venv to d68e861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants