Ticket #13715: trac13715.2.patch

File trac13715.2.patch, 8.1 KB (added by ddrake, 6 years ago)

rebased for 5.9.beta0

  • doc/en/reference/misc/index.rst

    # HG changeset patch
    # User Dan Drake <ddrake@member.ams.org>
    # Date 1353617968 28800
    # Node ID 32a6cc48adb91adeecb461ec3bc36956cf898c6d
    # Parent  2cdee9868e867bd1c0e3d2bacb7172ae6ef4e7dc
    documentation for attach() should mention load_attach_path()
    
    diff --git a/doc/en/reference/misc/index.rst b/doc/en/reference/misc/index.rst
    a b  
    5050   sage/misc/cython
    5151   sage/misc/messaging
    5252   sage/misc/viewer
     53   sage/misc/session
    5354
    5455LaTeX
    5556-----
  • sage/misc/preparser.py

    diff --git a/sage/misc/preparser.py b/sage/misc/preparser.py
    a b  
    14471447
    14481448def reset_load_attach_path():
    14491449    """
    1450     Resets the current search path for loading and attaching files.
    1451    
     1450    Resets the current search path for :func:`load` and
     1451    :meth:`~sage.misc.session.attach`.
     1452
    14521453    The default path is '.' plus any paths specified in the environment
    14531454    variable `SAGE_LOAD_ATTACH_PATH`.
    1454    
     1455
    14551456    EXAMPLES::
    1456    
     1457
    14571458        sage: load_attach_path()
    14581459        ['.']
    14591460        sage: t_dir = tmp_dir()
     
    14621463        True
    14631464        sage: reset_load_attach_path(); load_attach_path()
    14641465        ['.']
    1465    
     1466
    14661467    At startup, Sage adds colon-separated paths in the environment
    14671468    variable ``SAGE_LOAD_ATTACH_PATH``::
    14681469
     
    17221723        sage: sage.misc.preparser.load('http://wstein.org/loadtest.py', globals())  # optional - internet
    17231724        hi from the net
    17241725
    1725     We can load files using secure http (https):: 
     1726    We can load files using secure http (https)::
    17261727
    1727         sage: sage.misc.preparser.load('https://github.com/jasongrout/minimum_rank/raw/minimum_rank_1_0_0/minrank.py', globals())  # optional - internet 
     1728        sage: sage.misc.preparser.load('https://github.com/jasongrout/minimum_rank/raw/minimum_rank_1_0_0/minrank.py', globals())  # optional - internet
    17281729
    17291730    We attach a file::
    17301731
     
    18481849
    18491850def load_attach_mode(load_debug=None, attach_debug=None):
    18501851    """
    1851     Get or modify the current debug mode for loading and attaching
    1852     .sage files.
     1852    Get or modify the current debug mode for the behavior of
     1853    :func:`load` and :meth:`~sage.misc.session.attach` on ``.sage``
     1854    files.
    18531855
    1854     In debug mode, loaded or attached .sage files are preparsed
    1855     through a file to make their tracebacks more informative.
    1856     If not in debug mode, then .sage files are preparsed
    1857     in memory only for performance.
     1856    In debug mode, loaded or attached ``.sage`` files are preparsed
     1857    through a file to make their tracebacks more informative. If not in
     1858    debug mode, then ``.sage`` files are preparsed in memory only for
     1859    performance.
    18581860
    18591861    At startup, debug mode is ``True`` for attaching and ``False``
    18601862    for loading.
    1861    
     1863
    18621864    INPUT:
    18631865
    18641866    - ``load_debug`` - boolean or (the default) ``None``;
     
    18721874
    18731875    - if all input values are ``None``, returns a tuple
    18741876      giving the current modes for loading and attaching.
    1875    
     1877
    18761878    EXAMPLES::
    18771879
    18781880        sage: load_attach_mode()
     
    18971899
    18981900def load_attach_path(path=None, replace=False):
    18991901    """
    1900     Get or modify the current search path for loading and attaching
    1901     files.
     1902    Get or modify the current search path for :func:`load` and
     1903    :meth:`~sage.misc.session.attach`.
    19021904
    19031905    INPUT:
    19041906
     
    19311933        sage: attach('test.py')
    19321934        111
    19331935        sage: attached_files() == [fullpath]
    1934         True       
     1936        True
    19351937        sage: sage.misc.reset.reset_attached(); reset_load_attach_path()
    19361938        sage: load_attach_path() == ['.']
    19371939        True
     
    20422044   
    20432045def attached_files():
    20442046    """
    2045     Returns a list of all files attached to the current session.
     2047    Returns a list of all files attached to the current session with
     2048    :meth:`~sage.misc.session.attach`.
    20462049
    20472050    OUTPUT:
    20482051
     
    20622065
    20632066def detach(filename):
    20642067    """
    2065     Detaches a file, if it was attached with the attach command.
     2068    Detaches a file, if it was attached with
     2069    :meth:`~sage.misc.session.attach`.
    20662070
    20672071    INPUT:
    20682072
  • sage/misc/session.pyx

    diff --git a/sage/misc/session.pyx b/sage/misc/session.pyx
    a b  
    357357    """
    358358    Attach a file or files to a running instance of Sage and also load
    359359    that file.
    360    
     360
     361    USAGE:
     362
     363    ``attach file1 ...`` - space-separated list of ``.py``, ``.pyx``,
     364    and ``.sage`` files, or ``attach('file1', 'file2')`` - filenames as
     365    strings, given as arguments to :func:`attach`.
     366
     367    :meth:`~sage.misc.preparser.load` is the same as :func:`attach`, but doesn't
     368    automatically reload a file when it changes.
     369
    361370    .. note::
    362371
    363372       In addition to ``attach('foo.sage')``, from the sage prompt
    364373       you can also just type ``attach "foo.sage"``.  However this
    365374       second common usage is not part of the Python language.
    366    
    367     ``load`` is the same as attach, but doesn't automatically reload a
    368     file when it changes.
    369    
     375
     376    EFFECT:
     377
     378    Each file is read in and added to an internal list of watched files.
     379    The meaning of reading in a file depends on the file type:
     380
     381    -  ``.py`` files are read in with no preparsing (so, e.g., ``2^3`` is 2
     382       bit-xor 3);
     383
     384    -  ``.sage`` files are preparsed, then the result is read in;
     385
     386    - ``.pyx`` files are *not* preparsed, but rather are compiled to a
     387       module ``m`` and then ``from m import *`` is executed.
     388
     389    The contents of the file are then loaded, which means they are read
     390    into the running Sage session. For example, if ``foo.sage`` contains
     391    ``x=5``, after attaching ``foo.sage`` the variable ``x`` will be set
     392    to 5. Moreover, any time you change ``foo.sage``, before you execute
     393    a command, the attached file will be re-read automatically (with no
     394    intervention on your part).
     395
     396    EXAMPLES:
     397
    370398    You attach a file, e.g., ``foo.sage`` or ``foo.py`` or
    371399    ``foo.pyx``, to a running Sage session by typing::
    372    
     400
    373401        sage: attach foo.sage   # or foo.py   or foo.pyx or even a URL to such a file (not tested)
    374402
    375403    or::
    376    
     404
    377405        sage: attach('foo.sage')  # not tested
    378406
    379407    Here we test attaching multiple files at once::
    380    
     408
    381409        sage: sage.misc.reset.reset_attached()
    382410        sage: t1 = tmp_filename(ext='.py')
    383411        sage: open(t1,'w').write("print 'hello world'")
     
    389417        sage: set(attached_files()) == set([t1,t2])
    390418        True
    391419
    392     The contents of the file are then loaded, which means they are
    393     read into the running Sage session. For example, if ``foo.sage``
    394     contains ``x=5``, after attaching ``foo.sage`` the variable ``x``
    395     will be set to 5. Moreover, any time you change ``foo.sage``,
    396     before you execute a command, the attached file will be re-read
    397     automatically (with no intervention on your part).
    398    
    399     USAGE: ``attach file1 ...`` - space-separated list of .py, .pyx,
    400     and .sage files.
    401    
    402     EFFECT: Each file is read in and added to an internal list of
    403     watched files. The meaning of reading a file in depends on the file
    404     type:
    405    
    406    
    407     -  read in with no preparsing (so, e.g., ``23`` is 2
    408        bit-xor 3),
    409    
    410     -  preparsed then the result is read in
    411    
    412     -  *not* preparsed. Compiled to a module ``m`` then
    413        ``from m import *`` is executed.
    414    
    415    
    416     Type ``attached_files()`` for a list of all currently
    417     attached files.
     420    .. SEEALSO::
    418421
    419     Use ``detach(...)`` to instruct Sage to remove a file from the internal
    420     list watched files.
     422        - :meth:`~sage.misc.preparser.attached_files` returns a list of
     423          all currently attached files.
    421424
    422     .. note::
     425        - :meth:`~sage.misc.preparser.detach` instructs Sage to remove a
     426          file from the internal list of watched files.
    423427
    424         ``attach`` is exactly the same as load, except it keeps track of
    425         the loaded file and automatically reloads it when it changes.
     428        - :meth:`~sage.misc.preparser.load_attach_path` allows you to
     429          get or modify the current search path for loading and attaching
     430          files.
    426431    """
    427432    import preparser
    428433    for filename in files: