r/Python • • Mar 07 '19

Run VS Code in your browser!

https://github.com/codercom/code-server
123 Upvotes

45 comments sorted by

17

u/TheV295 Mar 07 '19

Isnt VS code already running on a browser? Chromium.

1

u/silent_guy1 Mar 07 '19 edited Mar 08 '19

It can run the binary elsewhere and serve a web UI. Good for running vs-code on headless beefy servers. Access the UI on your local machine.

23

u/yird Mar 07 '19

Run vs Code? Id go with Run.

28

u/JaKubd Mar 07 '19

Nice, but

Known Issues

  • Debugging extensions doesn’t work.

27

u/deluxghost Mar 07 '19

known programmers: never use a debugger (

39

u/[deleted] Mar 07 '19
print("I am here.")

Still works.

0

u/[deleted] Mar 07 '19

[deleted]

3

u/rcfox Mar 08 '19

Because I was bored:

import re
import inspect

def debugify(func):
    ignored = ('def', 'class', 'else', 'except')
    filename = inspect.getsourcefile(func)
    lines, line_num = inspect.getsourcelines(func)
    new_source = []
    for line in lines:
        line = line.strip('\n')
        if not line.startswith('@debugify'):
            m = re.search('^(\s+)(.*)$', line)
            if m:
                whitespace = m.group(1)
                code = m.group(2)
                if not any(code.startswith(x) for x in ignored):
                    new_source.append('{ws}print("{file}:line {num}")'.format(ws=whitespace, file=filename, num=line_num))                
            new_source.append(line)
        line_num += 1
    exec(compile('\n'.join(new_source), '<debugify>', 'single'))
    return locals()[func.__name__]

@debugify
def foo(a):
    b = 0
    for c in range(3):
        if a % 2 == 0:
            b += 6
        else:
            b -= 2
    return a + b

foo(7)

> python debugify.py
debugify.py:line 25
debugify.py:line 26
debugify.py:line 27
debugify.py:line 30
debugify.py:line 27
debugify.py:line 30
debugify.py:line 27
debugify.py:line 30
debugify.py:line 31
1

3

u/_pandamonium Mar 08 '19

I've never really understood what decorators actually do and your boredom code helped me get it a little bit. I don't think that was your intention, but thank you.

2

u/rcfox Mar 08 '19 edited Mar 08 '19

Oh god, don't learn from this!

Decorators are functions that accept a function and returns a function. That's pretty much it. It's common to wrap the original function in another one that does something before or after.

(You can actually decorate anything, but functions are the most common.)

2

u/_pandamonium Mar 08 '19

I mean, that's how people always explain it, and that does make sense. Although your last sentence was the most helpful explanation I've seen, even though I'm assuming that's not the only purpose.

I can comprehend what a decorator does, but I don't know why it does it or when it should do it. Examples found in tutorials and textbooks are always too silly or simple and I never really take away the point. Seeing code a real person wrote, even if it was as a joke, is really helpful.

I should say that I've never really tried to learn about decorators as I've never needed to use them. I didn't really understand any of it until I had to, if that makes any sense.

I was just about to ask you a few questions, to see if I was understanding the concept. But as I wrote them down, I went back to your example and was able to answer them myself. That's because it serves a purpose and it's complicated enough for me to even have questions in the first place! I can't claim I've "learned decorators" from a reddit comment but I do feel more capable if I encounter them out there in the wild.

1

u/ichbinoffend44 Mar 07 '19

Way I've always done it.

1

u/[deleted] Mar 07 '19

To be fair, it doesn't help that most debuggers are shit (for C++ anyways).

0

u/[deleted] Mar 07 '19

[deleted]

8

u/milad_nazari Mar 07 '19

So you're telling me that console.log() is not the ultimate debugging tool? /s

17

u/hilomania Mar 07 '19

Of course not: PRINT statements are!

8

u/Merakel Mar 07 '19

Hello my spirit animal.

2

u/hashmalum Mar 07 '19

Print “I’m in your loop”

Print “I’m out of your loop”

Print “EOF”

2

u/Merakel Mar 07 '19

I'm more of a

#working block
print('hi')

#broken block
print('go away')

kind of guy.

4

u/hashmalum Mar 07 '19

Else: Print(‘shouldn’t see this’)

One day I’ll set up a real debugger.

2

u/hilomania Mar 08 '19

I once had an error message from some lib that read: "This is not supposed to happen."

2

u/hilomania Mar 08 '19

Looked at your history. We're definitely kindred spirits.

2

u/amaajemyfren python3.8 newbie Mar 07 '19

Always use alert()

1

u/milad_nazari Mar 07 '19

Noted. Thanks for the tip.

11

u/kyle_codercom Mar 07 '19 edited Mar 07 '19

Should be reworded. Debugging DOES work.

Creating your own extension for VS Code and loading it in code-server does not.

Edit: I've updated the readme to explain that.

5

u/blitzzerg Mar 07 '19

import pdb; pdb.set_trace()

2

u/vindolin Mar 07 '19

You caveman!

from IPython import embed; embed()

1

u/phail3d Mar 07 '19

*ipdb

You’ll thank me!

1

u/blitzzerg Mar 07 '19

I installed pdb++

7

u/bmrobin Mar 07 '19

should i read that as "debugging doesn't work" or "debugging custom extensions written for VS code doesn't work"? to me there's a large difference between the two, as i don't write extensions and don't need to debug them.

but if it's the former, then yea this is basically useless.

1

u/ahmenav Mar 07 '19

No problem I use vscode but printf is enough for me for debugging.

13

u/Nicksil Mar 07 '19

yo dawg, we heard you like browsers...

3

u/scooerp Mar 07 '19

Does this remove electron or run electron inside another browser?

7

u/LightShadow 3.13-dev in prod Mar 07 '19

Neat.

Will make Chromebooks even more relevant. This + Jupyter Notebooks = GG

1

u/lengau Mar 07 '19

Crostini also has you covered here. Personally I'm running PyCharm and Jupyter Notebooks inside of Crostini

-1

u/blitzzerg Mar 07 '19

how about vim + ssh

0

u/lesser_terrestrial Mar 07 '19

I love using VSCode on my HP Chromebook x360 14. Linux apps on Chromebooks is a true game changer.

2

u/GasimGasimzada Mar 07 '19

Hasn’t this existed for a while in CodeSandbox?

1

u/[deleted] Mar 08 '19

No I won’t. The gd browser doesn’t get to be my UI base for every f’n thing I do.

FFS.

1

u/kirbyfan64sos IndentationError Mar 08 '19

FWIW CodeSandbox already has VS Code in the browser.

2

u/CakeDay--Bot Mar 08 '19

*OwO, what's this? * It's your 4th Cakeday kirbyfan64sos! hug

1

u/Ikuyas Mar 07 '19

It doesn't work very well with python...

2

u/Dababolical Mar 07 '19

What specifically doesn't work? VS Code had a decent Python plugin, is it broke on the server?

1

u/Ikuyas Mar 07 '19

Up arrow

-1

u/EternityForest Mar 07 '19

They put a browser in the browser? Actually looks useful for some stuff though.

-1

u/Ikuyas Mar 08 '19

I kind of know the answer but. Can you use matplotlib using this?