cd /Documents/course-123/ fails because of preparser

55 views
Skip to first unread message

Neil Penning

unread,
Jul 31, 2020, 1:37:22 PM7/31/20
to sage-devel
Hello, I'm new to sagemath, and I stumbled upon a bug and I don't know where else to report it.

The preparser seems to have no problem with "cd test123" but has a problem with "cd test-123" (see screenshot)
Screen Shot 2020-07-31 at 1.24.48 PM.png

Dima Pasechnik

unread,
Jul 31, 2020, 2:01:11 PM7/31/20
to sage-devel
On Fri, Jul 31, 2020 at 6:37 PM Neil Penning <ne...@penning.email> wrote:
>
> Hello, I'm new to sagemath, and I stumbled upon a bug and I don't know where else to report it.
>
> The preparser seems to have no problem with "cd test123" but has a problem with "cd test-123" (see screenshot)

Thanks. As a workaround, one can use

sage: cd "test-123"

to avoid this issue (if you know how to fix this, you're most welcome
to contribute a fix)


>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/5a30f756-4dc3-47a4-b9df-003e7b96b63cn%40googlegroups.com.

Sébastien Labbé

unread,
Jul 31, 2020, 2:13:18 PM7/31/20
to sage-devel
This might be a workaround too:

sage: !cd test-123

Neil Penning

unread,
Jul 31, 2020, 2:28:27 PM7/31/20
to sage-...@googlegroups.com
Thank you both.

I'll take a stab at improving the preparse code, but these solutions sort of make the issue moot.


On Fri, Jul 31, 2020 at 2:13 PM Sébastien Labbé <sla...@gmail.com> wrote:
This might be a workaround too:

sage: !cd test-123

--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/zIswdvM_YK4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/b17f1745-6211-4124-82fe-e990d82dc7a7o%40googlegroups.com.

Justin C. Walker

unread,
Jul 31, 2020, 4:06:42 PM7/31/20
to SAGE Development


> On Jul 31, 2020, at 10:27, Neil Penning <ne...@penning.email> wrote:
>
> Hello, I'm new to sagemath, and I stumbled upon a bug and I don't know where else to report it.
>
> The preparser seems to have no problem with "cd test123" but has a problem with "cd test-123" (see screenshot)

Ha! I don’t know if that has ever been noticed before. Good catch!

FWIW, there’s a “magic” version that avoids this issue: “%cd”, viz:

> sage: cd /tmp/this-1/
> [Errno 2] No such file or directory: '/tmp/this-Integer(1)/'
> /private/tmp
> sage: %cd /tmp/this-1/
> /private/tmp/this-1

Given the workaround, I don’t know that it’s worth a trac report, but if you think so, make one.

HTH

Justin

Justin C. Walker

unread,
Jul 31, 2020, 4:18:43 PM7/31/20
to SAGE Development


> On Jul 31, 2020, at 11:13, Sébastien Labbé <sla...@gmail.com> wrote:
>
> This might be a workaround too:
>
> sage: !cd test-123

I don’t think this will work. The “!” forks a subshell where the given command is executed, and once the command executes (so the CWD is “test-123”), the shell exits, leaving the “sage” command with its CWD unchanged :-}

Justin


Nils Bruin

unread,
Jul 31, 2020, 7:52:47 PM7/31/20
to sage-devel
 Quotes are your friend. Try

sage: cd "test-123"

It would be virtually impossible to adapt the preparser in a reasonable way to recognize this exceptional pattern. We'd basically have to teach it these specific prefixes. If we ever look at hooking preparsing somewhere else, then this might be an example to take into account (IPyhton must somehow recognize this and not subject it to python parsing, meaning we should hook in after that distinction has been made)

Markus Wageringel

unread,
Aug 1, 2020, 6:36:58 AM8/1/20
to sage-devel
This issue is difficult to solve. A similar problem was discussed in https://trac.sagemath.org/ticket/29391#comment:4. Using `cd` instead of `%cd` is an IPython "feature" called automagic which is not guaranteed to always work – for example, if there is a variable named `cd` in scope. The following behavior is correct I would say:

sage: implicit_multiplication(True)
sage
: cd = 10
sage
: test = 100
sage
: cd test-123
877
sage
: preparse("cd test-123")
cd
*test-Integer(123)

Reply all
Reply to author
Forward
0 new messages