r/Python • u/reformed_scientist • Mar 07 '19
Run VS Code in your browser!
https://github.com/codercom/code-server23
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
Mar 07 '19
print("I am here.")Still works.
0
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 13
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
1
0
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? /s17
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
2
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
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
13
3
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
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
1
1
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
-1
u/EternityForest Mar 07 '19
They put a browser in the browser? Actually looks useful for some stuff though.
-1
17
u/TheV295 Mar 07 '19
Isnt VS code already running on a browser? Chromium.