py-execute-buffer and CWD

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

py-execute-buffer and CWD

andrea crotti-2
While trying to run a script and there is already another *Python*
buffer open
for another directory, running the script normally fails if there are some
relative file paths.

Apparently the CWD in the *Python* buffer remains the old one, and thus it
makes sense that Python can't resolve relative paths.

I tried to add this line in py-execute-buffer but without success,
any help?

     (cd (file-name-directory (buffer-file-name py-master-file)))

_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Andreas Röhler-2
Am 01.11.2011 12:33, schrieb Andrea Crotti:

> While trying to run a script and there is already another *Python*
> buffer open
> for another directory, running the script normally fails if there are some
> relative file paths.
>
> Apparently the CWD in the *Python* buffer remains the old one, and thus it
> makes sense that Python can't resolve relative paths.
>
> I tried to add this line in py-execute-buffer but without success,
> any help?
>
> (cd (file-name-directory (buffer-file-name py-master-file)))
>

Hi Andrea,

better use the bug-tracker for that kind of stuff.

Done here:

https://bugs.launchpad.net/python-mode/+bug/884739

_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Andreas Röhler-2
In reply to this post by andrea crotti-2
Am 01.11.2011 12:33, schrieb Andrea Crotti:

> While trying to run a script and there is already another *Python*
> buffer open
> for another directory, running the script normally fails if there are some
> relative file paths.
>
> Apparently the CWD in the *Python* buffer remains the old one, and thus it
> makes sense that Python can't resolve relative paths.
>
> I tried to add this line in py-execute-buffer but without success,
> any help?
>
> (cd (file-name-directory (buffer-file-name py-master-file)))

cd is a shell command

you can't mix that into Emacs Lisp.

BTW ipython shell would understand "cd" it, but that's another item.

Maybe give a example, what you trying to do, so we can look how to solve
that task.

BTW answered here, as you are not indicating a bug as thought at first
glance. My mistake...

_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Georg Brandl-2
Am 01.11.2011 21:53, schrieb Andreas Röhler:

> Am 01.11.2011 12:33, schrieb Andrea Crotti:
>> While trying to run a script and there is already another *Python*
>> buffer open
>> for another directory, running the script normally fails if there are some
>> relative file paths.
>>
>> Apparently the CWD in the *Python* buffer remains the old one, and thus it
>> makes sense that Python can't resolve relative paths.
>>
>> I tried to add this line in py-execute-buffer but without success,
>> any help?
>>
>> (cd (file-name-directory (buffer-file-name py-master-file)))
>
> cd is a shell command
>
> you can't mix that into Emacs Lisp.
It's also an elisp function.

(I agree that it's named a bit out-of-consistency with the usual
wordy elisp function names...)

Georg


_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

andrea crotti-2
In reply to this post by Andreas Röhler-2
On 11/01/2011 08:53 PM, Andreas Röhler wrote:

> cd is a shell command
>
> you can't mix that into Emacs Lisp.
>
> BTW ipython shell would understand "cd" it, but that's another item.
>
> Maybe give a example, what you trying to do, so we can look how to
> solve that task.
>
> BTW answered here, as you are not indicating a bug as thought at first
> glance. My mistake...
>
Mm I don't think so:
cd is an interactive compiled Lisp function in `files.el'.

And anyway, I think is quite a bug, because if I run a python script I
should expect that it runs in
the same current directory...

_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Georg Brandl-3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 01.11.2011 22:50, schrieb Andrea Crotti:

> On 11/01/2011 08:53 PM, Andreas Röhler wrote:
>> cd is a shell command
>>
>> you can't mix that into Emacs Lisp.
>>
>> BTW ipython shell would understand "cd" it, but that's another item.
>>
>> Maybe give a example, what you trying to do, so we can look how to solve
>> that task.
>>
>> BTW answered here, as you are not indicating a bug as thought at first
>> glance. My mistake...
>>
> Mm I don't think so: cd is an interactive compiled Lisp function in
> `files.el'.
>
> And anyway, I think is quite a bug, because if I run a python script I
> should expect that it runs in the same current directory...

I quite agree.

Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEARECAAYFAk6waeUACgkQN9GcIYhpnLB+6wCfTtoS2ygA2KWbm1IhHf2B47rj
rPsAoLETDsRQs6uzebCAAt3tz3kUCWs9
=N2f6
-----END PGP SIGNATURE-----
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

andrea crotti-2
In reply to this post by Andreas Röhler-2
So from my understading the problem is that if there is another *Python*
buffer around,
it will just be used without changing the current directory.
Apparently my attempt to "cd" didn't have any effect, so maybe we need
to pass the path
of the master py file to the real "execute" function, does it make sense?

Another partially unrelated thing, I noticed the two following:

(defun py-execute-buffer-no-switch (&optional async)
   "Like `py-execute-buffer', but ignores setting of
`py-shell-switch-buffers-on-execute', output-buffer will being switched to."

(defun py-execute-buffer-switch (&optional async)
   "Like `py-execute-buffer', but ignores setting of
`py-shell-switch-buffers-on-execute', output-buffer will being switched
to. "

Which
- are different functions but with the same docstring
- are never called from anywhere and not bound to any keys..
So are they useful at all maybe?
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Andreas Röhler-2
In reply to this post by Georg Brandl-3
Am 01.11.2011 22:51, schrieb Georg Brandl:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Am 01.11.2011 22:50, schrieb Andrea Crotti:
>> On 11/01/2011 08:53 PM, Andreas Röhler wrote:
>>> cd is a shell command
>>>
>>> you can't mix that into Emacs Lisp.
>>>
>>> BTW ipython shell would understand "cd" it, but that's another item.
>>>
>>> Maybe give a example, what you trying to do, so we can look how to solve
>>> that task.
>>>
>>> BTW answered here, as you are not indicating a bug as thought at first
>>> glance. My mistake...
>>>
>> Mm I don't think so: cd is an interactive compiled Lisp function in
>> `files.el'.
>>
>> And anyway, I think is quite a bug, because if I run a python script I
>> should expect that it runs in the same current directory...
>
> I quite agree.
>
> Georg

so follows up here:

https://bugs.launchpad.net/python-mode/+bug/884739
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: py-execute-buffer and CWD

Andreas Röhler-2
In reply to this post by andrea crotti-2
Am 01.11.2011 23:33, schrieb Andrea Crotti:
[ ... ]

> Another partially unrelated thing, I noticed the two following:
>
> (defun py-execute-buffer-no-switch (&optional async)
> "Like `py-execute-buffer', but ignores setting of
> `py-shell-switch-buffers-on-execute', output-buffer will being switched
> to."
>
> (defun py-execute-buffer-switch (&optional async)
> "Like `py-execute-buffer', but ignores setting of
> `py-shell-switch-buffers-on-execute', output-buffer will being switched
> to. "
>
> Which
> - are different functions but with the same docstring
> - are never called from anywhere and not bound to any keys..
> So are they useful at all maybe?
>

The first has a docu bug: must read "will _not_ being switched to"

maybe change that into: sending buffer remains current.

BTW better keep items apart, if you can...
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode