|
|
14:16 |
|
show
|
7:01 |
And we're live.
Welcome everyone to...
No, dude, this is not a live stream, Cecil.
This is a course.
Visual Studio Code for Python Developers, man.
This is a course?
We're recording a course right now?
Yes, yes.
I know you're used to doing live streams, but we're doing a course now.
Oh, okay.
So what course is this?
Tell me, remind me.
Visual Studio Code for Python Developers.
Oh, that's right.
Yes, that's right, that's right.
Hi everyone, welcome to Visual Studio Code for Python Developers.
What am I supposed to do now?
Now we're supposed to talk about their instructors, Cecil.
Your instructors for this course are...
Me and you!
Dude, we're recording a course!
No, you.
Oh, you want me to talk about me?
Okay, go ahead.
I'll talk about me.
Hi everyone, my name is Cecil Phillip.
Developer advocate and big, big fan of Python.
And that's my picture here.
Is this the right finger?
Yes.
There you go.
And that's my social thing.
So if you want to reach out to me on social media at Twitter, at Mastodon, and Blue Sky, and all the things, you can probably find me at this...
Handle?
Is that what you call these things?
Yeah.
Some of these different places.
But super excited to be here, super excited to talk to you all.
And I am joined with my buddy, Brian.
That's me, looking like a doofus, as usual.
Yes, I am Brian, Brian Clark, go by Clarkio on the internets.
You can find me on Twitter, and I'm Brian Clark.
You can find me at that handle, either underscore Clarkio, because the name's taken, or just Clarkio.
And yeah, I am a Python enthusiast, I would say.
Cecil and I have live-streamed learning Python before, and that's what we were joking about before.
And I've been a developer for many, many years.
And I'm a developer advocate now as well.
And I'm excited to jump into this course and teach you about using Visual Studio Code for Python developers.
Assuming you're a Python developer.
I hope you're a Python developer.
I hope so, too.
So, we talked about...
What the course is, who their instructors are, but who's this course for?
Python developers?
Is that it?
I think so.
But I think even more importantly, why we're doing this course, because one, we're both fans of Python.
But we're also both fans of Visual Studio Code, right?
And in some weird universe, there must be a place where people like the two of those things and want to put them together.
Right?
And so, then there's the question, how do Python people Python on Visual Studio Code?
So, we thought it'd be a great...
I think it's a great way for us to kind of take two of those things that we're really passionate about and put them together and create a resource that will be hopefully helpful for all of you.
So, if you're new or maybe you're a seasoned Python developer or maybe, you know, maybe you're an architect, but like you've never used VS Code before.
Maybe this is the new thing for you, right?
Everyone's learning something new.
So, hopefully, regardless of whatever path that you're walking, hopefully you'll learn something from what me and Brian are going to share with you during this course.
Yeah.
And speaking of...
What you'll learn being that you're in the right place, let's talk about what we're going to cover in the course.
First up, we're going to help you get set up.
Okay.
If you don't have Visual Studio Code, if you don't have Python already, we're going to get you...
Walk you through that process very briefly, just to make sure we're all starting off on the same page.
Next up, we're going to be talking about exploring the editor.
So, getting acquainted with the visuals of VS Code and how you navigate around there and what the names are of different components within the UI.
So, you're going to be talking about the UI of Visual Studio Code so that you know what those terms are, you know what we're referring to throughout the rest of the course, and you're familiar with it and up to speed with all that.
After that, we're going to jump into editing the code.
So, what's the experience like writing Python code in Visual Studio Code?
And how do you go about making sure that that is up to the most optimal settings and situation in order to be able to do that successfully and efficiently?
Then we're going to be talking about managing environments.
So, we want to talk about that real quick.
Yeah.
So, one of the things that folks that if you're familiar with Python, you might have heard about virtual environments or even setting up your workspace, right?
What are some of those things that you wanted to do?
And maybe you already have a pattern that you'd like to use already today.
How can you do that with inside of VS Code?
So, we're going to try and show you how to get everything set up so that you're, you know, have the best chance to, you know, do the workflow that you're used to using the tools that we're going to show you.
All right.
And then next, it's going to be running in debugging.
Cecil, tell us more about that.
Well, if we're going to write the code, I'm going to assume we're going to want to run it at some point.
Yeah.
Well, if you run it, if it doesn't work, you probably need to debug it too, right?
So, how does that work in Python, right?
Like, how do we engage with the debugger and, you know, set breakpoints?
How do we use conditional breakpoints?
How do we look at some of the debug output and, you know, some of the other diagnostic tools that are inside of Python that'll help you make sure that your applications are running the way that you're expecting them to?
Very good.
And if you get it running, there's...
This is the next thing you're going to need to be doing, right?
To make sure that what you are running and using is working as expected, right?
Nobody test their code, Brian.
Come on.
Oh, man.
You got me there.
I'm guilty.
Nobody does that.
I'm playing.
You all should test your code.
Don't listen to me.
Test your code.
Please do.
And we're going to talk through some of the different, well, testing support in VS Code for Python.
It's not going to be an intro to testing, but it is going to show you how to run your test, probably look at some code coverage.
And again, how to, you know, use some of the navigational features inside of Visual Studio Code to make sure that your testing workflow is as efficient as possible.
Excellent.
And last but not least, we're going to be talking about source control, where you and I are going to demonstrate together what the experience is like checking things in, making changes, committing changes to our code on a project that we're both working on and what that experience is like for a Python project using source control within VS Code.
Visual Studio Code, right?
Yeah, I think one of the things I love about programming and even just being in the open source community is how we can collaborate with each other.
And I think Visual Studio Code gives us tons of great tools that allow us to collaborate.
And one of those is source control, right?
So, you know, I think it's important for me to know that if there's a bug, I want to look at the line of code and be able to blame somebody and be like, oh, OK, I wrote this.
My bad.
Yeah.
All right.
So that's what we're going to be covering.
You're going to what you can expect in the upcoming videos is a combination of either myself and Cecil together talking about a topic of choice within the what we're going to cover here.
But also sometimes it'll be us as individuals teaching you about that particular topic within that module.
So that's what you can expect throughout the rest of the course.
In the next video, we're going to tell you what you need to be prepared, like prerequisites, that type of thing in order to get started with this course.
And then after that, we'll talk about some resources you'll be able to use or throughout the whole course.
course.
Awesome.
Sounds good.
See you in the next video.
Sounds good.
|
|
show
|
5:04 |
Welcome into this next video.
We're going to be talking about what you will need in order to be able to follow along with this course.
First up, obviously, you're going to need the most important thing.
What is that, Cecil?
A computer.
Yeah.
One of the first things that you're going to need for this course, and we should have installed or we're going to talk about how you can get it installed, is Python.
We are going to talk about Python and VS Code, so hopefully you have Python installed already.
If not, we have some other videos later on in the course that are going to talk about how you can get it installed.
But for those of you that are pretty new or fresh, Python is a programming language, and it allows us to do a lot of cool things like build desktop applications and microservices and web apps and web APIs and tons of cool stuff.
So, again, we're not going to dive into how to use Python or the syntax and the semantics.
But we are going to talk about how you can be productive using Python inside of VS Code.
And speaking about VS Code, I'm guessing we're going to need to install that too, right?
Yes.
So you will need to get this in the getting started module.
You'll be able to go into detail on all of this, but I at least want to give you a high level overview of what Visual Studio Code is.
It is an editor.
It is not necessarily an IDE, but through its plugins and extensions, you will be able to kind of view it as on a spectrum of like whether it's an IDE or an IDE.
It is not necessarily an IDE, but through its plugins and extensions, you will be able to kind of view it as on a spectrum of like whether it's an IDE or an IDE.
but through its plugins and extensions, you will be able to kind of view it as on a spectrum of like whether it's an edit, more of an editor or an interactive or integrated development environment.
That is, because of the rich development experience you'll get with a lot of the plugins that are available to you in the VS Code marketplace.
So VS Code is a piece of software.
It's a desktop client, but also it could be used in the web, for VS Code.dev and it's built with web technologies.
So things like JavaScript and Electron help make it possible to be used cross-platform as a thick client application, but then also in the web, in your browser, like I was mentioning before, it is open source.
So if you went to github.com/Microsoft slash VS Code, you can follow along.
You can build it from source if you wanted to, even it's completely free and, you can, you know, keep up to speed with the latest releases and, and the development.
Activity on it directly in this open source repository.
So now that we know what you're going to need, like Python and VS Code, I mentioned editors and IDEs.
What Cecil, what's the difference for folks that aren't familiar with that?
What's the difference between the two?
Yeah, I think that's an important thing for us to like take care of off the bat.
And for folks that are in the Python space, if you've been around for a little while, you might even have heard of a couple like PyCharm as an example.
And PyCharm is a really good, Python IDE, right?
IDE standing for integrated development environment versus an editor.
And now one of the things that you get from your IDE versus your editor is, well, you usually get a lot deeper support for introspection and debugging for, you know, a lot of analyzers, linters, all these different types of things.
And they're usually already pre-packaged and bundled and ready for you to go.
Right?
Python itself, again, it's, it's very focused on Python.
We talk about this Visual Studio Code, as you'll see as we go on, it's a very extensible editor.
It's good for editing code, and you can add extensions to it.
You can customize it, you can tweak it, you can set whatever settings you need to set, so you can do what you want to do.
But it is not an IDE, right?
So again, out of the box, you can expect to have things like templates or syntax highlighting for your templating languages and all these different types of things from your IDE.
And you might have that in your editor too, but usually your editor has so much better support, even support for deployments, version control, all kinds of things, but with so much more additional features.
Like what Brian mentioned a little while ago, VS Code is free.
It's free, it's open source, and you could download it and compile it and tweak it yourself if you wanted to.
Versus something like PyChart, well, you do have to pay some money for it.
They do have licensing available for open source projects and students so that you don't have to pay or pay as much for it.
But again, IDEs and editors are different, right?
And they serve different purposes.
So again, we're going to focus on the editor, right?
Which is Visual Studio Code in this course.
But PyChart is a really great choice if it has the features that you need it to, you know, to build your application with.
Yeah, and really quick to close that out, there is this awesome blog post on LogRocket about PyCharm versus VS Code that goes more in depth if you want to know and understand that better on a deeper level.
You can go ahead and check that out.
We'll share the link in our resources, which leads me perfectly to segue into the next video where you're going to be able to find out what other resources we have available for you to use throughout the rest of the course to help you along the way.
So tune into that next.
|
|
show
|
2:11 |
Everybody.
Before we actually dive into the meat of the course and start talking about the editor and customizing it and debugging and source control and all those other cool topics we're going to cover.
First, I think it might be important for us to look at some of the resources that are available to you as you're just getting started with the course.
As you're looking at the screen right now, what you should be seeing is the GitHub repo for the course.
So VS Code-Python-Course.
And so inside of here, you should find pretty much everything that you need to follow along as you're watching some of our videos.
So you can imagine that the source code will be in there because GitHub, that makes sense, right?
And then we'll also have a full roommate that'll have links to resources, keyboard shortcuts that we use, settings and commands and things of that nature that we're using as we're going through the different chapters of this course.
Yes.
Anything else you think I'm missing, Brian?
No, we'll have links to download VS Code in there.
We'll have links to the extensions that we're talking about and we'll show you and work you through.
So anything basically it's one link you need to worry about the GitHub repo for this course and then everything else will be within there to make it simple and easy for you, the viewer here watching the course.
In addition to that, though, if you want to go and learn more beyond the course, one of the things you can do is go to VS Code's official documentation.
They have documentation on their website for specific languages.
And how?
They set things up with that particular language for VS Code.
And there's one for Python, of course.
So you can go through here.
It's a very high level type of documentation through it that you can, which links off to more things and goes into other topics that we're not going to be covering in this course.
Things like Jupyter notebooks and whatnot that goes a little bit further in depth within the Python ecosystem than what we're going to be covering.
You can check that out in addition.
But again, the main resource you want to use is the GitHub repo.
The GitHub repository.
That's it.
Right.
And I'm going to be inside of that documentation site, so you should stick here because we're going to have a lot more fun in this course.
Absolutely.
All right.
Well, next up for you, you're going to be moving on to the next module getting set up.
Cecil and I are going to walk you through that whole process.
|
|
|
14:54 |
|
show
|
0:32 |
Hey everyone, welcome to chapter 2 of the Visual Studio Code for Python Developers course.
So in this particular chapter, Brian and I are going to go through some of the things you need to do just to get set up to start taking this course.
So we're going to talk about, you know, Python and, you know, getting Python set up in your machine, different distributions of Python.
And also how you can get Visual Studio Code installed and set up in your machine.
And also talking about like the different versions of Visual Studio Code and when you may or may not want to use them.
Looking forward to it.
Let's get right into it.
Let's do it.
|
|
show
|
9:04 |
In this course, we're talking about how to use Python in VS Code.
So ultimately, at some point, we should install Python, right?
Like we should get some version of Python.
Nah.
You don't need it.
No.
Oh.
I mean, we should at some point, right?
Okay.
All right.
I guess so.
But here's the thing.
Here's the thing, right?
And I see what you're saying.
But here's the thing.
There's so many different iterations of Python.
It becomes hard for people to know like which one exactly should they install.
Yeah.
So I figured why don't we spend some time in this video kind of going through what are some of those different versions of Python and then, you know, some of the reasons you might pick one versus the other.
Does that make sense?
That makes sense.
And I'm excited about that.
That sounds good.
Because I don't know all the different versions of Python.
I just know Python.
And you know what?
And you know what?
We'll talk about that too.
Because what does Python mean?
Now we get into like this whole philosophical question.
Oh, wow.
Yeah.
I don't know.
What is Python, right?
What's the meaning of life, Cecil?
Is it Python?
What's the meaning of life?
Is Python the answer?
Maybe Python is the answer.
Okay.
But this is the first one we have.
So one of the more common distributions of Python is called Anaconda.
Now, this one is primarily used by a lot of folks that do data science, machine learning, that type of work.
And that's because when you install this distribution of Python, right, we call these different versions distributions.
It comes with like a lot of different versions of Python.
It comes with different Python packages, you know, tools and utilities and stuff like that, like included in the box.
That means that I don't have to go out and install a bunch of other stuff.
I can just download Anaconda.
And you see, I got stuff like Jupyter Notebooks.
I got Pandas.
I got all this stuff that's just kind of included.
So it's easy for me to just start, you know, playing around with Pandas or creating graphs and like finagling with my data.
So that's one of the reasons why a lot of folks like to use this particular distribution.
That's interesting.
That's interesting.
A lot of AI based stuff.
I like that it comes packaged with things.
I love the names of stuff like Pandas, you know, and Jupyter.
And Anaconda.
Yeah.
So this might be for somebody who's starting out with Python, though, this maybe is a little bit overkill.
Not maybe, maybe not overkill is the right word, but it's a little bit over the top for somebody just getting started in the beginning and maybe looking to use Python with VS Code.
Would you say that's the case or no?
Or what do you think?
Well, I would say it depends on what you call beginning.
Okay.
So a lot of folks that are beginning Python, they may be folks that maybe are using Excel or you're used to using some other tool for data analysis.
So you know what you're doing, right?
But maybe you really want tools to kind of help make your job a little bit easier.
So like something like having a notebook and working with cells and stuff like that is natural for you.
So now you have to learn Python to do it.
So for you, maybe having to install all those additional packages.
Maybe that might be overkill for you versus just, oh, okay, I just have it because I just downloaded the thing and it has everything for me.
So as I'm saying, like, you know, all of these different distributions has like a purpose.
And it kind of depends on it kind of depends on what your purpose is, right?
Like what exactly you try to do.
All right.
That makes sense.
All right.
So I see.
So that's Anaconda.
The next one we have is Micro Python.
What's the purpose of this one?
So this one is for folks that are working with like microcontroller, you know, like those little boards.
And, you know, you get your little solder.
Yeah.
Internet of things.
Soldering iron.
Yeah.
Internet of things and IoT and that kind of hardware stuff.
IoT stuff and, you know, plugging in sensors and controllers and all these types of stuff.
But you need a very small version of Python because, again, those devices have very limited memory sets.
You know what I mean?
And, you know, very limited processing power.
Yeah.
So you want to be able to have something that's very lean and able to run in like those types of architecture.
So Micro Python is a great way to do that.
And it's a great way to do that.
And it's a great way to do that.
And it's a great way to do that.
And it's a great way to do that.
Yeah.
Yeah.
Yeah.
Yeah.
Micro Python is a great option for doing some of that type of stuff, too.
Okay.
Cool.
Cool.
All right.
Next up, we have Iron Python.
Iron Python.
So this one and the next one, the next two are going to be really interesting because so Iron Python is like Python for .NET developers.
Right.
And some folks might be like, well, why do I want to do that?
Yeah.
And then, well, I mean, for a lot of folks, there's a couple of reasons.
One, you might want to have like some type of interoperability.
When I talk about interop, I might have like a thing.
Yeah.
Like a Python library that I wrote that I want to use in my .NET application or .NET DLL that I want to use in my Python application.
Okay.
Or I've seen folks that have done inline scripting that would allow me to like write some, you know, small little scripts, maybe in Python, interpret them and run them on the fly in my .NET application.
So there's a lot of different use cases for why folks might want to do this.
You know, also, too, because it's running, this version of Python is going to be running on the .NET CLR.
So now the way that we think about it is, you know, I'm going to run this version of Python.
Now, the way that we think about threading and, you know, multiprocessing and some of those types of things are a little bit different than it would with some of the traditional, you know, Python idioms.
I got you.
Now, this one, if we look, this one is up to Python 3.4.
Now, the current version of Python, I believe, is like 3.12 at the time that we're recording this right now.
Yeah.
So as you can probably see, there is some gaps between like the current version of, you know, the default installation of Python and where it's running.
But again, if you're not really needing those, you know, cutting edge features, then, you know, this should be fine.
And this would be really great.
Again, if you're trying to like just interrupt or integrate into an existing application.
Okay.
And you mentioned this other one, Jython is essentially similar to, it serves the same purpose as IronPython, but for Java.
Yeah.
Python and Java.
Okay.
So now when we talk about Java, we talk about like the JDM.
Right.
The Java Virtual Machine.
Right.
And for folks that are familiar with Java, maybe you are, maybe you might not be, the JDM runs lots of different languages on top of it.
So Kotlin is an example that runs on the JDM.
Scala runs on the JDM.
Groovy, which is a different scripting language, runs on the JDM.
And now we also have Jython.
So that means that, again, we can pull in Java jars and packages and all these types of stuff and write Python code to run with those things too.
So again, if you have any of those types of, it's a great way to run.
If you don't have any of those type of interrupt scenarios, then it's a great option.
That makes sense.
And I'm talking about the version gap a little bit again.
Here, this one, the current release only supports Python 2 right now, but they are working towards supporting Python 3, at least at the time of recording this.
Right.
Something else to keep in mind.
What's great about these things too is that, you know, both this and IronPython, they are open source.
So if you're interested in getting into language interrupt and writing compilers and parsers and all these types of things.
This might be a good option for you to like contribute back to some of these projects to help make that community better.
Yeah, for sure.
All right.
Last but not least.
Python.org.
It's just Python.
Just Python.
It's just Python.
This is what I was expecting you to tell me about.
And, you know, maybe we should have started with this one, but this, it's just Python, right?
This is the default distribution of Python.
You know, it's, you know, hosted on Python.org.
It's written in C.
You know, runs on tons of different archives.
It runs on tons of different architectures.
And for most folks, when you install Python, you know, this is generally the version that, you know, most folks are going to be able to use.
So if you're interested in like diving into this one and seeing how to install it, you can go ahead and head over to downloads.
Hit that little download button in the menu bar.
And you could pull it down for your system, right?
It runs on Windows, Mac, Linux, and tons of other architectures as well.
Awesome.
All right.
So this is all about getting different versions of Python.
For the purposes of this course, we're going to be using throughout 3.11.3, I think, to be very specific.
But if you need help getting you, the viewer, need help getting installed, Python installed on your system, you can look no further than right on this platform where you're watching this course.
If you go to talkpython.fm/installing-python, you'll be able to step through this guide, this article here that will walk you through doing that to make sure you get it installed properly on your operating system.
operating system and verify that it is ready and available for you to start writing python exactly and like i said before like this one's gonna help you get the default or the the python version distribution written in c the one that we showed at python.org on your machine if you're interested in getting anathonda or iron python or any of those other ones make sure you go to those websites and it'll let you know like the instructions and the steps you need to take to handle those awesome well now that we know about the different types of python distributions that are there which one we're going to be using in this course and how to get it installed next in the next video we're going to talk about getting vs code set up on a machine very briefly giving you an idea what to expect in doing that so let's head on over into that what do you say cecil let's
|
|
show
|
4:48 |
So Brian, we just went through how to install different versions of Python, different distributions of Python, right?
Like try to understand what version we're going to use in this particular course.
But I kind of feel like we should tell people how to get Visual Studio Code installed too.
That might be an important thing for us to do.
So could you help us out with that?
It's just a little important and I'd be happy to help you out with that.
So to get folks started, if you don't already have Visual Studio Code installed at this module here, this video is going to help you out.
You want to go to code.visualstudio.com, which is what we're looking at right now.
And here you're going to be presented with a lot of information.
But one thing I want to call out that may not be exactly apparent because right now it says download for Windows.
It's picking up that I am running on a Windows machine right now as we're recording this.
But VS Code is available for Windows.
macOS and different distributions of Linux.
Your mileage may vary on there, but you get the idea.
It's meant to be cross-platform supported on all major operating systems and Linux distribution.
So keep that in mind if you're looking to install it.
You don't need to worry about jumping to a different operating system for the purposes of this course.
You use what you want to use.
Get Visual Studio Code.
Now, when you come here, you can click the big blue button to download it for your operating system that you're going to be running on.
But you don't need to worry about jumping to a different operating system for the purposes of this course.
You can click the big blue button to download it for your operating system that you're going to be running on.
But that's going to give you what's called the stable build, which is typically the blue icon that you see when you're installing it.
But if you wanted to, you could potentially open up the door to...
You want to get a bit adventurous.
Cecil, are you feeling adventurous, man?
I mean, I live on the edge.
So what you could do then, since that's the case, is you can actually install the Insiders version, which would be...
The way you know the difference between them is it has a green icon.
And what the Insiders version is, is you're getting more frequent updates ahead of time before the stable.
So you can get more frequent updates ahead of time before the stable release.
Now, why you might want to do that?
Well, I, like Cecil, like to live on the edge and get the latest and greatest features that are coming out in VS Code and be able to test them out and try them in my projects.
But I also have found that running both...
You can run both side by side, by the way.
But running in Insiders, I rarely ever ran into issues where I would have to stop using that and actually switch over the stable.
Like maybe two times that's happened in nearly a decade or however long I've been using VS Code.
I want to say it's almost...
How old is VS Code?
I don't know, but it's pretty old, okay, at this point.
And over those many years that I've been using it from the start, two times have I ever really had to shut down Insiders and then just reopen the project in the stable build.
So try out either one, whichever one you like.
If you want to see the difference between them, you look at the icon here.
It's green.
Okay.
That signifies that it's Insiders to me, the Insiders version where I'm going to get weekly or daily even updates in the bottom right hand gear.
Or for me, it's the bottom right hand gear.
Okay.
So that's the bottom right hand gear.
But for others, it might be on the left hand side.
And then if I'm in the Insider or standard stable version, it'll be looking like this with the blue icon.
So just calling that out if you're interested in checking out different flavors of Visual Studio Code.
But you click on that, it gives you the corresponding executable for Windows or DMB or DMG rather for macOS and so forth.
And you just step through the little installation process and you'll be off and running with Visual Studio Code on your operating system.
So the only one thing I want to point out with that is, and like Brian said, we like to live on the edge, right?
And so we often would have both the, I guess, the stable version and the Insiders version on our systems.
Sometimes when your Insiders version updates and, you know, the folks that build the plugins and the folks that build the editor aren't the same folks.
And so sometimes, you know, updating to like the bleeding edge version might make some of your VS Code extensions freak out a little bit.
I'm just like, it's okay.
Nothing bad is going to happen.
It's going to happen on your computer or your machine.
But you can expect that, again, when you're living on the edge, sometimes things are going to happen, right?
And so that's usually why I like to have both.
I have like the Insiders version and the stable version.
So I can kind of see how the worlds are different, right?
And look at the updates, but also see how like my extensions react to that as well.
Yeah.
It's great you bring that up because there's actually a third flavor of Visual Studio Code, if you will, that you can potentially use.
It's outside the scope of this course, but there is a web.
So if you're using something like GitHub Codespaces or some type of cloud development environment, it can leverage most of, if not all of Visual Studio Code, just like the one that you would install on your operating system, but in your browser.
And you get a lot of the conveniences of that without having to pollute your local, you know, machine that you're working on necessarily.
So you can check that out.
That's also there under VS Code.dev if you want to go learn more about that and find out ways you can leverage Visual Studio Code.
|
|
show
|
0:30 |
All right, folks.
Well, hopefully after watching this chapter, you've learned everything you need to learn about getting set up with Visual Studio Code, different Python distributions, and having that set up on your machine.
If you have any questions at all, always feel free to message either Brian and I.
You can reach out to us via the Talk Python folks, and they'll make sure they send any questions and queries our way.
But now, we're going to move on to the next chapter of this course, and we're going to learn a little bit more about how we could customize and get set up using Visual Studio Code.
|
|
|
1:08:51 |
|
show
|
2:14 |
Hey there and welcome to this module on exploring the editor with Visual Studio Code and I want to talk you through what we're going to cover in the module so you have an idea of what to expect.
First of all, we're going to take a look at and get a general overview of the user interface so that we can get acquainted with it and how it works and where things are within that space.
After that, we're going to take a look at the activity and secondary sidebars.
These are the bars that come up on either the left hand side or the right hand side, depending on your preferences and configuration.
You can hide and show those throughout your developer workflow.
After that, we're going to take a look at the command panel, which is your gateway to doing anything and everything all from the keyboard to jump around between different actions and customizations right within Visual Studio Code itself.
We'll take a look and understand the Explorer and workspaces, the Explorer being the area where you can open up folders and files and.
Have visually see what you're working on and workspaces allowing you to logically gather things together or aggregate different projects from different folders together into Visual Studio Code.
Once we're done with that, we're going to talk about the status bar, which is something that gives you active information about the current state of things when you're working on a project.
So things like the file you have open the current cursor position and line that it's on stuff like that within the status bar.
Then we'll talk about the terminal, which is going to allow you to run commands or navigate around different directories, things that you normally would do in an external terminal.
But this one is built into Visual Studio Code.
After that, we'll talk about settings.
We got to be able to customize our editor to our liking.
We got to tweak things, make things visible that we want visible, hide things that we don't want visible and stuff like that.
Shortcuts and whatnot that you'd like to be able to do.
Speaking of, we'll talk about common shortcuts that you can use to keep your workflow efficient and productive.
And then we'll talk about the default settings.
So if you're using a default setting, you can use that.
So that you can jump through your projects, get your things done as fast as possible.
After that, Cecil and I are going to talk with you about extensions, the themes that we recommend that you can check out.
That'll help you and enhance your overall experience developing within Visual Studio Code.
And then that will close things out for this module on exploring the editor Visual Studio Code.
|
|
show
|
5:23 |
Visual Studio Code has a user-friendly interface that consists of several components designed to enhance your coding experience.
Understanding these UI components will allow you to navigate, edit, and manage your code and projects effectively while using Visual Studio Code.
The menu bar is located at the top of the Visual Studio Code window, right up here.
That's where we see File, Edit, Selection, View, Terminal, Help, and all those options there.
It provides access to different menus such as File, Edit, View, Go, Debug, Terminal, and Help.
Each menu contains a set of commands and options that you can use to perform various actions within Visual Studio Code.
So if you need to open up a new file, open up a folder, save things, share, close things, all that kind of stuff is happening from the File menu along with some of the other menu options that you have here.
Next up is the Activity Bar.
This is positioned...
along the side of the window and it's typically, by default, on the left-hand side.
It consists of icons representing different functionalities and aspects of Visual Studio Code.
Common icons in this bar include the Explorer view, which we have open right here, Source Control, which is this one right here, the Run and Debug view, Extensions, and Search.
Each icon corresponds to a specific view or feature that you can utilize within your development workflow.
After that, we have the Editor Group.
That's where you see the current file that I have open right now, api.py.
The Editor Group is the main area of the window where you open and edit code files.
Visual Studio Code supports multiple Editor Groups, allowing you to work with multiple files simultaneously.
Each Editor Group can contain one or more tabs representing individual files, as you see here.
api.py is an individual file represented under its current tab here, right there.
You can switch between these two tabs to see which one is the most important.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
You can also change the file type to be the one that you want to use.
|
|
show
|
6:18 |
One of the most powerful components of Visual Studio Code is what is called the command palette.
It allows you to access and execute various commands within Visual Studio Code.
It's a versatile feature that provides a quick and efficient way to execute commands, which range from basic editor operations to advanced features and even extensions.
You can open up the command palette using a keyboard shortcut, such as Ctrl-Shift-P on Windows and Linux or Command-Shift-P on Mac.
Another way you can open up the command palette is by going to the View menu and clicking on Command Palette.
Once the command palette is open, you can start typing to search for a specific command or feature that you want to perform.
As you type, the command palette will dynamically update and filter those results, displaying any relevant commands or suggestions to you.
So, what can we do here?
In order to execute a command from the command palette, you just select it from the filtered list and press Enter.
Or you can click on it if you'd like.
So, as an example, let's say we want to close the current file that we have open.
Say Close Editor.
And what's nice about this is it also shows you any keyboard shortcuts that are associated with that command so that you can, over time, learn to memorize that particular keyboard shortcut instead of having to go through the command palette for that particular action.
In this case, I'll hit Enter or I'll click on that one.
And it did indeed close the API.
If I bring up the command palette again, now I want to open a file.
I hit Enter on that file.
And I can choose API.py.
What I find to be really great about the command palette is that even if I don't know exactly what the command is or action that I want to perform, if I start typing out what I'm looking for, it'll filter those results and give me a better idea of what might be possible.
So, in this case, I want to edit settings for the command palette.
How can I find those?
Well, I'll bring up the command palette, Control-Shift-P, and I search for settings.
And then I can see all the different options that have that keyword in it.
And in particular, I realize, oh, I want to open the settings UI.
Now, once in here, this is what we're talking about.
We want to update some of the command palette settings.
So, I'm going to search for command palette.
And here we can see, let's close the bottom panel there.
We can see the different options.
So, we can see the different options that are related to the command palette in VS Code settings.
So, we showed those two examples.
And a few more examples of using the command palette that you might want to leverage it for is maybe changing the editor layout for you.
So, in this case, you see I have a tab open for settings and another tab open in the editor view for the API.py file.
What if we wanted to split those?
Well, Control-Shift-P, and I look for split editor.
And hit enter on that.
And now we can see it did indeed.
Split the editor.
We have an editor group on the right-hand side with the settings view open.
And then I can close.
It looks like it duplicated in this case.
And then I have the API.py on another side.
Another option would be, which I personally prefer, is toggling which side of Visual Studio Code the activity bar shows up on.
So, I'm going to search for activity bar.
And you can see, we can focus on it or toggle the visibility of it.
We can hide it completely.
If I hit enter again, you'll notice when you bring up the command palette, it shows your recent command that you executed in that history.
So, you can quickly jump between them if you need to go back and do something or revert something that you did.
Toggle the sidebar, primary sidebar position.
So, right now, that's on the left-hand side.
And as I was mentioning before, my personal preference is to have it on the right-hand side.
Now that you can see it's over there.
The reason, really quick, sidebar on this.
No pun intended.
Why I want that on the right-hand side versus the left-hand side is I personally often move around my UI components or hide and show UI components.
So, in this case, I like to hide and show this sidebar view so that I get more real estate to see my code.
So, you can click on the currently active view to hide and show that.
Or you can press control B or command B if you're on macOS.
And that will toggle it on and off.
In which case, you can hide and show it.
In which case, you notice the behavior now.
It's not as jarring on my eyes when I'm hiding and showing that versus when the sidebar is on the left-hand side.
So, I'm going to press control B a few times and you'll see the code jumps.
The positioning of where the code starts for me to read jumps quite a bit.
And since I do that a lot in my personal workflow, I prefer it on the right-hand side.
And maybe you will, too.
One last really cool example of the power of the command palette that you can use it for.
Is checking out extensions, too.
So, control shift P to bring it back up.
I'm going to search for extensions.
And I have some options here.
We can check for extension updates.
Disable some of them.
But I want to install, let's say, an extension like this.
And it brings me right to the extensions view.
Another thing you can search for is a lot of times people want to change the color theme of Visual Studio Code.
You can start customizing it to your liking and be more visually pleasing for you.
Well, I can search for theme.
Click on this preferences color theme.
And all within the command palette is when I'm doing this.
And I can toggle through all the different options that are installed in my instance of Visual Studio Code.
Some of these are built in.
Some are ones that you can install separately.
Which also can happen directly from the command palette.
You see this top option.
Sorry for the flashing there.
Browse additional color themes.
I hit enter on that.
And now it's searching the Visual Studio Code marketplace.
For all the color themes that are available out there.
So maybe I want to search for Night Owl is one that I really like by Sarah Drasner.
And here is the chance where I can actually see a live preview of that searching from the marketplace.
All within the context of Visual Studio Code and the command palette.
|
|
show
|
7:42 |
One of the main features and functionality that you will be using within Visual Studio Code is the Explorer view and what's called workspaces.
So right here on the left hand side, you can see from the activity bar, I clicked on the Explorer view and then that loads up in the primary view.
Now, here you have some options.
There's icons at the top that allow you to perform actions within the Explorer view and within the current context of the root folder of your project.
So I can create a new file within it.
I can say I want it to be like test.py if I wanted to, to create something new there.
You can see it opens up automatically as soon as I create that in the editor view.
Some other options that we have in these icons within the Explorer view is to create a new folder or maybe behind the scenes separately in your Windows Explorer or in Finder on macOS.
You add another file within here that doesn't show up for some reason in Visual Studio Code.
You can say, hey, I want to reload.
Refresh.
The Explorer view.
I'm clicking on it right now, but nothing's changing.
You can see that.
And let's say things get a little unwieldy and I have too many parent child folders opened up and it's become too unwieldy to try and manually close all of them.
Well, there's a collapse all folders in the Explorer view option like that.
So that's the Explorer view.
In a nutshell, you can also see at the bottom, there's a couple of little sashes too.
So here's the main view in the Explorer view, the current root folder that I have open.
But in addition to that, there's the outline.
Which when you have an actual file opened up, Visual Studio Code will recognize the type of file it is.
In this case, a Python file and give you a general outline of the structure of that file.
In this case, we just have the API, which is a very simple file.
So it's not showing a lot.
But as you get a larger code file open, this will help you navigate it a little bit more easily.
And last but not least, and this is something that has saved me at least once, if not twice.
Now, where I've accidentally deleted something in a file that I forgot about and later needed to come back and restore it.
Visual Studio Code will keep like a shadow copy of your files for you.
And you can restore back to those times or the state of that file at that time, essentially.
Just really saved my butt, to be honest.
You know, excuse my language there, but it has.
For instance, I had an ENV file, environment variables file, and that I deleted the API key that I needed and I couldn't find it or generate a new one.
And that helped me restore back the API key value that I wanted.
All right, so that's the Explorer view.
Now, next up, as that kind of goes hand in hand with the Explorer view is a concept called workspaces.
This is something that took me a little while to get my head around.
But once, hopefully the way I explain it to you now, it'll be really quick and easy for you to understand.
Essentially, a workspace is a way that allows us to organize projects effectively.
Within Visual Studio Code.
So in this case, my project, I just have this one root folder, which is for my API, the podcast API.
But maybe I had a front end component to this overall project that's in a separate folder structure or a separate repo that I clone down to this machine.
And I want to be able to work on that project at the same time as my API project and jump around quickly.
And that's where workspaces come into play can act as even though they're not physically in the same folder structure.
They can be connected virtually within Visual Studio Code using workspaces.
The way workspaces are made available within Visual Studio Code is a number of ways.
Well, one, one of the most prominent ways is through the file Explorer menu or the file menu.
In here, you can see there's a couple of options related to that are related to workspaces.
I can open a workspace file from a file.
I can add a folder to the workspace.
I can save my current setup as a workspace.
Cause right now.
It's not technically a workspace because it's just the one folder that I opened up.
We can turn it into a workspace.
And last but not least, you can duplicate a workspace.
So maybe you have it configured a certain way that you like it, and you want to add a little bit more for a certain workflow that you have.
Maybe some settings specific to that workflow.
You can duplicate this workspace as like the template to work off of and configure it a bit further to your needs.
But getting a little bit ahead of ourselves there.
Let's talk about how we can create a workspace.
So what I'm going to do is with the current project that I have open, I'm going to create a workspace.
So I'm going to say save as workspace.
I can give it a name and decide what, where I want to save it.
In this case, I'll just put it directly in the root project where you save this workspace file doesn't really matter as long as you know where it is and where you can get to it because it acts as a manifest for you to describe where other projects that need Visual Studio Code needs to reference and pull into it.
So I'm going to put it in here and I'm going to click OK.
You'll notice Visual Studio Code reloads now and this top area or sash, if you will, within the Explorer view now has that workspace keyword in there instead of just the name of the folder that I had open, which was base.
You'll also notice that now base that folder is a collapsible region within the Explorer view.
So may not really look too different, but this next step is what's going to really show the.
Power of workspaces for you.
So in this case, talking about the example I was going through before where I have this API project, maybe I have my UI front end project in a separate folder.
Well, I can right click in the Explorer view and I want to be able to see it within here.
I can say, hey, I want to add that folder to this workspace by click on that.
And let's just say for demonstration purposes, this is the folder that has.
My UI in it and I click OK, and now I can navigate both of those.
Within the same instance of Visual Studio Code.
Again, this is like a virtual directory that references multiple other directories that are not necessarily connected.
So let's say I made a mistake, though, this as you can see, this is just a essentially an empty folder that I added in here and I clicked on the wrong one.
I need to remove this from my workspace.
I right click on that particular dropdown and say remove folder from the workspace.
Now we're back to just that base folder that we needed from before.
So one of the unique things about a.
Workspace is you can configure your Visual Studio Code settings to be saved to that workspace so that whenever you load up this project again or the workspace again, Visual Studio Code will apply those setting changes separate from when you open up a different workspace or a different project within Visual Studio Code.
Demonstrate that will one let's take a look at what the code space file code workspace file looks like.
It's essentially a JSON file.
It describes the folders that should be included as part of that workspace and any settings associated to it right now.
So you can see it's just empty.
But if I go in and let's say maybe for this project, I want my font to be different size than what I have by default font size.
I'll search for that in my settings view right now.
It's set to 18.
I'll click on workspace in here.
And.
Let's change that to 22.
And I hit save.
And now you'll see that one, the font size changed and it saved it into the workspace.
Folder or workspace project file.
All right, and that essentially summarizes workspaces that can be a powerful tool for you in those larger, more complex projects that you might be working on within Visual Studio Code.
|
|
show
|
3:07 |
Let's explore the status bar a bit further to understand its purpose and functionality and how it is commonly used.
The status bar is a fundamental component of the Visual Studio Code user interface or UI.
It's located at the bottom of the window as we mentioned earlier and provides essential information and indicators to enhance your coding experience.
The status bar consists of various key components that display relevant information and facilitate interaction.
One of them being language mode.
This indicates the programming language or file type of the currently active file.
In this case, I have a Python file opened up and it correctly detected that right here as you can see the language mode that I'm currently in.
If I click on that, you can see that it auto detected the language mode, but I could manually change it to something else in case it did so incorrectly for some reason.
The status bar also shows line and column numbers.
This.
Displays the current cursor position in terms of the line and column numbers in the active file.
So if you notice right here, LN for line number 10 and COL column number 16.
It goes directly to that.
If I want to go to another one, I can click on this and I can say maybe line number 20 that's available or 15 in this case.
It moves the cursor to those positions for me.
But as you move it around, maybe with your arrow keys on your keyboard, you'll see those numbers changing.
Such as the line number and the column that the cursor is actively at.
In addition to line number and column numbers that are shown in the status bar, you can also see the indentation that's being used in the active editor.
This shows the indentation settings being used in that active file.
In this case, we're using four spaces.
But I can change that to indent using tabs.
I can change the tab size and other options within that action.
Last but not least is Git integration.
That can potentially be shown in the bottom of the status bar.
In this case, I'm not using a Git source controlled project.
But if you were and had that open in Visual Studio Code, it would be shown in the status bar.
Okay, so that's a high level overview of the status bar.
One other thing I'd like to call out, at least, as is the case with most of Visual Studio Code, we can customize the status bar to our liking a little bit.
If you right click on the status bar, you'll get this menu with a bunch of different names of things and checkboxes.
Next.
So, as we were talking about before, we can see the editor indentation or the editor end of line or the encoding.
All these options that are currently being displayed in the status bar, we can choose whether they are actually shown or not.
So, maybe I don't want notifications to be available, which is that bell icon in the bottom right hand corner.
Right now, I have no notifications.
That's where they would show up if you'd like to see them and read about them further.
But maybe I don't want to see those or I don't want to see the feedback icon capability anymore.
I can click on that and you'll notice that the status bar has now been customized to my liking.
And you can do so how you choose that fits you best.
And that is the status bar.
|
|
show
|
3:33 |
One of the key tools when it comes to your overall development workflow when working on a project is your terminal or command line.
This acts as a way for you to run your projects, build them, compile them, test them, all kinds of different actions you might take within the project that you're working on.
And what's nice is Visual Studio Code comes with an integrated terminal built into it.
The way you can access that is from a number of ways, but one being the view menu and going down to terminal.
Or as you see in the menu here, the keyboard shortcut related to that is control back tick.
That's for Windows and Linux or command back tick if you're on macOS.
Click on that and we'll notice that the terminal view within that bottom panel is now at the forefront.
I'm going to make it a little bit bigger really quick.
And right off the bat, you might notice that my terminal is likely looking different than yours.
And that is because I have on my host operating system Windows here or WP.
WSL, Windows Subsystem for Linux.
I've configured my shell and the way that shell theming is within that space.
So that's how you would go about doing that yourself.
But what's great here is Visual Studio Code will just reflect that.
One way you need it to do that or to get that set up is by indicating to Visual Studio Code what should be your shell type.
And that's where this little menu by the plus icon here, if you click that down arrow, you can see default is ZSH, which is the default default.
Which is Z shell.
That's my default one.
But I also have access on this operating system to bash shell, JavaScript debug terminal, T mux, and then a couple other options related or related to terminal workflows.
Maybe I want to split the terminal or configure terminal settings, set, select the default profile, which you can see here, which is the S H and then run tasks and configure tests.
That'll be covered later.
If you have set up your own shell on your operating system, just be sure to come over here.
Click that little menu.
And tell Visual Studio Code what the default one is.
So in this case it was bash for me before, but now I switched it over to that Z shell, which I like to use personally.
And that's why mine looks a little bit different here.
You can get into the weeds on tweaking and configuring your shell, but that is outside the scope of this course and Visual Studio Code, to be honest.
But to dive deeper into the behavior of how the terminal can be used within Visual Studio Code, you can see I have two separate instances that are open.
These act as.
Almost like tabs, just like how you have editor tabs for different files you might have open.
You can have terminal tabs here.
You can split these.
Horizontally.
Don't necessarily be two separate tabs that you would click into.
You can have both of them visible at the same time.
Let's say you accidentally opened up in that split view and you don't want that terminal anymore.
You can click the little trash icon to remove it.
You can move terminal into the editor area, which is nice.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
So you get a little bit more real estate when you're working with it.
And then just close it when you're done.
You can open up the other different shell types that you want.
So if I wanted to create a new one, I click bash.
Or.
Tmux.
Goes ahead and does that.
I can clear the terminal from here.
These are all the different terminal options, but essentially everything that you're used to doing in a separate app potentially on your operating system, you can do.
You can do this directly within Visual Studio Code via the terminal view in the bottom panel.
|
|
show
|
5:52 |
All right, now it's time to get into settings for Visual Studio Code.
VS Code settings allow us to tailor our coding environment the way we would like it.
And that can be specific to what projects you have open or general development purposes.
But there's a few ways to get access to the Visual Studio Code settings.
First of all, one of the more common ways if you're more of a visual person through the UI is by going to File, Preferences, and then Settings.
But that takes a little bit, a few clicks.
You've got to use your mouse.
If you want to use your keyboard and have quicker access to the settings, you can press, as you saw there, while I'm on Windows or on Linux, you can press Control, comma, which I just pressed to bring this up.
You get the settings view.
Or if you're on macOS, it would be Command, comma.
And last but not least, one of the other ways that you can do it is through the Command Palette.
So to bring the Command Palette up, you press Control-Shift-P on Windows and Linux.
On MacOS.
On MacOS, it's going to be Command-Shift-P.
And then in here, I can just type in Settings, or if you wanted to, you could say Preferences as well.
Right?
And Open Settings UI.
So that's the one you would want.
And it brings us right back to that Settings UI there.
So use whichever one you prefer.
I personally feel that it's more efficient to just press Control, comma, for Windows and Linux, and Command, comma, for macOS.
Now, as we're looking at the Settings UI here, you'll notice...
at the top here, there's a few different tabs.
Now, you may not see all the same ones that I have, but in particular, you should see a User and a Workspace at least.
What that does is it encapsulates settings based on the different environments you might be working within.
So when it comes to User, that's your user level settings.
That's more globally applied across Visual Studio Code.
And then Workspace is for the current workspace you're using and have open within Visual Studio Code.
So in this case, this base Python project.
So I can have settings tailored to that environment versus settings at a more global level at the user environment.
You'll also may notice that I have this other one.
It's for remote development environment.
So I'm working within Windows Subsystem for Linux.
So if you are doing something like that on Windows, you might have the option, this option here to configure settings based on that environment.
Or if you're working within a dev container, for instance, which is outside the scope of this course, you'll be able to apply settings based on that as well.
But the remainder of this, we're going to focus on user level or workspace level settings, and you can ignore that remote one.
So within settings, you can actually search for whatever type of setting you might want.
I know right off the bat, you can see at the front here that there's font sizes.
But if I couldn't find that or I didn't know what it was I was looking for, you can start typing in the search box here to look for what you're wanting.
Maybe I want to change the font, right?
And I want to find all settings based on font.
I just type that into the search box and I could see I get 44 different settings, related to font, font size, font family, and so forth.
It's very, very efficient, very helpful to have that search box.
It's improved quite a bit over the years since VS Code has been available.
And I use that quite often, even if I don't know the exact name of the setting that I want to change, to find what it is that I need, and it's super helpful.
So that's how you navigate settings in Visual Studio Code.
Again, you can encapsulate them at the user level, workspace level.
But one other thing I want to talk about with this is you can actually sync these settings.
So if you work on more than one machine, so for instance, I work on a macOS machine for a laptop, but when I'm on a desktop, I'm on Windows, I can sync these settings across instances of Visual Studio Code, across operating systems as well, and machines.
The way you can do that is by going to the gear icon in the bottom of the activity bar, clicking on that, and you can see I have settings sync as on.
I'm going to turn it off really quick to demonstrate what that flow is like, or I can configure it to all the different options that you have related to settings sync.
What ends up happening is you sign into either a GitHub account or a Microsoft account.
This is what the option will look like for you if you've never set it up before, backup and sync settings.
You choose which settings you want to and UI state and extensions that you want to include as part of this.
We'll get into profiles in just a moment.
I generally choose all and then you click on sign in and that will take you through the sign in flow with options to sign in with GitHub, which I'm already signed into my Clarkio GitHub account.
Or other Microsoft based accounts.
And what that will do is store your settings in a secure manner in the cloud based on whichever one you signed into.
And that way when you sign into a new machine in Visual Studio Code with that same account, your settings will be synced over along with all those other capabilities that are incorporated into your account like extensions and profiles and stuff like that.
Okay, I'm signed back into my settings sync account.
Now the last thing I want to touch upon this when it comes to settings because I think it's related and it's really nice and I'm using it actually for the purposes of this course.
You can create profiles and those profiles will be a further encapsulation of your settings.
So in this case, I have a profile that's Python dev recording, but I have other ones for when I'm presenting or my just default one or VS Code default.
You can create all kinds of different profiles.
You can edit the profile.
You can delete profiles export.
And import.
We can use that.
So if you want to share with a colleague like your Python, the perfect Python settings and environment within Visual Studio Code, you can export that profile and share it with colleagues and friends that want to use the same approach.
Same environment that you're using for developing in your Python projects.
And that folks concludes everything at a high level.
What you need to know to get familiar with settings in Visual Studio Code.
|
|
show
|
17:09 |
All right, brace yourselves for this video because we are going to take a look at keyboard shortcuts in Visual Studio Code.
And I say brace yourselves because this is something that I'm personally passionate about in the sense of I want to be efficient and keep my hands on the keyboard as much as possible without having to touch the mouse or do anything else off of the keyboard.
Now, while I say that, I'm also, I don't know every keyboard shortcut possible.
I do know a lot of keyboard shortcuts in Visual Studio Code, but I don't know all of them or haven't used them all efficiently.
But the idea is you'll be able to learn them on your own.
And I'm going to give you a highlight of some of my favorite ones that I think you'll find useful to help you in using Visual Studio Code for writing your Python projects.
Now, to start us off, though, let's first talk about how to learn shortcuts.
Often the way that I come across new keyboard shortcuts is by through the visual indications that VS Code offers to you.
So if you open up any menu, you'll notice to add a new text file.
There's a keyboard shortcut associated.
With it, that is displayed in that action.
So control and on this in this case, if you're on Mac, it'll be command and right and so forth.
Some of the other ones, new file, new window.
This is a great way to get acquainted with some of the common things that you're doing that are you're like manually doing.
But with your mouse, you can find the keyboard shortcut associated with that action in the menu of items that are there.
Or if you hover over certain things.
So let's say I wanted to instead of showing the Explorer view, which I have available right now.
I can see that that is associated with the keyboard shortcut of control shift E or run and debug control shift D.
So that's how I go about learning new keyboard shortcuts.
And it's a nice little quality of life improvement that VS Code has had for quite some time now so that you can get more acquainted with new keyboard shortcuts and start incorporating it into your workflow.
That's one way you can learn about it through the UI.
Another way I like to do it, and this is probably the number one keyboard shortcut.
If there's one keyboard shortcut you remember from.
This course in this video, it's control shift P or command shift P.
This opens up that command palette, which I believe we discussed previously and got you a little bit acquainted with it.
But that's the gateway to everything in Visual Studio code along with the keyboard shortcuts that are associated with it.
So if I wanted to create a new file.
Let's do a new file.
I can see that create new file has a keyboard shortcut associated with that control.
Alt windows plus N.
If I wanted to open something like open the keyboard shortcuts in particular, there's a keyboard shortcut for that control K and then control S on Windows and Linux.
So I'm going to hit enter to bring that up because this is the third way that you can learn about new keyboard shortcuts.
You can search for certain actions or commands that you would like and find the key binding that's associated with that in this table.
There's even conditions and you can associate them with certain.
Operating systems as well if you'd like.
So this is the keyboard shortcuts view that gives you the overview of every possible keyboard shortcut and key binding that is saved and associated with Visual Studio code or any custom ones that you create.
So that's how you access the shortcuts view.
Now if you want to create, let's say a custom keyboard shortcut, you can either override an existing one.
So like except chat input or except inline completion, I can click edit and type in whatever I want for the keyboard shortcut.
So maybe.
Control.
I don't know.
L will just make it up for now.
It lets you know, by the way, that there are three existing commands that have this key binding that you will probably interfere with.
So just heads up on that, but you can hit enter, press the enter key to then save that key binding to that command.
I'm going to hit escape to undo that twice because I don't want to override this existing one.
So that's kind of a quick overview of how you can get acquainted with keyboard shortcuts.
Again, it's through visual indications, the command palette.
Control shift P or in the keyboard shortcuts view directly.
Now one thing I'm going to do to help with the rest of this course, I'm going to enable what's called screencast mode.
Developer toggle screencast mode.
And what this is going to do is it's now going to visually display whatever key bindings or keyboard shortcuts I'm using or actions that are happening.
So you can get that available to you and I'll do my best and Cecil as well to keep this on throughout the rest of the course.
You'll also notice every time I click, it'll highlight in red as well.
So if you're somebody that wants to create a video or tutorials or anything like that, or you're displaying doing a presentation to your colleagues, it might be a setting you might want to turn on to help improve the experience of those folks that are viewing that.
All right, so let's jump into some of my commonly used keyboard shortcuts that I find useful.
First up, we talked about control shift P, right?
That brings up the command palette and then I can search for any other command that I want.
If I want to add one like a custom one.
So this one right here, like open settings UI doesn't have any.
Keyboard shortcut associated with it.
I can click edit on it.
And then in this case I can go add and then put that one in there too.
So that's just a heads up on that one as well.
Another way to go about adding, instead of overriding keyboard shortcut, you can add a keyboard shortcut.
Another one I commonly use is once I have a file open that I want to edit like this one here, the API dot PI, I don't need to see the Explorer view or whatever it might be open.
Maybe I have run and debug open anything in the side panel.
If I want to minimize that I press control B.
And that toggles the visibility of the primary sidebar as you saw here.
Now really quick, this is a personal preference.
I don't really like this view being on the right hand side because of how common I use this keyboard shortcut and you see how visually jarring it is to keep my eyes on the code when I'm doing that.
So what I like to do is I like to turn, move the activity bar and this whole Explorer view sidebar rather to the right hand side.
And the way you can do that is bring up the command palette.
and it's toggle primary sidebar.
And you can see that it's in the right hand side.
So I'm going to go ahead and drag and drop this.
And you notice now it's on the right hand side.
And when I press control B now to hide that visibility of that, notice how it's less jarring.
I love that.
It's so much better.
Thank me later.
All right.
So that's control B.
Now, if I need to use the terminal to run any type of commands on my operating system or Python commands to run things, what have you, if you need to view the terminal, the way you do that is control back tick.
And you'll notice it popped open this terminal here.
And then I can start running whatever commands I want.
I need to do here, like clear the screen or whatnot.
Right.
Change directories, all that fun stuff.
If I want to hide that though, I just press it again.
Now, one other thing that I personally edit is the whole that's to bring up specifically the terminal view.
Then there's other ones for the debug console, maybe the output.
You can see I'm hovering over them or any problems that, VS Code is trying to alert me to about my project.
Remember that control back tick is specifically to bring you to the terminal and oftentimes this bottom panel.
I always.
Have the terminal tab visible in here, but I want to sometimes just hold like a quicker keyboard shortcut.
It's a little hard for me to like my dexterity in my hands to press control back tick every time.
Although I do use that sometimes.
So I added another keyboard shortcut control J to toggle the panel visibility.
Now, the reason I'm calling this out is if I have the debug console selected in here and I press control J to hide it and bring it back.
It's always whatever the last visible tab in the bottom panel.
Was open is what's going to show up in there.
So that's just something to note.
And the reason I did control J, it's one of those keyboard shortcuts.
It's not associated with anything else.
And I also added one because you can expand the terminal or this bottom panel to take up the full view, within Visual Studio Code.
If you normally, you would just click on this.
I added a keyboard shortcut instead of having to click on that.
I added control shift J.
Oh, it's not in this profile.
Actually, let's go at it real quick.
So if I want to add one, I know that this action or command is called.
Maximize panel by hovering over it.
So let's bring up the keyboard shortcuts, open keyboard shortcuts, and I'm going to search for, let's clear this from before.
I'm going to search for maximize panel.
I'm going to click plus control shift J hit enter.
It said one existing command use that.
Okay.
Well, I don't know what that other existing one was.
Let's try that again.
Really quick.
Out of curiosity.
You can click on that to see workbench action search toggle query details.
Yeah, I never really use that, so I don't know about that one.
So it's okay that I'm overwriting that for my purposes, maybe not for yours.
Okay.
So what does that do now that I added that well control J just hides and shows that bottom panel.
But when it's small like this, I can press control shift J to maximize it and then bring it back to its previous size.
The nice one to have that I like in a little, little added bonus tip in there for you.
Okay.
Well, we talked about control shift E to show the explorer view or control B just to hide it in general.
Kind of like control J.
What's what else do we have here?
If I need to search for something within a file, I press control F and that brings up the editor view file search.
So if I want to find, yeah, like shows router or API dot anywhere I'm using that I can then see that you can expand this to then replace it as well, which I believe the toggle replaces a there's a keyboard shortcut associated with that too.
I thought as well.
But I might be wrong on that.
You notice this one replace you hit enter.
If you wanted to replace API with like, I don't know, test that first one probably messed it up or no, I just typed it there.
So here's a keyboard shortcut.
I use that with any text editing type of software.
These are common keyboard shortcuts that maybe you already know, but just in case folks that don't know, like I made this mistake that I want to undo control Z will undo that.
And so now that API was changed back to, or from test to back to API rather.
Close that out.
All right.
So that is control fine.
But if I want to find like a certain string of text through my whole project that or workspace that I'm having, I currently have open, I can press control shift F and that brings up the broader search view, which now I can look for API in across the entire project anywhere.
That instance is not just in the currently open file API dot PI.
I'm looking in project Tomel PI project Tomel ring, read me and all that fun stuff there.
And then if I want to clear that, I can hide that control shift F to toggle it back off or no rather let's just do control B to hide that.
Okay.
Next up, speaking of editing, let's hide that for a second while we're editing some keyboard shortcuts more.
We talked about control Z.
What else can we do in here that I use often is there's a thing called multi-cursor actions in Visual Studio Code that you might not have in a regular old text editor, like notepad or something like that.
And that is possible by one.
There's a couple of different ways you can actually make that possible.
One common way that I do it is let's say I wanted to edit all of these three lines of API dot to something else.
I can press on Windows and Linux control alt down arrow down arrow and you'll notice there's two or two or three now blinking cursors.
And as I move it over, they're moving in in concert together there.
Right.
And now I can press like control shift right arrow to select that.
Okay.
And I can say maybe I want to call that test instead.
Right.
And you notice how it edits multiple lines at the same time, all in sync together.
So keep that in mind.
One other way to go about doing this.
If you have like a common function name or something like that, you can press F two over it and it's like edit enter to rename shift, enter to preview.
So if I call that test now and now I'm, you know, assigning tests to FastAPI, and then I can use the functions off of that as well.
I want to do that again.
That's another way to do it.
F two is to rename when you're renaming like a variable.
That's something that's specific to Visual Studio Code, but maybe you have like a string of text that is not necessarily a variable that you want to edit and you know, it's in multiple places, even in comments and stuff like that.
Well, in that case, you can highlight it and then you can, and you notice how VS Code kind of highlights the other ones that are even case insensitive throughout the rest of this file.
I can press control D to select each instance of that slowly.
So I wanted those three in just the comment there.
I want to change that to like test if I wanted to as well.
It did that in all cases, if I want to select all of them at once.
So I go like this and I can press control shift L and that selects all instances at once.
So control D to select them slowly, but surely for which one that you want.
In fact, you don't even need to have it selected.
You can just have the cursor right in front of it.
And then it'll slowly add.
Actually, if you want it, if you want it to be case insensitive, you should select it.
I'm just realizing this now making this, but if you don't do that, you're going to have to do it.
Then you can just press control D and step through each one that you want.
So maybe I didn't want that last one.
I go back up to the top here.
It allows me to slowly pick which ones I want there.
Okay.
All right.
What else we got control shift L we talked about control shift D.
What does that do?
That will bring up the debug view, right?
In case you're done editing, you're ready to run your Python code.
Now you can come in here and use the run and debug view within Visual Studio Code.
Let's hide that.
We got next, we got control slash.
This should be fairly common for most developers in Visual Studio Code.
If you want to comment out a line of code, you bring your cursor to that line and you press control forward slash.
And that will comment it out.
And you notice it uses the appropriate one for the language that we're working within.
In this case, Python.
If you want to undo that control Z again, if you want to redo something, we've been talking about control Z.
If you want to redo it, you can press control shift Z to redo that thing back and forth.
So if control Z to undo controls, Z, two, one, and then you're done.
You can press control shift Z to redo control shift Z to redo rather control space.
Something I want to tell you about.
That's I think specific to Visual Studio Code, maybe some other editors and IDs out there help with this.
But the interesting thing here is let's say API.
Now, typically when you press dot, it will bring up this what's called like IntelliCode IntelliSense that's available in Visual Studio Code to let you know of all the different properties and functions that are available for that particular item.
If that doesn't show up for you, you can manually trigger that by pressing the button.
You can also trigger that by pressing control space.
Sometimes that happens to me and that way I can start intentionally turning that visualization on and I can explore for which one I want.
You can start typing out what I might be looking for and that highlights it even more for me.
Highlights more specifically what might be relevant to what I'm looking for.
Getting towards the end of the shortcuts here and there's plenty here.
This is not a comprehensive list of shortcuts, but it's one of the common ones that I like to use.
F5.
I'm not going to press it right now.
But you can.
If you're using our project, they'll be there for you.
If you're using our project, they'll be there for you.
But if you're creating your own, you can get into creating a what's called a launch configuration in Python.
More on that in another video.
And last but not least, we talk about custom shortcuts.
I showed you one, my control J and control shift J.
One other one that I like to do is sometimes Visual Studio Code is a little bit more complicated.
I'm going to show you how to do that.
So I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
I'm going to go to my custom shortcuts.
for custom and common keyboard shortcuts in Visual Studio Code.
In the next video, we're going to start talking about extensions that you can use that are just common ones that me and Cecil like.
We're going to present those to you and talk a little bit more about them.
|
|
show
|
9:31 |
Hello, everyone.
Welcome into this next module.
We're going to be talking about extensions and themes for Visual Studio Code.
And this is part of VS Code that makes it customizable to your needs, the way you want your environment to be when you're developing so you can stay productive and efficient.
And I love this functionality and capability within VS Code.
How about you, Cecil?
Yeah, for sure.
I mean, VS Code works with so many different environments, different programming languages, different types of applications.
And so being able to customize it to do the thing you want it to do and, you know, work in the way that you want it to work, I think is huge.
So why don't we start off with me talking about one of my favorite extensions, which actually happens to be the REST client.
Now, this one's really important to me because I, you know, I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
Yeah.
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
So I'm not a UI developer.
I don't, you know, move bits on the screen and work with CSS and things like that.
I usually exist in the backend, right?
:
|
|
show
|
5:52 |
All right, so all this time, Cecil, we've been talking about more what I would describe as like functional extensions, but that's which is great.
It helps enhance your developer workflow and improve that type of thing, your productivity and efficiency in Visual Studio Code.
But let's get to some more of the visual style type of things that we would like to get into, which are theme extensions.
That's how you can change the color and styling of Visual Studio Code is through theme extensions.
So do you have one that you prefer that you use day in and day out?
You know, what's funny is I switch my themes all the time.
Oh, okay.
You know, I like dark themes.
I like light themes.
I'm not one of those folks that like dark themes all the way.
Yeah.
Like, you know, light themes are evil.
But, you know, depending on the time of day, you know, you switch your themes up, you know, it's kind of like, you know, switching clothes when you get up in the morning.
So one of my favorite themes that I use a lot is called Cobalt 2.
You know, regardless of whether I'm working late at night or during the day, you know what I mean?
I'm a big fan of like how prominent it makes the actual code look, right?
And I don't feel like the IDE is like getting in my way with distractions.
Like, as you can see here, like I'm looking and...
And you can see how my imports are very much like in my face, right?
And the methods we're calling are very much prominent in the code.
But I think that's important for me.
Yeah, I like that.
It's definitely one of the ones that I've used in the past.
And I'm similar.
Like, I tend to fluctuate in which themes I use because, you know, you like changing it up.
It feels different.
It feels fresh.
And Cobalt 2 is one of those ones that I put in my rotation as well.
And I tend to lean towards darker themes.
But in certain situations, like if I'm outside...
I'd rather have a lighter theme so I can read my screen a bit easier.
So I'm not going to show a light theme because I generally, like 90% of the time, I don't.
But this is Cobalt 2.
And if folks didn't catch, the quick way you can switch between themes is bringing up the Command Palette, Control Shift P on Windows and Linux, Command Shift P on Mac.
And you just type in color theme or just theme and you pick preferences color theme.
And then you can actually, for ones that you already have installed, you can cycle through them quickly.
But if you don't have it installed, you can just search for it.
Like, and it would help you in a way.
And it would help you install it from the marketplace type of thing.
In any case, the one that I want to talk about is Night Owl.
That's one of the ones...
There's a couple different variations of it, but look at that.
Isn't that beautiful?
It's just so pleasant on the eyes.
And I like this one because it's just...
The different syntactic styling it does for me stands out a bit better.
Typically, I'm switching between Python and JavaScript code and this tends to lend itself well in that regard to stand out for certain things.
For certain keywords in the languages there.
And there's the ability to be italicized or not.
I generally don't have it italicized.
I go like this.
But you'll notice that, like, depending on the font you're using with Visual Studio Code, which is yet another customization you can do, it will enable you to support italicized themes.
If your font supports italics, then your theme will pick up on that and enable it as well if the theme supports it.
So you need both to go hand in hand in that regard.
So, just to show the difference of that real quick.
Alright, what's your next theme, buddy?
Nice.
The next theme I have is the GitHub theme.
Ooh, which one though?
There's a bunch.
Well, so here's the thing.
When you install the GitHub theme package, it gives you a lot of different options, which I think is great.
So you get GitHub dark, GitHub light.
So it's a theme that has multiple themes, it has multiple variations.
Very similar to how you showed the...
Whoa!
It's so bright!
Oh.
It's very similar.
Very similar to how you showed the night hour theme, and there's different variations to night hour.
There's also different variations to the GitHub theme as well.
But one of the things I like about it is it's simplistic, it's minimal.
And that's one of the things that's important for me in a theme sometimes, right?
Like, I just want something simple.
I don't want too many things going on.
Because at the end of the day, my goal is to, like, focus on the code.
And like I said earlier, I like to switch back and forth.
So, you know, depending on how I'm feeling, I might be using the light theme.
But if I'm feeling like I'm going to be doing this later at night and I kind of want to dim things down a little bit, I'll switch over to the dark theme.
So I love having the option of, you know, still staying within, like, the same style, but now I'm just switching back and forth between, like, those different light and dark options.
Yeah.
No, that's cool.
I think I like this one the best.
It's the GitHub dark default.
You got to watch out for those other ones.
You got to be careful.
Those light themes will creep up on you.
High contrast is a pretty cool tool.
All right.
One last one before we close things out.
It is the Houston theme I want to talk about.
You can see it's very similar to the ones we were talking about earlier.
Again, another dark theme.
I like that it's a little bit more, like, if I need a little bit more highlighting in terms of the syntax of the code, it's a noticeable difference now.
And, again, you can even keep these preferences to different profiles within Visual Studio Code, which we talked about in a previous module or previous video.
And those profiles will isolate those changes.
So maybe you have a profile for doing Python development.
Maybe you have a profile for doing Node.js.
Maybe you have a profile for doing Node.js development and so forth.
You can have different themes and languages and setup in your Visual Studio Code.
You capture it all to fit your needs for that workflow that you're going through.
Yeah, I agree with you.
One of the things that I like to do is I'll have certain themes and extensions and just configurations set up for personal projects, for work projects.
Maybe just change the colors so I know, oh, okay, well, this one belongs to this and this one belongs to the other one.
So I have a visual indicator of, oh, okay, well, this belongs to a client.
This is for work, so this is, like, the serious one, right?
Like, I need to be careful what I do over here.
Yep.
Well, that about rounds it up, then, for everything that we want to talk about in the extensions and themes video.
Hope you all enjoyed it and got some good tips out of it.
|
|
show
|
2:10 |
Alright, that was fun and we hope you enjoyed that module as much as we had fun putting it together.
Let's quickly summarize what you learned so that you can reinforce that throughout this closing here.
So, first of all, we learned about the user interface of Visual Studio Code and got an interview to get acquainted with that and the different aspects of it that we should know about as first-time users of Visual Studio Code.
Then we talked about the activity and secondary sidebars.
These and what their functions and purposes are for Visual Studio Code and how we can use those to our advantage.
We talked about the command panel and how it is the gateway to all things and actions and settings and whatnot that are capabilities within Visual Studio Code that we can do right from the keyboard without even having to lift our hands over to the mouse.
We talked about the Explorer and how that allows us to view different files and folders and then workspaces to help us aggregate different folders, structures together as part of one project.
We took a look at the status bar and what information that provides to us.
While we're writing our code, while we're using Visual Studio Code and it gives us at a glance information for us.
We talked about the terminal and how that enables you to take terminal-based actions within Visual Studio Code without having to jump into a separate tool to handle that purpose.
We covered the settings in Visual Studio Code that allows you to customize it to your liking but also for whenever you add new things to it like extensions that have its own settings to it.
You go there to customize.
You can customize that and configure things the way you need.
We covered common shortcuts that you would use to help improve your efficiency and use of Visual Studio Code to hide and show different aspects of the UI or execute certain actions within the editor so that you can work productively on your Python projects in VS Code.
And last but not least, Cecil and I shared some of our favorite extensions, just a couple, and themes that we like to use to help enhance our overall development experience and make the editor a little bit of our own with the different themes, and options that we have there.
We hope you enjoyed it.
The next module, you're going to learn more about the experience of writing Python code and what you can do there within Visual Studio Code.
|
|
|
37:03 |
|
show
|
1:11 |
Hello and welcome to this module on editing Python code in Visual Studio Code.
Let's go over what this module covers so that you can have a better idea of what to expect moving forward.
The first thing we're going to go through is what the default Python experience is like when writing Python code in Visual Studio Code.
After that, we're going to talk about how we can go about enhancing the Python experience in Visual Studio Code through a couple different mechanisms.
One of them being adding the Python extension, which gives you this richness, this rich developer experience when writing Python code and working within Python projects.
After that, we're going to talk about how you can go about formatting and refactoring your code for a Python project with Visual Studio Code and some of the tools that are available there.
We'll talk about linting and the different linting capabilities that are made available to us in Visual Studio Code.
Last but not least, we're going to talk about snippets in Visual Studio Code.
Now, this isn't specific.
This isn't specific to Python projects, but in general, when you're working on a Python project, snippets can be handy to help you write code faster and with less keystrokes.
So we'll use that as an advantage to us when we're writing and editing Python code in Visual Studio Code.
Now, let's get into the next video.
|
|
show
|
2:57 |
Now for the fun part, let's experience what it's like by default in Visual Studio Code to work with Python.
And the first thing we're going to do is, one, I'm going to show you that this is the default experience.
If you just installed VS Code, a fresh install of it, you'll probably have nothing installed.
I do because I'm using Windows Subsystem for Linux, but that's not for the purposes of this video.
We'll skip over that.
In this case, we don't have anything, right?
That's the point.
We don't have anything installed extension-wise in Visual Studio Code.
So we have the raw experience.
So I'm going to create a new file.
I'm going to call it demo.py.
And you'll notice that Visual Studio Code realizes that the file extension is Python, and therefore the theme that I'm using, the icon theme, is indicating that that is a Python file.
Now if I start typing out some Python code, like let's print hello world, that seems okay.
We get a little bit of this syntax highlighting that's going on for things that are a string or a particular keyword in Python.
They're in VS Code.
And that is giving us a little bit of help in here.
Let's take it a step further a little bit and try some more keywords in Python.
Okay.
So you can see it's highlighting some of those keywords.
Again, these statements of from this module, I want to import this particular fun or from this library.
I want to import this particular function or module and so forth.
Right?
So we're getting a little bit of highlighting.
Let me show you what that looks like.
If it's even.
Not a Python extension file.
So let's create a new file.
I'll demo without any file extension and start writing the same code.
So far, no highlighting or anything like that.
And now VS Code is starting to notice something.
It's like, hey, this looks like Python code, even though it doesn't have the Python.py extension.
And it's recommending you install the Microsoft Python extension for the Python.
Language.
And what this will do is it's going to enhance the experience.
It's by default, Visual Studio Code doesn't have Python support fully baked in and they abstract that out so that it's an extension and you choose to opt in to have that type of experience within Visual Studio Code.
So let's skip that for now.
Well, in the next video, we'll actually install the Python extension, but I want to show one of the things.
So if I wanted to run this code right now and Cecil in a later module is going to go through running and debugging Python code and projects.
In Visual Studio Code.
But for the sake of this quick demonstration, I want to show you what the experience is like.
And let's just do the print hello world.
And I get hello world.
And that's the raw default experience in Visual Studio Code.
In the next video, we're going to talk about the Python extension, which is going to enhance this experience and give it a richer environment for us to be working within.
Understand what that's about and what it provides to Visual Studio Code to create that experience for us.
|
|
show
|
3:52 |
Now, I mentioned the Python extension, and before we go installing it in Visual Studio Code for use in the project, let's get an understanding of what it is and what it makes possible.
Now, if you go over to the Visual Studio Code website, code.visualstudio.com, and you click on API, and then Language Extensions, let's get an overview of that.
The Python extension is what's called a language extension.
It's a type of extension that will give smart editing features for your particular programming language through this type of an extension.
So, VS Code is not providing built-in language support for Python, per se, to the degree that you would expect or want out of an editor or an interactive development environment.
The way they provide that is through extensions.
It's extensibility.
In this case, the Python extension, let's go take a look at what that is.
So, the Python extension is in the Marketplace.
The Python extension in the Marketplace, which you can go through on the website or directly through the extensions view within Visual Studio Code, and you search for Python, you'll want to look for the one that's from Microsoft directly.
It has that little blue checkmark there.
And what this ends up doing is it creates that rich experience for you by including features such as IntelliSense through PyLance, linting, debugging, code navigation, code formatting, refactoring, Variable Explorer, text, and so on.
And you can also add a lot of other features like the VSCode extension, which is a great extension for your own computer.
I mean, I don't know how you can have any more because that was a lot in itself and a mouthful to say.
But that's what the extension does.
It creates that rich experience.
It allows you to opt in because it doesn't know whether you as a developer are going to be working with Python or some other languages.
And so that's why VS Code takes this approach so that you can enhance the experience there based on the type of projects you're working with and the programming language you're using.
Now, what's interesting about this extension is it used to be actually a bunch of separate extensions.
It used to be a bunch of extensions that you would put together and install separately.
But now Microsoft has opted to go with a more bundled approach with a lot of things baked into it.
And because of that, you're going to have some options to set up things with it.
But in particular, I want to go over the more detailed features that it provides, which is IntelliSense.
IntelliSense allows you to essentially have autocomplete.
You can think of them as kind of interchangeably, but don't quote me on that.
But essentially, if you have functions that you want to use or modules you're trying to import, it can give you...
It can give you smart suggestions as you're typing that out and then help you if you hit tab or enter to autocomplete that suggestion.
And we'll see an example of that shortly.
In addition to that, there's linting.
You can choose whatever linting approach or tool you'd like to use, like PyLint or Flake and any other ones that are out there that have an extension within Visual Studio Code.
When it comes to code formatting, which is super important because you want to have consistent formatting on your projects, especially if you're working on a team with other developers, you need to rely upon a tool to...
keep that consistent throughout your project.
So something like Black or AutoPep, those are your options that you can use in conjunction with the Python extension.
And then debugging, testing, and all these other things that we'll get into in later videos, such as the testing and debugging that Cecil will cover in a later chapter.
And then last but not least, I want to mention at least, is the refactoring Python code, which is super important when you're editing code.
You want to be able to quickly refactor things.
Maybe you're renaming a variable that's used throughout a file.
Or other files.
You want that support within Visual Studio Code, and that comes through the Python extension.
And a little bit more, if you wanted to get componentized support to enable additional refactoring, such as import sorting, you get that through extensions like Isort or Ruff.
And that, in a nutshell, is the Python extension, which is a language-based extension for Visual Studio Code.
In the next video, we're going to get into installing it, setting it up, and seeing how the experience is different from the default experience.
in Visual Studio Code.
|
|
show
|
3:28 |
Alright, back over in Visual Studio Code, we're going to install the Python extension.
One of the ways that might be possible is Visual Studio Code might notify you in the bottom right-hand corner under the notifications to install it that way.
And in this particular project, that's happening because we have it as a recommended extension.
But if that doesn't happen for you, you can come over to the extensions view, which is those little blocks typically with the default themes and icons, and search for Python here.
Once that loads up, you click on this Python one.
Again, remember, it's the one from Microsoft themselves with over 100 million downloads.
We're going to click install on that.
And once that's done, that was quick and easy.
It's installed and ready to go.
Let's take a look at the different experience now in Visual Studio Code.
Now, when we come back over here, remember, it gave the syntax highlighting of print.
But notice what might change as I'm typing this out.
You see this quick little IntelliSense auto-completion showing options for how to complete.
And I can see what I'm typing.
So I have to type less and I can just press tab or enter and it will fill in the rest of that command for me.
From here, you can go hello world again.
Save it.
I can hover over the print function and I get more details about what this does.
What are the parameters that this function is expecting?
And I can learn more about how to use it more properly.
What are the options I have within it?
All driven through the Python extension in Visual Studio Code that you would not have in the default experience.
Let's talk about some of the settings that are available with the extension as well.
So I'm going to open this up the settings with the keyboard shortcut control comma or command comma.
If you're on macOS.
I'm going to search for Python.
Once I'm in here, you'll notice that there's a couple of different options, but we're going to focus on under the extensions category Python.
And you'll see there's a lot of options here.
One that I highly recommend that's a relatively new feature in Visual Studio Code is this enable REPL smart.
Send enable that.
I don't think it's on by default and I'll demonstrate what that does in just a second.
Outside of that, you have a couple other options.
You want to activate the terminal environment, activate environment in the current terminal that you might have open.
You can enable those types of things with that checkbox.
You have launch arguments that you want to pass in when you run Python projects and files within Visual Studio Code.
Some auto complete options, extra pads for it to look at such as the Google app SDK, if you'd like.
You can.
Point to that globally referenced library on your machine through this these settings.
Now, one other thing to note that makes the Python extension create this type of experience for us is it's using what's called a language server protocol.
The one by default that it comes bundled with is called pylance, which is why we're seeing that as another option here under the extensions.
If you don't like this one in particular, maybe it's not working to your expectations, but honestly, it works fine for me.
You can change.
That you can install other language server providers.
And choose that that as the one that you want for the Python extension to use.
So in this case, there's Python language server.
you can use like Jedi for instance, or pylance.
And if you installed any other ones that might be out there, they would show up here.
And that is the Python extension in a nutshell.
We're going to dive deeper into the overall experience that it's providing and how it enhances the development workflow and efficiency for us as Python developers in the next few weeks.
|
|
show
|
13:22 |
All right, in the last video, we installed the Python extension, looked at some of the settings for it.
And in this video, we're going to dive deeper into enhancing these capabilities and what this extension itself provides versus what other extensions you might need to enhance the experience even further.
Now, one thing I really want to dive into in this video is talking about linting and code formatting.
Okay.
What has changed in the origination of this extension was it used to come bundled with a lot of this stuff with a lot of this stuff already in it.
But when it comes to linting and code formatting, they've taken a step back essentially and allow you to take initiative on your own to choose what type of linter or formatter you want to use when it comes to your Python projects.
So we're going to dive deep into that now, and then we'll get into some of the other capabilities like refactoring in the next video.
Okay.
So first up, let's understand what's the difference between linting and code formatting.
Shield your eyes for a second.
It's going to get bright.
Okay.
Going directly to the Visual Studio Code website, it talks about this.
And in particular, linting is about highlighting things like the syntax and issues with problems in your syntax so that it can help you catch errors and issues in your code before having to realize those at runtime.
So the idea here is while you're writing the code or you're analyzing a PR or something like that, you can catch some of these issues around the syntax that's being used in the Python project way before and saving you some time way before runtime, which would lead you to having to run and debug and change things over time to get to a resolution.
This enables you to potentially save yourself from that and save that time that you would go through in that developer loop.
Now, in particular, you can choose from a number of linters that are separate extensions that the Python extension will support for you within Visual Studio Code.
So some of the ones that Microsoft publishes.
Our PyLint, Flake8, and mypy.
And then some of the community ones are like Ruff and then a community version of mypy.
If I were to start today from scratch, I'd probably go with Ruff because Ruff seems to be, if we open it up really quick, Ruff seems to be an all-in-one type of solution.
It's a Visual Studio Code extension with support for the Ruff linter.
And what's nice about Ruff is it can also format in addition to that, which I'm getting a little bit ahead of us here.
We'll get into formatting in just a second.
But right now, I just want to talk about linting.
And Ruff seems to be that kind of end-all solution or bundled solution that replaces Flake8, Black, iSort, PyUpgrade, all these different individual tools into one tool.
And it does it super fast because apparently it's using Rust behind the scenes, which is a super fast and lean programming language.
Getting back to linting.
I have already installed PyLint in VS Code.
And I kind of want to show the difference of what PyLint will show versus what you get out of the box.
With the Python extension.
So if we head on over to the status router.py file, and if I just type in foo.
And I hover over it, PyLint is telling me that foo is not defined, which is great.
That's like a nice linting indication to let me know, like, I might have messed up something here.
I didn't finish typing this out or whatever I may have intended for foo here.
PyLint is letting me know it doesn't look like you finished what you're trying to do.
Now, if I enable PyLint.
And I go back to that file, you'll notice it's got a different squiggly line under it.
So it's no longer the orange or yellow squiggly line, which is more of a warning from PyLint.
It's red now, which is more of an error.
And now it's being driven by PyLint.
And PyLint is reporting that statement seems to have no effect.
It's undefined variable foo.
And we can see the rule set that's associated with that that PyLint is reporting on.
This is one way you can view these types of problems, by the way, by hovering over the problem.
Or you can bring up the problems panel, which a shortcut for that is control or command shift M.
And now you can see all the problems for this particular file that we have open right now.
And again, there's PyLint, which is showing here, and the PyLance one.
And you see the difference there.
PyLance is somewhat helpful in this regard, but it's better to have a standalone linter or separate extension that handles linting for you to give you a better experience and better information on potential errors in your code.
Now, when does linting happen?
You might have noticed that once I enabled PyLint, it just started working right away.
And essentially the way VS Code is set up is that anytime you open a file or save a file, whatever linter that you have defined and in use will analyze that file and lint it for you immediately.
The last thing I want to call out when it comes to linters is some of them offer what's called code actions.
In this case, PyLint isn't really offering a code action here, but just to describe what that means, it's a very simple way to use it.
So you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
And you can see that it's a very simple way to use it.
|
|
show
|
6:18 |
Let's take a look at how VS Code and the Python extension helps us to refactor our projects and our Python code.
First up, we're going to take a look at renaming variables and modules and what that does for us.
So in this case, we have this variable in this function for this API route, show_id, and we want to rename that.
Maybe it's not really a show_id, it's like show_time_id or you want to capitalize the ""i"" let's say.
So what you can do is a couple of ways you can go about renaming this.
You can right-click on it and click on the rename symbol or as you can see from here in the menu, there's the F2 keyboard shortcut.
I click on that and you'll see this new little pop-up come in here and let's change it to where it's capital ""i"" and then ""d"".
One thing I want to call out before I hit enter to rename it, as you can see here, there's different keyboard commands.
If I do shift enter, it shows me a preview of what's going to change, which is really nice.
And then you can choose to apply or discard.
Right now I'm going to discard it.
We'll do this again.
Show_id, capital ""i"" ""d"" and take note of everywhere else inside of this function where show_id is being used.
VS Code will update this for us.
So if I hit enter, all those have now updated with the capital ""i"" ""d"".
So that's one of the ways that Visual Studio Code through the Python extension and PyLens are able to create that quick experience, quick way of editing and renaming a variable.
You can do the same thing for modules too.
So let's take a look at this logging module that we're importing.
I'm going to put this over to the side because I want you to be able to see the changes from this.
All right.
In the same way that we're able to rename variables in our file and it affects that variable that's being used throughout the whole file, we can do the same with modules.
So if I want to rename the logger module here, I press F2 on that and I type it to call it log.
And you'll notice on the right hand side, I have the logging py file that defines that module for me.
And let's see what changes.
You'll see now that while I changed the name in this file, it also updated the module itself to use that log file instead of logger naming convention.
That's one of the cool things about VS Code is if even though I'm working in one file, it will update all the other places that that name change would affect.
Moving on from here, let's talk about extracting methods and variables in a function.
I'm going to close out that and let's fix this really quick because that's bothering me.
So let's go back to the show ID.
So let's rename that back to show ID.
So let's try and extract a variable.
In this case, we're logging information that the show ID that we're retrieving is the one that's being executed right now for when a request comes into this API.
But instead of having maybe I reuse this multiple times in here and I wouldn't like to have to retype this every time I want to extract this out to a variable.
So I can select that and I can go back to the show ID.
And I can see that I've got a variable that I want to extract.
So I can go back to the show ID.
You'll notice that the little bubble like a bulb icon rather shows up here.
I can click on that and I can say, hey, I want to extract the variable from this.
And it'll prompt you to give a name to that variable that you'd want.
So let's say message.
And now I can use that variable again anywhere else.
In this case, I'm only using it once, but you get the idea.
And you can even use that string interpolation capabilities built into that as well.
So that's extracting a variable.
But what about extracting bubbles?
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
I'm going to use a little bit of code here.
|
|
show
|
5:03 |
All right, so let's take a look at snippets and how they can help us be more efficient when writing Python code in VS Code.
First of all, what are snippets?
Well, you can kind of think of them as like a text expansion, but focused on code.
And the idea behind it is so that you don't have to type as much as you normally would, or you don't have to keep typing common things that happen or that you use very often, like API creation functions and that sort of thing.
So that's the idea behind snippets.
You can use ones that are built into VS Code.
Some of them are there, but they're mostly focused on JavaScript, TypeScript out of the box that are built in, Markdown and PHP.
But if you want one for your particular language, in this case, Python, you can search in the marketplace for the category of snippets with the keyword of Python and you'll find some.
And in fact, I'll show you one right off the bat.
Being that this project that we've been looking at throughout this course is this podcast.
API, we're using FastAPI to make this possible.
So there's a lot of common ways that we can set up routes and things like that in FastAPI.
So one of the extensions I found when searching the marketplace was FastAPI snippets.
So I searched for category snippets and then specifically FastAPI.
I installed this extension and then I can see that there are various abbreviations I can type that will then generate more code for me.
However, the first thing we need to do in order to enable this is to update our settings.
If you have a fresh installed VS Code, you're likely going to have to change this because the default version of this is off.
If you go into your settings, you search for tab completions, turn it on, you'll be all set and good to go.
Install your snippets and you're ready to try them out.
So the first one we're going to try out from this snippets extension is hello world HW.
So if I come in here and I add a new line, type in HW, you'll notice before I press anything else that it shows this snippet extension.
So if I come in here and I add a new line, type in HW, you'll notice before I press anything else that it shows this snippet extension.
This shows this type of indication in the IntelliSense from Visual Studio Code.
Now, if I hit tab, what that will do, if you watch closely, it's going to go by fast.
It's going to generate a HelloWorld example of FastAPI.
And boom, I'm ready to go.
You can see it imported FastAPI.
It set up the app and set up a default route that returns a JSON message of HelloWorld, which is great.
And you can use this for all kinds of things.
Now, the last thing I want to describe here is being able to create your own snippets.
So maybe I wanted to create one that redoes this logging that's specific to my particular project here, because I'm constantly, as you can see here, writing this over and over again.
So maybe you could see I'm repeating this code over and over again on line 52, on line 57, on line 39.
So it'd be great if I could just quickly type out or create a snippet that would set it up at least and allow me to enter in what I need, the string that I want, and then the variable.
So let's see what that's like and how I can go about doing it.
So in order to do that, we're going to use the command palette, which has always been our friend throughout all of this.
So control or command shift P and let's go snippets and configure user snippets.
We can see we have some options here.
There's new global snippets file, but we want one that's specific to Python.
So we're going to hit enter on that.
And we can see an example here before us.
Place your snippets for Python here.
Here's the example.
If we want to print the console, let's undo the snippets.
We can undo that one a little bit on comment that rather.
And now we have the print to console option.
Not exactly what I was talking about before, but at least a starting point for us.
And let's try it out.
So now that I have this log, which is the prefix log is what's going to expand to become the following body.
And when it's the description is what will show when it's when it's ready to be used.
So if we go in here and we try again, we type in log.
You'll notice there's print to console.
That's the description.
I was talking about before I can click on it and it automatically created the console log for me and that type of thing, right?
Again, this is specific to other programming languages, the console log that we have here, but we can change it to what we had here.
Let's take an example of this copy it, paste it in here.
You'll notice let's escape these characters.
And we'll set this to dollar one for placeholder.
Get rid of that second one.
And let's try it out now.
So now you can see it's log info, no episodes found for show ID and then it can type in Joe ID.
Variable like I was before and you can customize this further to your liking.
Make things more dynamic if you'd like as well and have a lot of fun.
With it, you could see the benefit and value of code snippets in Visual Studio Code because it allows you to more quickly and efficiently generate and write your Python code.
|
|
show
|
0:52 |
All right, in summary, and to help reinforce what you learned in this module, let's take a look at everything that we covered.
One, we talked about the default Python experience in Visual Studio Code right out of the box.
And then we talked about how we can go about enhancing that experience within Visual Studio Code tailored to Python.
One of the ways we're able to do that is with the Python extension that gives us a rich development experience for us for Python projects.
We talked about formatting and refactoring Python code within Visual Studio Code, as well as some of the linting capabilities that are available to us.
And last but not least, we covered the snippets that we can use or create on our own that helps give us a quick jumpstart to writing Python code more quickly and efficiently without having to move our hands off the keyboard.
In the next module, Cecil is going to teach you about running and debugging Python projects in Visual Studio Code.
See you over there.
|
|
|
26:09 |
|
show
|
0:54 |
Hi everyone.
Welcome to Chapter 5 in the Visual Studio Code for Python Developers course.
In this next set of videos, what we'll be doing is talking about how we can manage our developer environment using VS Code.
Specifically, we're going to be diving into topics such as switching between different versions of Python because that might be something you need to do depending on the collection of projects you may have on your machine.
Also, we'll talk about setting up virtual environments and how we could create these little isolated workspaces that we could use for our projects.
Next, we'll also talk about some of the built-in and open-source tools that are available to us that can really help improve our developer workflow.
Also, we'll talk about configuration settings and how using something like environment variables can be a really good option for managing the settings of our application.
Last but not least, we did see how Visual Studio Code can support all of these different techniques using the Python extension for VS Code.
|
|
show
|
7:46 |
When you're about to dive into a project, one of the things you might want to know is, well, which version of Python am I supposed to use?
And is it different from the other versions that I already have installed on my machine?
You might also be in a situation where you have different projects on your machine, which all require a different version of Python.
Now, it can get really tedious if you have to manage the installation and swapping between these different versions as you go from project to project.
Luckily, there's tools available that make it a lot easier for us.
And we're going to take a look at PyEnv, or pyenv, which is a free open source command line tool that makes it easy to switch between multiple versions of Python.
Now, in this video, we're going to see how to get pyenv installed on our machines.
We're going to see how to work with it inside of our terminal by installing different versions of Python and switching between them.
And we'll also see how it works with Visual Studio Code when we're trying to work with our projects.
Over in VS Code, I'm going to open up the terminal.
And since we're probably going to spend most of our time in here, I'm just going to go ahead and drag it to the top so it can take up most of our screen.
Now, I'm going to type in python --version.
And as you can see, I actually don't have Python installed in my computer.
So what we need to do is, why don't we go ahead and install PyEnv and install a version of Python that I can start working with.
Now, since I'm using macOS, I'm going to install PyEnv using Homebrew.
Make sure you head over to the PyEnv website so you can see the PyEnv website.
And you can see the installation instructions that you're going to need for the operating system that you're using.
Now that the installation is done, I'm going to clear the terminal and I should be able to type PyEnv on the command line.
And now I should see a list of commands that we're able to execute.
If I type PyEnv versions with an S, it'll show me the different versions of Python I have set on my machine.
And right now it has an asterisk next to the system version, but I actually don't have Python on the system.
So let's go ahead and install one.
If I go ahead and type PyEnv install-l, it'll show me all of the different versions of Python that I can install using this command line tool.
Now, I think one of the most current versions of Python is 3.11.
So I'm going to go ahead and install that one.
So I'll type Python install 3.11.3.
Now I'm just going to let it go ahead and do its thing.
It's going to download Python from the internet and set it up on my machine.
Now this may take a second, so I'm going to fast forward the video a little bit so we can get to it.
Now that that's installed, I should be able to say, I'm going to start working with Python on my machine, right?
But I'm still getting an error that says command not found.
What we need to do is to set the version of Python we just installed as the global version on our machine.
So if I type PyEnv versions, again, you can see the different versions of Python we have installed, and 3.1.11 is the one that we just got.
If I type PyEnv global, and I'll type in the version that we want, 3.11.3.
Now if I type Python, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type PyEnv local, it's going to say, PyEnv local.
So if I type python --version, this should say 3.11.3.
But I'm still inside of my folder.
What if I went to a different folder?
What if I just went to, I don't know, let's just go to the root folder.
This is not a good idea, but don't do bad things here.
If I type in python --version, notice now I'm getting a different version of Python.
Because PyEnv is installed, and I'm able to set both local and global versions of the Python interpreter that I'm using.
And now this becomes really handy, as you're switching between projects, and you can have a different version of the interpreter referenced based on the folder and based on the project that you happen to be using.
Now to close out this video, why don't we take a look at some of the useful commands that you can run using PyEnv.
We saw PyEnv versions, which allows us to list all of the available versions of Python that are installed on a local machine that we can start using.
PyEnv install dash L will list all the versions of Python that we can install using this tool.
PyEnv install with the version number 1, will allow us to download and install the version of Python that we chose.
And last but not least, we have two very special ones, which are PyEnv global and local.
The global one lets us set the global version of Python that's set across our entire machine.
On the local one, we'll set the context for that particular folder.
So if you want to have different versions of Python referenced within a particular folder, which represents a particular project, you can use that command to do that.
|
|
show
|
5:44 |
Now that we've learned how to switch between different versions of the Python interpreter using pyenv, let's move on to talk about virtual environments.
Now, according to the official documentation, virtual environments are a cooperatively isolated runtime environment that allows Python users and applications to install and upgrade Python distribution packages without interfering with the behavior of other Python applications running on the same system.
Now, that sounds like a superficial way to think about it, but the way me and Brian look at it is, virtual environments are just a safe place to work on our Python projects on our dev machines that doesn't interfere with everything else that's going on the operating system.
So that means that we don't have to worry about conflicts whenever we install or upgrade a dependency that our project needs.
Now, it turns out that Visual Studio Code and the Python extension have really great support for working with and creating virtual environments, so why don't we head over there and take a look at it.
With the podcast project opened up in Visual Studio Code, you might notice that I have some error messages due to some unresolved dependencies inside of my project.
Well, why don't we go ahead and create a virtual environment on the command line and then try to resolve these issues.
Now, I'm going to use the VENV module built into Python to create a virtual environment inside of my folder.
One thing you might notice on the bottom right side, Visual Studio Code has now noticed that I just created a virtual environment within my workspace.
So now it should ask me if I want to associate it with my project.
I'm going to go ahead and hit yes.
One of the things you might notice also on the bottom right side, if I click on this little selector here, it has set that virtual environment as the default interpreter that I'm going to use.
So now whenever I install packages or any additional dependencies, it's going to be scoped solely to this folder.
Now, another thing we usually have to do is activate our virtual environment.
But what you might notice is, well, the Python that's inside of our terminal right now is still not set up to work.
So now we're going to set it to the one that's within our project.
Now, one of the things that we could do, if we wanted to, well, it was we could run this activated command, and that's included inside of that virtual environment.
But we're not going to do that.
Instead, if I create a new terminal window, what you'll notice is that Visual Studio Code has gone ahead and activated that virtual environment for me.
So anytime we create a new terminal for our Python project, that's just one less thing for us to worry about.
Now, if I check one of the things that I want to do, which version of Python this one's running, it's using the one that's inside of the virtual environment we just created.
Now, that's just one convenient way to create virtual environments.
But let's say you're not a command line person.
Well, one of the things you can do is open up the command palette inside of Visual Studio Code, and then you can type Python create environment.
And then notice it'll offer you to create a virtual environment using VENV or Conda.
I don't have Conda installed, so I'm going to pick the first option.
And now I'm going to pick the base interpreter that I'm going to use.
And if you remember, I have multiple versions of Python installed on my machine.
So I'm going to select the one that I want it to be the base for.
And I'm going to choose 3.11.
Now the last step is notice that I have a requirements.txt file also inside of my folder.
So it's giving me the option to go ahead and install those while it's creating the environment.
So again, very convenient and just less steps for me to do.
Well, that's just a really convenient option if I didn't want to use the command line.
Now if I run my project, looks like everything's up and running.
So that's perfect.
I'm going to close this.
And I'm going to go ahead and delete this virtual environment that we just created.
And I want to show you one more way that we could do this inside of Visual Studio Code.
So you saw how to do it via the command line and you saw how to do it via the command palette.
Well, what if I open my project?
If I am supposed to head over to the requirements.txt file, notice on the bottom right side, it says create environment.
So that means that I can initiate that create environment action straight from the requirements.txt file.
And I'll go through the same workflow that I did before where I select the interpreter I'm going to use.
I'm going to select whether I'm going to use conda or VNV module.
And then also it'll install my requirements listed in my requirements.txt file.
So there you have it.
You've seen three different ways that you can create virtual environments using a Python extension inside of Visual Studio Code.
Now let's take a second to talk about how the Python extension discovers these different environments inside of your system.
When the VS Code extension for Python is looking for different interpreters on your system, different virtual environments for you to use inside your project, there are a few different lookup locations it checks out by default.
As an example, it takes a look at common installation paths based on your system, whether it's a Windows path or a Mac path or a Linux path, for instance.
Also, it's going to look for virtual environments that you might have created inside of your workspace folder, kind of like what we did in this video.
It's going to look for the virtual env folder off the root home folder of that user.
And it'll also look for different environments that might be created by pyenv, pipenv, and even portrait.
Also, if you're using conda environments, anything that's returned from the conda env list command is also for your game too.
Now this is not an exhaustive list.
There's definitely more places that it looks at when it's trying to determine what available environments, whether it's virtual environments or interpreters that are available for your system to use.
So I definitely recommend that you check out the documentation to see all the different options that you have.
that you have.
|
|
show
|
5:07 |
So far in this module, we've seen a few different tools that you could use to manage your Python environments.
But there are tons of others available that could really help boost your productivity.
So far we've seen tools like pip, but there's also pip-tools which adds a lot of additional functionality.
Pipenv and poetry are really great for not only installing packages but also managing your virtual environments.
Regardless of whichever one you choose, you'll be able to use them inside of Visual Studio to help boost your productivity.
Why don't we go ahead and take a look at one of them?
Let's go ahead and get started with using poetry inside of VS Code.
Now, the first thing I got to do is install it.
Since I'm on a Mac, I'm going to use Homebrew.
Now, I'll be honest, I installed it already so I'm just cheating just a little bit.
The next thing we need to do is initialize our project.
So I'm going to type in poetry in it, and now it's just going to walk me through a few prompts I need to answer.
So I'm going to give it the name of my package which is Podcast API.
I'm going to accept the defaults for the version, the default description, author looks good, I'm just going to leave all that as defaults, Python 3.11, that looks good.
Would you like to define your main dependencies interactively?
Yeah, sure, let's do that.
Now, the first one I'm using is TinyDB, so let's go ahead and put that in.
I want to select that first option, and I don't have any version constraints, so I'm just going to hit ""Enter"".
And the next one I'm going to do is FastAPI.
And this one, I'm going to add that all parameter, so I'm going to get all the good stuff.
I'm going to select the first option for that again, no version constraints, and that should be it.
Do I want to install any development dependencies?
Now, this would be good if I was installing anything for like a testing or anything I didn't want for production.
Now, I don't have any of those right now, so I'm just going to type ""No"", confirm that the generation looks good, that looks great to me, and then now notice we have this generated PyProject.toml file.
If I kind of move away our command line, it's going to say ""No, you can't do that"".
So I'm going to hit ""No"", and then I'm going to hit ""No, you can't do that"".
And then I'm going to hit ""No, you can't do that"".
So if I move away our command line a little bit, you can see some of the things that it went in and set up for us.
So it has like a build system and the dependencies, and some general project information that we're going to use.
Now, I'm going to go back to the command line, let's clear it out a little bit.
Now, we have our packages installed.
So the next thing I actually need to do is create a virtual environment.
Now, Portrait does this really cool thing where it can create virtual environments in like a common space, or it can create it inside of your project.
Actually, I want to create it inside of my project, so I'm going to run some configuration steps really quickly.
And so I'm going to do ""portrait-config in ""project-true"".
So that means that I want to create the virtual environments inside of my project.
I don't want it to create it in some other directory or some other part of my operating system.
And now the next one I'm going to do is portrait-config and I'm going to do ""create-true"".
Notice that I'm also passing that -local"".
-local"" means that I want to save those configuration settings to this local folder.
configuration settings to this local folder.
So these are not just the configuration settings, these are not just the configuration settings, these are not just the configuration settings, these are specific to the project that I'm working on.
So if I move away this command line really quick, you'll notice I have a ""portrait.toml"" file and this defines, well I want these virtual environments in the project and I want you to create them in case it doesn't exist.
and I want you to create them in case it doesn't exist.
So we have our dependencies defined in pyproject.toml and we also have our ""portrait-config inside of a ""portrait.toml"".
So the only thing really left for us to do now is actually run our project.
Now what I actually want to do is activate our ""portrait"" environment and I'm going to do that by typing in ""poetry shell"".
and I'm going to do that by typing in ""poetry shell"".
Now notice it's created our virtual environment and as you can expect, since it's created within our workspace, VS Code is popping up on the right side of the screen asking, ""Hey, you want to use this virtual environment?
asking, ""Hey, you want to use this virtual environment?
Sure, why not.
Now I'm going to open up another tab and notice how VS Code has gone ahead and has activated that virtual environment for me.
I'm going to clear that out really quickly.
And now let's go ahead and do poetry install"".
This is actually going to install those packages that are listed inside of that portrait.toml"" file.
One of the great things I love about this is not only does it install the packages that we have listed, but it also installs our current project, which is pretty useful when we want to do things like testing with pytest a little bit later on.
Now let's just go ahead and run our project.
I'm going to do ""python -m podcast-api Oops!
python -m podcast-api And there you go.
Our project is working.
Looks pretty good.
Now you saw how we could create virtual environments and manage dependencies with another tool called ""poetry"".
And it all still works great inside of VS Code.
One of the things I would want to point out though for folks that are a little bit more familiar with Python, you might notice that this pyproject.toml"" file is a little bit non-standard in comparison to the one that's officially supported by Python.
And that's totally fine.
In future versions of ""poetry"", I believe they are going to update to use that more standard version.
Right now I'm using the ""pyproject.toml"" version and using ""poetry 1.5.1"".
So, still a great tool, but just something for you to take into consideration.
Thank you.
|
|
show
|
4:36 |
Another thing for us to think about as we're getting our workspace setup is, well, where do our application settings go?
Depending on the type of project that you're working on, you might have a variety of different settings you need to store, like API keys or access tokens, deployment settings, or even customized values specific to your application.
Now, of course, we can have these values hard-coded inside of our application code, but that's usually not a good idea for a variety of reasons.
For one, it could end up inside of source control, which can end up potentially exposing sensitive information about our application.
Also, it makes these values so much harder to change.
So now every time we need to make an update to a configuration value, we're going to have to end up redeploying our application.
A better option is to use some type of flexible configuration system that will allow us to easily read and write these values.
A good option for that is using environment variables.
Now, environment variables are a platform-neutral way of storing dynamic configuration values usually as key-value pairs that can be accessed by applications running on the operating system.
It turns out Python has really good support for working with environment variables using a standard library.
Also, if you're going to use environment variables, I definitely recommend you check out and see how they work inside of your operating system.
Now, a good way to use environment variables locally in development mode is using .env files.
These are just simple text files that hold those key-value pair settings.
So as your application, it could look for this particular file, load up those settings, and now it could use them as it's running.
Again, I recommend that these files are mainly used during development time.
During production, you probably want to use whatever the native environment variable support is inside of your operating system.
With that being said, we can help with a Visual Studio code, but we can see how it helps us work with environment variables.
The first thing that we're going to do is create a new .env file in the root of our workspace.
I'm going to add this.
I'm going to add this app name setting, and I'm going to set that to Podcast API.
Now let's head over to our module and see if we could read this.
So I'm going to import the OS module from the standard library.
And now let's head down to the main function.
So inside of main, I want to see if I could read this using the os.getenv function.
Now, I really like this function because it makes it easy to read these settings, and it does not return an exception if it can't find it.
So that's usually pretty helpful.
Let's go ahead and set a breakpoint here.
And we're going to debug this and we just see if it can read the value.
Now, I know we haven't spoken about debugging, but this would be a good, you know, primer into it.
Okay, so it's loaded up our operation.
Notice how it's also set the virtual environment for us too.
That's pretty cool.
I'm going to hit run.
Run.
All right, now it's down an app name.
I'm going to step over.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
And I'm going to hit run.
|
|
show
|
2:02 |
All right, folks.
Well, that brings us to the end of chapter five of this course.
And what we did was spend a little bit of time talking about some of the different tools and techniques that you could use inside of Visual Studio Code for managing your Python development environment.
Now, before we move on to the next chapter, why don't we spend a couple of minutes and talk about some of the things that we've covered so far.
Now, first thing that we did was we talked about an open source command line tool called PyPI or pyenv.
And this is great if you need to swap between different versions of Python on your machine.
And maybe you have one project that uses one version of Python and another one that uses another.
This is a really good tool to help automate doing some of that type of stuff.
Now, the next thing we talked about is the support inside of VS Code for switching between different Python interpreters.
So after we have our different versions of Python installed, we can also, using the VS Code UI, swap between those different versions in there.
Also, we have the option of selecting different virtual environments too.
And that's a really cool tool.
So let's get started.
VS Code has some conventions that it follows to try and discover where these different interpreters are installed.
Now, the next thing we looked at was one of my favorite tools is Poetry.
And no, not writing Poetry, but this is also another open source command line tool.
And this helps us with package management, managing our dependencies.
It also spins up virtual environments for us.
So it's kind of like a little bit of an all-in-one environment management tool.
So this is pretty fun.
If you like Poetry, this is obviously very optional.
You don't have to use it.
But if you like it, make sure you head over to the docs and check it out.
Another thing that we talked about using is ENV files, and particularly how we could use them to help manage our environment variable settings.
Now, environment variables are just key value pairs that, you know, might hold information from our application, whether it's connection strings or API keys or anything of the sort.
It's a great source for keeping our configuration safe and also out of source control as well.
Now, in the next chapter, we're going to be talking about source control.
And specifically, we're going to be talking about how we could do source control in VS Code.
We're going to focus on using Git.
|
|
|
35:54 |
|
show
|
0:58 |
Hi everyone.
Welcome to Chapter 6 of the Visual Studio Code for Python Developers course.
In this chapter, we're going to talk about running and debugging your Python application.
So far in the course, we've talked about a lot of different things like editing your code and configuration settings and customizations you can make, extensions you can install.
We even talked about managing your Python environments and creating customizable workspaces.
So I figure at some point in time, we should actually tell you how to run and debug some of these applications that you're going to write.
So specifically, we're going to look at a couple of different things like one, how can I use the terminal to do command line debugging?
Not my recommendation, but some of you might want to do this.
We'll look and see some of the different visual elements and UI components inside of Visual Studio Code that you could use for debugging your application.
And then we'll talk about different debug configurations, how we can set these up and some of the options you might want to configure based on the needs of your project.
So why don't we go ahead and just get right into it.
|
|
show
|
9:13 |
Before we dive into learning how we can run and debug our Python applications inside a Visual Studio Code using a Python extension, first, I wanted us to take a moment to look at some of the existing command line debugging techniques that are available.
I mainly wanted to do this because for folks that might be coming from command line editors like VI or Emacs, I wanted you all to see exactly how you could easily transition over these skills and how they work inside of the Visual Studio Code editor.
One thing you might have noticed so far in this course is that whenever we run our Python sample application, we do so by calling the Python command.
Now, what I'm showing you here is that I'm using the version of the command that's inside of our virtual environment.
I'm going to clear the prompt.
Now, if I actually want to run our sample application, I could do something like this.
I can call Python, I can pass it the -m switch, then I'm going to give that switch the name of our module, which happens to be Podcast API.
Now, when I run it, I'm going to give it a second, and soon we'll see some output printed to the terminal, which will let us know that our application is doing the things that we expect it to.
Now, one thing a lot of developers do, and I know almost all of us have done it, whenever we need to get some more information about what exactly is happening inside of our app, we use something called print line debugging.
What that means is that we insert print line statements throughout very key points of our application, and then we run it, and then we see what happens.
Now, for me personally, I'm not a big fan of print line debugging.
I instead prefer to do something like logging.
So as an example, I'll do something like this, logger.info, and I'll set up a Python logger, so it'll output to the screen with almost the same amount of information, but instead, I'll have a little bit more control over what goes out there.
One of the key benefits between logging and print line statements is the fact, I can specify the severity of the message that I want to output, and also I can turn it on or off using configuration.
So that way now whenever it gets into production, I don't have to worry about it too much.
If you take a look at the application, you'll see that it's not just a simple logger, but it's a very simple logger.
If you take a look at the terminal window right now, we can see we have various log messages such as debugger info, along with the information associated with those particular logs.
Now, if you're curious to see what our logging implementation looks like, you can open the logging.py module inside of our project.
Inside here, you could see that we're importing the built-in logging module from Python, and along with some other things.
But essentially, what I'm doing is creating a named logger called podcast API, setting the default level, a custom formatter, and also the stream handler.
If we head back over to our categories router at the top, you can see that now I can just import that module and use it across all of our different parts of our application.
Now, if I go back over to the terminal, you can see at the bottom those two custom debug statements that are there.
Those examples of log messages from the custom logger that we set up inside of this project.
Now that our sample application is up and running, the next thing that we want to do is make a call to one of our API endpoints.
Now, you saw how to do this earlier using something called the Swagger UI.
This is built-in functionality inside of our FastAPI project, which is great because that means that whenever you create a new project, there's not a lot of extra work you have to do to get this setup.
But we are going to do something a little bit different now.
Back inside of Visual Studio Code, I'm going to head over to the extension section, and I'm going to search for something called the rest client.
I'm going to select this one.
What this is, is an extension for Visual Studio Code that allows you to create custom HTTP calls.
Now, I really love this extension because it allows me to make calls to my API without having to switch between different windows, and editors, and different tools.
I can stay focused right here where I am inside of VS Code.
Now, I'm going to head over to our Explorer, and I'm going to create a new file.
I'm just going to call this sample.http.
Now, these.http files are supported by that rest client extension, and they do have a very specific syntax.
Now, I don't want to make a get request.
The first thing I need to do is, well, I'm going to type get.
Notice how it has some really nice IntelliSense that really pops up for us.
The next thing I need to do is give it the URL.
So I'm going to copy this URL here from the command line.
I'm going to paste it in, and I'm going to give it the endpoint I actually want us to call, which is going to be categories.
Again, notice how that IntelliSense popped up.
It actually overwrote some of my stuff.
That's not what I wanted to do, but let's do this.
There we go.
Categories.
Now, I can hit the send request, and I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
I can see that it's already done.
But still, we're able to stay inside of Visual Studio Code without moving around too much and having a contact switch.
Another helpful feature is you have the ability to have more than one HTTP request inside of this file.
So let's say I wanted to make another endpoint call.
I'm going to copy this.
And let's say I wanted to make a call to the-- I think there's a shows endpoint.
So I should be able to do something like categories.
Give it a category.
I'm going to use art from the right side.
And then I'm going to do /shows.
There we go, shows.
And let me close that.
I'm going to close this right now.
Here we go.
Right.
Right now, notice I have two different requests inside of the same file.
So if I make this call, there you go, art and culture.
I'm able to see the shows represented from the categories.
But the important part is, as you can see, I can have multiple API endpoints or multiple HTTP requests specified in this file.
I can even add things like headers or a data body or anything like that that I want to.
And now I can save this file.
I can check it into source control if I needed to.
And now different folks in my team are able to use it to debug our application.
Now, if you quickly take a look at the bottom of your screen, inside of the built-in terminal, you'll notice that we got lock messages for every request that we made to our web API.
So that means that we're able to see exactly what's happening with our application as it's running using the logging that we set up.
Now, I'm going to stop our application from running and clear the terminal really quick.
The next thing that we want to do is elevate this and take everything that we've seen so far and use it with Python's built-in debugger.
Now, Python itself comes with a debugger called PDB.
And the only thing that we need to do is give it the name of our module that we want to debug.
In our case, it's going to be our podcast API.
I'm going to go ahead and hit Enter.
And what's happening now is that it's actually started to run our application.
Now it's just stopped at the first line.
But if I type in continue, notice that it's continued to run the rest of our application, which is pretty cool.
So we actually have a debugger now that we can use to not only run our applications, but we can set things like breakpoints to actually run it.
Why don't we try it out really quick?
I'm going to stop our application again.
I'm going to type in exit to exit the debugger, and I'm going to clear the screen.
Let's head back over to our Categories API.
We'll close this window, head back to Categories.
Let's clear some of these things away from the screen.
It's starting to get a little busy.
All right, let's put it here.
And then let's also replace this with something that we can use to do some logging.
Logger.info, right?
There we go.
Do we have any more of those in there?
Great.
Logger.info.
Now, the next thing that I want to do is I want to add a breakpoint.
And we can do that by calling back-- there's an actual breakpoint function built into Python.
Let's go back to the terminal and run our application with the debugger.
OK, application running.
I'm going to hit Continue.
And I'm going to run it.
And let's see what happens.
And you'll notice at the command line at the bottom, it says that it is now stopped at the Logger.info line of code.
It hasn't run it yet, but this is the next line of code that it's actually going to run.
And if we head back over to the Categories router, we can see exactly where that is.
Now, inside of this debugging session, we can use all of the commands that we can expect to have, like move on to the next statement, continue running, and so on.
So we can see exactly what that is.
And now, we can see that it's running.
We can even take a look at some of the variables that exist inside of this context right now.
So let's say I typed in Logger.
And let's say I wanted to print the Logger.
Right?
You can see that it says we have an instance of Logger.
The name Logger is Podcast API.
And it's set to debug right now.
So again, we can kind of inspect the context of what's happening around this space.
If you wanted it to continue running, we'll just type Continue.
And there you have it.
So we're done with the debugger from that REST Client API extension.
We also get our log messages at the bottom.
And we're also still invoking using the built-in debugger from Python.
Now, I'm not going to go super deep into all of the different things you can do with the debugger.
But the point of this was really just to show you whether you're coming from a command line tool or not, you're able to use some of those familiar techniques inside of Visual Studio Code along with some other extensions that can make your workflow just a little bit nicer.
|
|
show
|
5:46 |
Now that you've seen how to do it via the command line, in this video, I want to show you how quickly you could get started with debugging your Python applications inside of Visual Studio Code.
Before we start debugging, there's a couple of things that I want to clean up really quick.
First off, I want to remove this breakpoint statement that we added inside of our router controller because we don't really need that anymore.
Next, I want to make sure that we're in the right virtual environment.
I'm going to go down to the bottom right side of the screen and click on the status bar.
In here, you'll notice, as we saw before, it'll list all of the different virtual environments and Python interpreters that we have, but also that one with the star in it, it shows us, well, this is the one that we're currently using and that's the right one.
We'll close that really quick.
Next, I'm going to open up the command terminal.
Now, I want to type in python-m pip list.
I just want to make sure that I have all of my dependencies from my requirements.txt file installed.
Now that that's up and running and we know that's all good, let's go ahead and start debugging.
Now, on the left-hand side of my editor is where right now, you can see that I'm keeping my activity panel.
Inside of there, you should see an icon that looks like a bug with a little play sign next to it.
If you hover over it, it should say, ""Run and Debug.
If I click on that, it opens the ""Run and Debug"" panel.
Now, guess what I'm going to do?
I'm going to press ""Run and Debug.
Now, what the Python extension for VS Code does is it gives us a couple of different debug configuration options.
Do I want to debug a file?
Do I want to debug a model?
Do I want to module?
Do I want to remote attach?
Or do I want to use one of the configurations that are specific to one of these different web frameworks?
Now, we are using FastAPI, but for this case, I just want to use Debug the Module.
I'm going to click on the module.
I'm going to enter the name of our module.
If you remember, it is PodcastAPI.
I'm going to hit ""Enter"" and then I'm going to go ahead and let VS Code do its thing.
What you're noticing is happening in the terminal at the bottom is that it's activated the virtual environment in a new window.
It's not going to be able to run the application.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
It's going to be able to run the application in a new window.
|
|
show
|
3:13 |
In the previous video, you saw how to set up quick debugging sessions inside of Visual Studio Code.
Well, now we're going to take some time and look at some of the various debug configuration options that are available to us as Python developers.
Now, running ad hoc debug sessions is fine, but for most scenarios, you'll want to have more control over the various debugging settings, as well as the ability to persist them between runs and even share them with your teammates.
This is where setting up a debug configuration file comes in really handy.
In Visual Studio Code, that's the role of the launch.json file.
It allows you to configure and save debug setup details specific to your current project and the programming languages that you're using.
One of the things I like about the launch.json file is that it's not hard to edit or create once you get the hang of it.
At its core, launch.json is just a JSON file that contains an array of configuration objects, each with their own unique settings.
Inside that array, you can have just one or many different launch configurations.
It's fairly common for developers to create it by hand or use the VS Code UI.
Just remember that Visual Studio Code is going to look for it inside of the .VSCode folder inside of your workspace.
Now, if you look on the right-hand side of the screen, you'll notice an example configuration of what it might look like to configure a Python application.
Now, on the left-hand side, you'll see examples of familiar attributes that you might run into as we continue to explore the launch configuration.
So, for example, if I wanted to run a Python application, I could run a Python application using the VS Code UI.
So, I can run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
So, I can run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
So, I can run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
So, I can run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And then, if I wanted to run a Python application using the VS Code UI, I could run a Python application using the VS Code UI.
And thanks for watching!
|
|
show
|
7:47 |
Let's see how we can create our first launch configuration.
First thing we're going to do is open up the Explorer.
Inside of that.VSCode folder, you'll notice that there's no launch.JSON file.
That means that we don't have any configurations that are set up as yet.
Let's go ahead and do that.
In the activity bar, I'm going to click on the Run and Debug section.
In there, I'll click on the link that says, Create a launch.JSON file.
Now, this is going to pop up a window that'll show us some options that make sense for Python developers because we're building a Python app.
I'm going to select the option for module, and now I'm going to type in the name of the module of our application.
In this case, it just happens to be Podcast API.
Now, Visual Studio Code is going to create a launch.JSON file for us.
As you can see, this contains a single configuration that allows us to run and debug our module.
Now, one small change I'm going to make here is I'm just going to rename this, and I'm just going to call this Podcast API.
If we take a look at some of the other settings, you'll notice that the type is set to Python.
You'll see the request is set to launch, which is important because this tells VS Code that we wanted to launch our application and then attach the debugger to it, as opposed to attaching our debugger to an already existing process, which is a completely different setting.
We have our module, and then we have some other settings down there as well.
Another thing I want you to pay attention to, if we head back over to the Explorer, and we take a look inside of that.VSCode folder, you'll see that VS Code is now created that launch.JSON file.
Now, let's go ahead and run this debugging session and see what happens.
Now, inside of this run and debug section, I'm going to open this up a little bit so we could see it a little bit better.
The drop-down at the top is going to show us a listing of all our different configurations.
Right now, we have this one that says Podcast API module.
If you'll notice, that matches the name of the configuration we have in our launch.JSON file.
I'm going to select that one and go ahead and click ""Run"".
As expected, Visual Studio Code is going to activate our version, and it's going to run the debugger.
Now, if you go to the virtual environment, it's going to start the debugger, and it's going to attach to our application, and you should see those familiar log messages right there in the terminal.
Why don't we go ahead and create a different type of launch configuration?
I'm going to stop the debugger.
I'm going to move this over a little bit so we can have some more space, and let's close the terminal for now.
Instead of going through what we did before and clicking on that link, right here inside of the launch.JSON file, we're going to go ahead and create a new one.
This time, now it's going to show us a listing of a lot of the different configurations that it has by default.
As you can see, Python is right at the top, which makes sense for us, but there's also options for Chrome, Edge, Node.js.
If you have other language support in there, you might see them for Java, .NET, etc.
Let's go ahead and click on the Python one, and this time I'm going to select FastAPI, because our sample application is actually built with FastAPI.
I'm going to hit ""Enter"".
Now, it's asking us for the paths for our application.
If I take a look inside of our Explorer, you can see that it's PodcastAPI, and the main app actually exists inside of here.
But what this actually wants is the name to the FastAPI module that we want to run.
This is what we're going to do.
I'm just going to type in PodcastAPI, and I'm going to put a .API.
Notice as it creates this new configuration, it has a colon on the right-hand side with a value of app.
Now, we actually need to change this, and let me show you.
Let's say I want to call this API.
If I open up our API.py file, you'll notice that the name of our application that's getting exported is actually API, and it's not app.
And I did this on purpose.
So what we need to do is just rename this really quickly, and call this API, or whatever the name of your particular module happens to be.
Now, I'm going to do what I did the last time, and I'm going to rename this really quickly, call this PodcastAPI.
But this time, notice the postfix is different.
This time, this one says PodcastAPI FastAPI.
Just so that we know that the names for these different configurations are different.
But the type is the same.
It still says Python.
The request is the same.
It still says launch.
But what's different now is that you can see that it's using Yubicorn, which is a server, and then it's passing it some command line options using that args key.
So it's passing it the name of the module, which is PodcastAPI.API, and it's also passing it the reload flag as well.
Let's head back over to the debug section.
Open it up.
Now, I should be able to select from one or the other of these debug configurations.
Now, this FastAPI one is the one that we created last.
Let's go ahead and run it.
And now you see it's running our application.
Now, what are some of the things that you notice might be a little bit different?
Well, first of all, when we run it like this using this FastAPI option, what we need to do is we need to give it a FastAPI object.
Let me move this window out of the way so you can see what I'm talking about.
So we need to provide it this object, and it's going to pass it over to the server.
This is going to start running our application from here, which is fine.
With the other option I did when I read it as a module, it's actually going to end up running the code that's in main.py, which is a little bit different.
And as you can see, my main function does a couple more things.
It gets a parser, and it looks at some of the command line args.
It generates fake data for me, and then it actually calls uvcon for me.
So again, I just want to show you this because you might have different ways to run your application.
And now you can kind of see some different ways where you could get more flexibility and also rely on some of the built-in functionality that's inside of VS Code.
Let's head back over to the launch.json file for a second.
Now, if I come down here, and let's say I go down to the next line, and I hit Control + Space, and this should work on any operating system, right?
We're going to hit Control + Space.
Now, notice this is going to show us some of the other options that are available for us as we're setting up this debug configuration.
So some examples.
Examples are .env for adding environment variables, or .env file to point to the environment variable file that's in your workspace.
I also have options for Django.
I have options specific to Linux or Mac if you wanted to.
You have path mappings and programs, purposes, all these different options that you can set.
And like I said, we're not going to go through all of these, but I just wanted to show you some of the different options that are available for you.
And if you hit Control + Space, IntelliSense will kick in and allow you to explore some of the options that you might want to set for your debug configurations as well.
Now, as you can see, with our debugger still running, we can run our application just like we did before.
So let's say I head back over to the categories router.
I'm going to go ahead and add this breakpoint here.
And now if we open up the sample.http, I can go ahead and send requests.
And notice, now I can start stepping through my application.
I can hit Step Over, I can hit Continue.
I can get the results.
I can get the results as I expected to.
And again, what I'm doing now is instead of just running like an ad hoc debugging session, I'm actually running it based on some of the information that I have set up inside of this file.
Now, if you're not using PaaS API, you're using some other framework, or maybe you just want to run a module, or maybe you just want to debug a Python file, I definitely recommend you check out some of these different configurations that are available.
And I definitely recommend you head over to the documentation so you can learn about all of the different settings you could supply, all the different options that are available for you.
So you can make sure that you can create these debug configuration files that make sense for your project.
But the great thing about this is that now I have a configuration that's set.
So I don't have to worry about recreating this every time.
And I can even check this into source control so I could share with my team, or I could have it available for me whenever I switch machines.
|
|
show
|
4:49 |
Now, let's take a second to talk about breakpoints and explore some of the interesting options that Visual Studio Code offers to make working with them a little bit nicer.
As you saw in a previous video, we can use breakpoints to pause the execution of our debugging session at any point in our program where we want to expect and see the state of any of the variables or functions we have inside of our application.
Here, I'm going to set a breakpoint inside of the status router.
What I'm going to do now is I'm going to open up that sample.actp file, and I'm going to make a request to status.
As you can see, the breakpoint stopped before running the current line that I set the breakpoint at.
But at this point, I can check and see the state of any of those variables that are inside of here.
For instance, I can look at the status code, and I can see, well, it's actually not set to anything yet.
But once I step over it, notice my application is still paused, and I can check and see now this is set to 200.
Right?
I can go ahead and keep my application running.
Now, not only does breakpoints allow me to pause the execution of my function, but inside of Visual Studio Code, we actually have a breakpoints view.
So inside of the debug section, I can open up the breakpoints view, and now I can see all the breakpoints that are set.
I can even click on those breakpoint listings, and it'll take me to the exact file and line where that breakpoint was placed.
Within the same view, I have the option to edit any of these breakpoints, or I can even remove them if I don't want to use them anymore.
I can add new breakpoints using this plus button, or I can toggle on or off those active breakpoints for my current debugging session.
Now, while that seems pretty straightforward, there's a lot of other interesting things that we can do as well.
I'm going to set this breakpoint back to where it was before.
Now, on this breakpoint, I'm going to right-click on it, and if we zoom in a little bit, you can notice that I have an edit breakpoint option.
When I click on edit breakpoint, notice now, I can set what's called a conditional breakpoint.
Conditional breakpoints allow me to pause the execution when a particular condition is met.
As an example here, I can do it based on a hit count.
A hit count would be, hey, if this thing hits this particular breakpoint n number of times, maybe it's four times or five times or six times, at that point, then I want you to pause it, or I want you to pause based on the value of an expression.
Let's take a look at the expression one.
I'm going to say i is equal to 10.
I'm just going to make up an arbitrary variable and value.
I'm going to hit enter.
Notice there's no i here.
I'm just going to set i is equal to 10 here at the top.
Oops, that's my mistake.
This should be i single equals to 10.
What that should be able to do now is if I go ahead and start my debugging session again.
Remember, I set this to break only when i is equal to 10.
I'm going to run this request.
I notice the breakpoint is stopping because, well, condition i is equal to 10, obviously.
Let's go ahead and I'm going to change that to 11.
I'll restart my debugging session.
But now if I go ahead and I execute this status request, it should not break at all because, again, even though my breakpoint is set, it's not going to meet the condition because i is no longer equal to 10.
Obviously, this is a very simple use case.
You can change it for whatever condition you want.
Maybe you want to set a condition where the incoming request is equal to a certain value and you want to stop at that point.
Or whatever other variable is in scope, you might want to break whenever that condition is true or not.
Now, let's go ahead and stop this.
Let's take a look at the hit count one.
So let's say maybe, no, I don't want to remove it.
I can right click.
I want to edit this breakpoint.
I'm going to change this now to hit count.
And let's say I want this, you know, every time the hit count is three, right?
So when it reaches three, I want it to hit or I want it to stop at this breakpoint.
So starting the debug session again so we can see what happens here.
Now my application should be running.
I'm going to head back over to sample.http.
Now I'll issue my request for status.
One, didn't stop.
Two, didn't stop.
Three, ding, ding, ding, ding, ding.
We got a winner.
So notice, again, our condition was I needed to stop when the hit count is equal to three.
So now notice that it stops here.
Now I can stop my debugging session.
I can remove my debug breakpoint from here.
Or I can even come inside of the debug window inside of the debug view.
And I can exit out from here if I wanted to.
But now you can see some of the different options you have when it comes to working with breakpoints inside of Visual Studio Code and how you could use conditional breakpointing to set the specific conditions you want to inspect in your debugging session.
|
|
show
|
2:24 |
There's one more tool I wanted to point out to you when it comes to debugging your applications in Visual Studio Code, and that's the Debug Console.
Let's go ahead and set our breakpoint back inside of the status router.
I'm going to go ahead and start my debugging session again.
And I'm going to go ahead and issue a request using our sample.http file.
Now I'm going to issue the request.
And notice here in this area at the bottom where the terminal is, there's a tab for Debug Console.
And what I can actually do here is I can type in the names of the variables that are in scope and I can inspect and see what some of those values are equal to.
So for instance, if I wanted to take a look at the response, for instance, because the response is in scope, notice it gives me some information about the object.
I can see this is a starlet responses response type, or it's an instance of that type.
I could open and expand a little bit.
I can see, well, there's no body in there.
There's the headers and some of these different types of things that are set.
But another thing we can do is actually alter some of these variables.
And we can actually change their values as we're going through the debugging session.
So maybe you want to see how your code reacts to when certain values are set.
You can do it here in the Debug Console.
So let me show an example.
If I go ahead and you just hit the Run button, notice that this should return an http 200 OK.
So that's a successful request.
Let's go ahead and run it again.
And now this time, what I'm going to do is I'm going to step over.
I'm going to head back to the debug console.
And I'm going to go ahead and do a little bit of debugging.
And I'm going to go ahead and do a little bit of debugging.
And I'm going to go ahead and do a little bit of debugging.
I'm going to head over to the debug console.
Let's say response.status is equal to 10.
I think 10 is a bad number.
Let's set this to 400.
I'm going to hit Enter.
Now if I inspect this, or actually let's inspect it in the debug console.
I'm going to hit Response.
Oops, didn't type that right.
There we go.
Let's hit Response.
And now if I inspect it, I had done the status code.
I can see my status code is set to 400 because I changed it in the debug console.
So I'm going to hit Enter.
And now if I inspect this, or actually let's inspect it in the debug console.
I'm going to hit Response.
And now if I inspect this, or actually let's inspect it in the debug console.
If I continue my debugging session, notice it says 400 bad requests.
Now maybe I have some middleware I want to test.
Maybe I want to test the handler or maybe my unstartup shutdown operations or whatever it is that you have going on inside of your framework.
You have the option to intercept the debugging session, change some of the values in the debug console, and see what happens as you continue debugging your application.
|
|
show
|
1:44 |
Congratulations.
You've made it to the end of Chapter 6, where we talked about running and debugging Python applications inside of Visual Studio Code.
Hopefully, after watching this chapter, you feel a little bit more comfortable about navigating the UI of VS Code and how you can set up your debug configurations exactly how you want it to be.
Before we move on to the next chapter, why don't we take a moment to talk about some of the things that we covered so far.
Now, we took a look at the launch.json file.
Inside of here, this is where you set up your different launch configurations, and you can have one or many or as many as you want to have in there.
But you can set different options like the name of the configuration, the types of applications you want to debug, the module you want to target, and some of these other interesting things.
Environment variables, arguments, current working directories, so on and so forth.
Most of the things that you'd want to be able to configure to say, this is how I want my configuration set up, you'll do it here inside of the launch.json file.
Using the UI inside of Visual Studio Code, you can select which one you want to run at that given time and go ahead and execute that.
After we took a look at our configuration, we took a look at the UI of Visual Studio Code when it comes to debugging.
We took a look at the debug view, we looked at the debug console at the bottom, we learned a little bit about breakpoints and using conditional breakpoints and how those work.
We also took a look at the breakpoint view that lets us edit, add, remove, delete our breakpoints, and then we can also add a breakpoint view that lets us add a breakpoint view to our application.
So, we can see that we have a breakpoint view that lets us add a breakpoint view to our application.
So, we can see that we have a breakpoint view that lets us add a breakpoint view to our application.
So, we can see that we have a breakpoint view that lets us add a breakpoint view to our application.
|
|
|
14:16 |
|
show
|
1:21 |
Welcome to Chapter 7 of the Visual Studio Code for Python Developers course.
In this chapter, we're going to be talking about how you can test your code.
And we're going to look at some of the different options that Visual Studio Code has built in for enhancing your testing workflow.
You know what I was just thinking though?
Isn't it weird that the testing chapter always ends up at the end of the book or the course?
Anyway, not a big deal.
Let's keep going.
So in this chapter, we're going to talk about some of the different options you have.
So you'll see how you can execute your commands for your tests by the command line if that's a workflow you're already using.
But we're also going to see how to use the test explorer that's built into VS Code.
We're going to talk a little bit about test discovery.
And obviously, we're going to see how we can run and debug our tests so we can see exactly what's going on and make any changes if we need to.
And then we're going to take a look at some of the configuration options as well.
So what are some of the things that you could use to fine tune exactly how your tests are running inside of VS Code?
Now the Python extension in Visual Studio Code has support for a lot of different community frameworks and tools.
And when it comes to unit testing, it actually supports two of the most common testing frameworks, which is unit test, which is built in, and also pytest, which is a third-party dependency.
In this chapter, we're going to focus on using pytest since it can run pytest tests and also unit test tests.
So I think that's a win-win.
So let's go ahead and get started.
|
|
show
|
4:50 |
>> If you take a look at the sample code for this chapter, you might notice that we've made a few changes to our project structure.
Now, even though these are small changes, they do have an impact on the way that we're going to test our code.
First off, you might notice that there's now a test folder in the root of the project.
As you can imagine, this is where all of the unit testing code is going to go.
Secondly, there's no longer our requirements.txt file.
Instead, we're going to specify our dependencies inside of the pyproject.toml file.
Also, you'll notice that we're going to have some of the other project configuration located in this file as well.
Why don't we head over to Visual Studio Code and I can show you how some of these changes impact our project.
As I mentioned before, we no longer have a requirements.txt file to specify our dependencies.
Instead, we're going to use the pyproject.toml file.
If I open up the file, underneath that project section, you'll notice that I have a dependencies property.
Inside of here, I could specify that I need FastAPI, TinyDB, and any other dependency that I need for the production version that I'm going to run for my application.
Now, I say production version because remember, we also need to have dependencies for our tests, but we might not want to have those dependencies installed whenever we run our project, so we want to keep them separate.
If you look down at the project optional dependency section, you'll notice that I have a test property.
Inside of here, I can specify the test dependencies that I want to run.
If we take a look down at the project optional dependency section, you'll see I have a property called test.
Inside of here, I have an array of dependencies where I let the project know that I need pytest, and I also need a pytest plugin called pytestMock.
Notice how we have the option to specify conditions for the versions that we want for those particular packages.
Now, if I was still using a requirements.txt file, it'd be a little bit challenging because I may have to specify two different files or do some type of special build configuration if I wanted to keep my production dependencies and my test dependencies separate.
Here inside the PyProject file, I could just have different sections that talk about my main dependencies, and also I can specify optional dependencies as well.
If we scroll down a little bit inside of the PyProject.toml file, you'll notice that not only can I specify information about my project, like the dependencies and some metadata, but I can also set up configuration for pytest too.
Inside of the tool.pytest.ini_options section, I'm able to specify pytest configuration properties, such as the Python path, test pass, and even different markers.
I can even do the add-ops where I can specify command line options that I want to use.
Again, this would typically be in a separate file, but because we're using PyProject.toml, I'm able to consolidate my configuration and not have so many different files to maintain.
Now, if I was supposed to open this test folder, you can see some of the tests that I've already written for our project.
Now, notice how I'm already getting red squiggly lines.
Well, that's because I haven't installed any of my dependencies yet inside of my project.
What I'll do is I'll open up the command line, and let's go ahead and install some of these dependencies.
I'm going to do Python-M, I'm going to do install.
Now, the dot is what we use when we're going to use our PyProject.toml file.
I'm going to go ahead and install this, and in a few seconds, you should see that it's going to install the dependencies that we have set up inside of our PyProject.toml.
Now, if I do something like pip list, I should see everything that just got installed.
But what I don't see is pytest.
Well, pytest didn't get installed because if you recall, let's head back over to this PyProject.toml file a little bit, let's move this window down a little bit so you can see what's going on.
I specify this in optional dependencies.
If I just do install, it's not going to install those optional dependencies.
I have to let it know that I wanted to do that.
I'm going to do Python-M pip install, but I'm also going to specify some of those optional dependencies.
The only optional dependency section or property I have here is test.
What you'll see inside of my command line now, it's going to install pytest and pytestMock using those version specifiers that I set up.
Now, if I go ahead and I do pip list, I should see I do have all those other dependencies, but I also have pytest and I have pytestMock.
Using PyProject.toml just gives me a really convenient way for me to manage different dependencies for the different types of environments I want to use.
Here I have my core dependencies and I also have my test dependencies specified as well.
|
|
show
|
3:00 |
Now that we understand how our project configuration is set up, let's actually run some tests.
What I'm going to do is open up the command line, and through that built-in terminal inside of VS Code, I'm just going to go ahead and run pytest.
Now, because we had it installed as a dependency, I should be able to just run pytest as a command in my command line inside of my virtual environment.
If we expand the terminal a little bit, you can see that it's picking up the pyproject.toml file as its configuration file.
It's using that test folder as the place that's going to look for the discover tests, and it's also picking up that pytest mock extension that we installed also.
We can be confident that our configuration is working so far.
But what I actually want to do is run these tests using Visual Studio Code.
Now, on the left side in the activity bar, we should see a section here called Testing.
Because we're inside of a Python project, it's giving us an option to configure Python tests.
Now, if we look at the top, it gives us the option to use two of the most common Python testing frameworks, unit tests, which is built-in and it comes with the standard version of Python, and also pytest.
Now, we're going to use pytest for this course.
Now, the next thing it's asking us is, well, what's the directory that contains the test?
Obviously, I'm going to select the test folder.
Now, inside of this test explorer window on the left side, you can see that pytest has discovered the test files and also the test inside of each of those files as well.
If I hit ""Command comma"" or if I just go into the settings file, let's close some of these windows really quickly, and I type Python testing, you should see some of the other options you can set as well, such as the debug port or whether pytest is enabled or not, we can change it here, the binary path for pytest, or we can even toggle it and maybe we changed our mind and we wanted to use unit tests instead.
We can come inside of the configuration file, or we can change all of these inside of our Visual Studio Code settings.
Now, here's one more thing I want to show you that I particularly think is interesting.
Now, whenever we run our tests, you may or may not notice that on the left side, inside of the explorer, there's a folder that got added called.pytestcache.
That's just a caching file to help pytest run a little bit more efficiently.
But it also is a little bit distracting and I don't want to see inside of my code.
What I'm going to do is I'm going to head back over to the settings and I'm going to type in exclude.
Now, I can start excluding file patterns.
For instance, let's say I don't want to see that inside of my folder view because it's not really important to me and I'm not going to really do anything with it.
I can just come in and I can do something like this.
I'll use this catch-all pattern and then I'm going to do exclude.pytest_cache.
We'll click ""Okay"".
Then notice now on the left side, it's completely gone.
Anywhere that that file pops up inside of my project, Visual Studio Code is just not going to show it to me.
Obviously, if you wanted to see it again, you can just come and hit this ""X"" here and it'll just pop back up.
You can do this with any folder or file that you want to hide from your Explorer view.
|
|
show
|
4:00 |
With everything that we've covered so far in this chapter, we should have most of what we need to start running a debugging test inside of Visual Studio Code.
Now, I'm going to open up the Test Explorer.
Now, you can see that we actually haven't run any of the tests yet, so there's no visual indicator to let us know whether they're successful or whether they're failed or not.
If you look at the top menu, we can see that we have a couple of options that we can run here.
We could refresh the test if we wanted to.
Maybe you've written some new tests and you want to force the editor to run its discovery.
You can use this button for that.
We can run all the tests and then there's also a debug one that we can debug all our tests as well.
In this tree view underneath, we can see that our tests are grouped by files and folders.
All our tests are inside of this test folder, and then we have two test files or two test modules.
One for testing the categories router and another one for testing the status router.
If I open up this tree, you'll see all the tests listed that I have for that category router.
Now, if we wanted to go ahead and run all the tests, I'll just go ahead and hit this ""Run all tests"" button.
You'll see some similar output to what we saw in the command line when we ran pytest directly.
If I give us a little bit of space here, you can see we have a test results tab, and then we can scroll through and we can see that all of our tests have been passing so far.
On the right side of the test results window, we can see that we've also captured some data about that latest test run.
Now, it's no fun when all your tests pass.
Let's go ahead and shake some stuff up.
Let's go ahead and break one of these tests.
What I'm going to do is I'm going to click on the ""Test"" and then right next to it, I can click ""Go to test"".
What it'll do is it'll send me right over to where that file is or where that test is defined inside of the editor.
Now, I'm going to do something like this.
I'm just going to mess this up, and now this is not going to work anymore.
Now, if I go ahead and run all tests, you should see that this test should fail.
Oh boy.
No one wants to see that.
Let's go ahead and fix this super quick.
Now, instead of me running all the tests all the time, maybe I just want to fix this one particular test, and not everything inside of my test suite.
I'm going to close this error window here that's telling me everything that went wrong and what problems I do have on my test.
I'm going to go ahead and fix that error really quickly.
But now that it's fixed, notice that this little X that's right next to it.
Well, this let me know that the test failed previously.
But if I click it again, it'll rerun the test.
It'll only rerun that single test, and it'll let me know what happened.
At the bottom, you can see I have one test passed in my test results window, and it also logged it here, my test runs at the right side.
Now, what if I wanted to go a little bit deeper?
What if I actually wanted to debug a test?
Well, we did cover running and debugging Python applications in a previous module, but running tests is so much easier.
All we literally have to do is just hit the ""Debug"" button.
So I'm going to select the test inside of the Explorer and I'm going to go ahead and run it.
Now Visual Studio Code has launched debugger, it's running my test, and now I could step through using all my usual debug functions like step over, step into, continue, stop, and all these other types of things.
I have my variables window, my watch window, my call stack.
Everything that I would expect from a typical Python debugging session is available to me.
I also just noticed that I have a typo here, so let's go ahead and fix that real quick.
There we go, that's better.
Let's make sure inside of VS Code that the name is also updated as well.
Notice how it looks at it like, well, it's a new test because I renamed it, I guess.
So let's go ahead and run this test, make sure it still works, and everything here looks pretty good.
Now, another thing you can do inside of this test Explorer window if you're interested, is you can actually run a different types of filters.
So you could say things like, show me only the test that fails, show me some of the excluded tests, maybe use skip tests or something like that.
Now, you know how to use the test Explorer to run and debug your tests written in Python.
|
|
show
|
1:05 |
>> Well, all right folks, I guess that's it.
After taking a look at this chapter, you should have a pretty good grasp on some of the options that are available, and some of the features that you can make use of when it comes to writing tests for Python inside of Visual Studio Code.
Specifically in this chapter, we talked about how to use testing frameworks like pytest, and do remember that Visual Studio Code does support unit tests as well.
We looked at test exploration and how test discovery works.
We saw how to execute your test by the command line, but then we also saw how we could use some of the built-in options inside of the editor as well.
We saw how to run and debug our tests, and then we also took a look at some of the different configuration options that are available.
Now, we're not going to just end it right there.
I actually have a challenge for you.
I challenge you to take a look at the code that's inside of the folder for this chapter and to go ahead and write some additional unit tests as well.
Feel free to message us on Twitter, on social media, or even contact us via the Talk Python e-mail address.
We'd love to know how you're applying what you've learned, and we'd love to see what types of tests you've written after you've gone through this chapter.
|
|
|
32:40 |
|
show
|
4:59 |
Hello and welcome to Chapter 8, Source Control with Git.
We're going to be diving into what it's like using Git and Source Control Management within Visual Studio Code.
We're going to step through things like what is Source Control and why do you need it.
We're going to talk about working with a repo within Visual Studio Code and Source Control Management around that.
And then we'll talk about how you can do common things with it, like viewing and syncing your changes, committing changes, pulling.
What else, Cecil?
Anything else I'm missing out of that?
What else would you do with it?
Yeah, just overall, how do I manage the assets that make up my application?
Whether it's your code, but also your configuration or your build setup, or maybe even have your data.
How do you version some of these things and share them with your team?
And so these are some of the things that we're going to cover in this particular module.
So Brian, why don't we start off with the question, the question.
What is Source Control?
So first off, VS Code is natively built to...
to work with Git Source Control Management.
If you're not familiar with that, you can go to git-scm.com to learn more about it.
But essentially, it's a way of tracking changes in a folder that you might have.
And being able to revert back to certain history, keep those things in sync, and be able to track that better for your project and files and assets that you're going to be working on within that project.
So again, Visual Studio Code is built natively to support that, but can support other Source Control.
Management systems.
Cecil, do you know some of the other ones that are available then and how they might be available?
I do.
And you know what, back in my day, I have to say, back in my day, I used to use a source control provider called Subversion SVN.
This was earlier on, very different from how Git is set up.
The differences aren't really important for this particular course.
But if you want to take a look at it, it is still available.
It's still actively maintained, I believe.
And so...
There are probably a lot of folks out there that still use it as well.
I know Mercurial is another option for Source Control Management that folks use.
I think Mercurial is a little bit closer to Git in terms of how it shares the assets around.
So, and if you want to be able to support those other Source Control Management systems, since Git is the only one that is natively built into VS Code, it's available to you through an extension.
If you head on over to Visual Studio Code and you go into the extensions view, you can filter by category SCM providers, Source Control Management providers.
And within there, the list that you'll see is SVN, like Cecil was just talking about, or Mercurial and other options that you might have within there to help support that Source Control Management system within Visual Studio Code.
And in this video, what we're going to do is explore that integration of Git inside of VS Code.
You're going to see how to work with repositories, pull them down and initialize them on your machine.
And also how do you share those changes with your teammates and then look at some of the other like really cool features built into VS Code that make working with Git a little bit nicer.
So when it comes to managing like your GitHub repos and projects and things of that nature, you obviously have the option to just host it yourself on your machine.
That's totally fine.
Or maybe you have your own little network set up in your home office.
You can host it there as well.
And you can have like your little distributed system of Git repositories.
And I know some folks that do that, but if you wanted to, you also have the option of hosting it online.
And there's a few different service providers that are available that allow you to do that really easily.
Probably the most popular one that a lot of developers use is GitHub.
And as you can imagine, it lets you host Git repos, but it also helps you do things like manage discussions.
And there's a build service in there.
And then there's tons of other additional features that makes not only just managing your source control, but managing well, the management of your project and your conversations in your community a lot more easily.
So I think that's a really good point.
And I think that's a really good point.
And so definitely recommend that if you don't have a GitHub account, make sure you go ahead and create one.
You can create one for free.
Another option for doing that as well is GitLab.
Very similar to GitHub, but also very different from GitHub.
Again, this is just another option that you can have for hosting your GitHub projects.
I'm sorry, for hosting your Git projects online.
So you can create public or private repos.
You can have discussions.
And then you can also have like, you know, corporate versions of it that you could use to work with your enterprise teams.
But throughout the rest of this chapter, this module, we're going to be talking about different Git terms and ways to use Git and source control management.
And if you're not familiar with those already, we highly recommend you check out the existing course on Talk Python, Up and Running with Git.
If you check that out, that'll give you the knowledge and skill set and information that will help you understand what we're talking about.
If it sounds foreign to you or unfamiliar, go ahead and check out that course.
Now, from here in the next video, we're going to dive into working with a repo inside Visual Studio.
Studio Code.
|
|
show
|
13:11 |
So now that we know a little bit about the role of source control and some of the things that we might want to do with it, why don't we see what it actually looks like to start working with Git and source control inside of VS Code?
Now, for folks that maybe you're already used to working with source control via the command line, again, regardless of whether you're using Git or Mercurial or SVN or any of those other tools, you can still have that same workflow inside of Visual Studio Code.
And the only thing that you need to do is just pull up the built-in terminal and you can start executing commands just like you would have in your regular workflow.
Now, while this is a great experience, and I think it's good to allow folks to easily migrate over to using new tools, VS Code, the wonderful editor that it is, has tons of different options built in that you could use either by accessing a menu or using the command palette.
So, Brian, why don't you show us some of the things that are inside of the command palette just specifically for working with Git?
Sure.
And really quick, I just want to remind folks that we talked about shortcuts in VS Code earlier, in an earlier chapter.
To bring up the terminal, the built-in terminal, if you want, you can press control or command back tick to toggle that on or off.
And that way you can start doing your things that you're used to doing with the command line directly in Visual Studio Code, like Git status and all the different Git commands you might use there.
But for now, let's hide that.
And let's talk about the command palette, like Cecil said.
So I bring that up with control shift P on Windows and Linux.
Command shift P on macOS.
And if I start typing in Git, now I can see all the available commands that are provided to me through the command palette from Visual Studio Code.
So I can clone a repo, I can add remotes, I can apply stashes, I can commit files and changes that are going on, and so forth.
And that's one way to go about doing this.
And that's one of the main ways that you can do it with where it allows you to keep your hands on the keyboard, one of the ways I prefer personally.
Or if you're more of a pointy-toe, point and click type of person more visually, all those actions that we were just talking about, if you bring up the source control view, which keyboard shortcut for that, we're going to call that out again, control shift G, G, and bring that up.
Or you just click on that icon there.
And then these three little dots, more actions menu, all those things we were talking about that you might want to do that's within the space of source control management using Git is available to you through this menu.
Now, one of the things I really love about using the menu is well, one, I don't know every Git command.
So if I wanted to kind of see what one, what are some of the operations I could do, or what are some of the different options within those different commands, I could easily use the menu and click through.
And now I could still be very productive, but also continue to learn about the capabilities that my source control provider has.
Yeah, it's a great way to learn.
In fact, I'm seeing ones right now that I've never used before or heard of before that I'm learning about too.
And the different types of commands that I'm learning about too.
I'm learning about the types of like, normally I just do a Git pull, but apparently there's a Git pull rebase or Git pull from type of command that is available or just syncing in general.
Those types of things I don't typically use in the past, like from the command line.
So it's interesting to see that populated in Visual Studio Code to make that more aware to me, and I can learn something new about that.
Take a quick second and actually go through some of those commands that we may have used before, maybe we've never seen before.
Sure.
I think for me, one of the most common options to kind of mess around with is using branches.
And so for folks that don't know what branching is, let's say you're working on a project and you have like a main, your main timeline that is your project, but maybe you want to add a feature or you want to kind of experiment with something, but you don't want to mess up your main workspace.
Well, essentially you can kind of create somewhat of a copy.
It's kind of like taking a fork in the road, right?
Like I'm going to make a left turn.
The other road is still there.
But I'm just making a little bit of a deviation to kind of explore and see what can happen there.
And then at some point I could either forget about that fork, forget about that copy, or I can bring them back together.
So one of the good things you can do is navigate through some different branches.
So why don't we go ahead and see, like, how can we do that inside of VS Code?
Sure.
Well, one of the ways I'm going to go about doing that is bringing up the command palette again, and I'm going to say git branch.
And what we can do now is from my current branch, which is the main branch, and the way I can double check that is, one, it's kind of hiding behind you, Cecil, right now, but in the status bar it shows you down there that it's the main branch.
But if I click on it, you can see it gives me the option to create a new branch, create a new branch from this one, but also showing me my local main instance of the branch, and then the remote branch, which is over at my origin, which is in this case up on GitHub.
So if I wanted to create a new branch from this main branch, which means taking the current state of it and moving it into whatever is there, assets, code changes, whatnot, copy, copying it over into a new branch, basically.
So I'll say new branch from here, and we'll call it this demo branch.
And now, while it's not necessarily a parent, but I have a local instance of that branch that I'm working on within Visual Studio Code.
One of the things that we do when we're actually inside of a branch, regardless of whether it's our main branch or, you know, a feature branch or a side branch, is we probably want to commit the code, right?
And so when we talk about making commits, this really means that, like, we've made some changes to some files, maybe we've added, removed, you know, moved some things around a little bit.
But what happens is, you know, the original state of our project and what it is now after our changes are different.
So what we want to do is make sure that we save these changes, and not save them in the sense that they're saved to the file system, but we want to save them to the repository.
So one of the things that we can do inside of Visual Studio Code and how VS Code visualizes those changes, it says, is if you take a look at the activity bar on the right side, you'll notice, like, the Git panel, right, has, like, some numbers next to it.
And those numbers will show you exactly how many different files have changed.
And then if Brian clicks on that really quick, you'll see, well, we have one, two, three, four, we have about five files that have changed.
And if he simply clicks on one of those files, we should be able to see a diff, right?
So now we're seeing, well, what does the original one look like on the left side?
What does the new version look like on the right side?
And now if we wanted to, the next thing that we're going to do is we're going to do a little bit of a change in the changes.
So what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And what we're going to do is we're going to do a little bit of a change in the changes.
And I think that's a good segue and probably the last thing we're going to talk about in this particular video is remotes.
So what exactly is remote?
Right now, kind of like what Brian was saying, he has, you know, the demo branch that's there.
There's also that main timeline that we talked about, like that main branch.
So there's almost like different, there's different train tracks of the same application that's there.
But one of the things that you could do is, hey, well, while all these changes are on my machine, I might want to share them with somebody.
And, you know, of course, I could put them on a thumb drive or just pick up my laptop and like, you know, drive to another city and try and share them.
But I can also use one of those services we mentioned in the previous video, like GitLab or GitHub.
And I could use a remote repository.
Right.
So pretty much just like a copy of the repository I have on my machine just hosted somewhere else.
I can use a remote repository and send my changes over there.
We talk about working with remotes.
We're really talking about, like, how can I take my code from on my machine and share it with somebody else?
And then I can just take my code from my machine and share them to another space.
Again, that remote repository might be like a cluster inside of my house in case, you know, that's the thing that we want to do.
Or it could be, again, inside of GitHub or GitLab.
All right.
So let's talk about how you can set up your remotes in Visual Studio Code.
Well, one, when you get in clone or if you clone a repository, which you can do from the command line or command palette, rather, excuse me, you can say git clone.
And then you would paste in the repository clone.
Whether you're doing it by HTTPS or SSH from GitHub, you can do it that way.
Or if you're signed into your GitHub account in Visual Studio Code, you can choose this other option clone from GitHub.
I'm going to go with this one for this case.
I've already have it available.
I've already cloned this locally.
But if you hit enter on this, it would step you through the process.
It would pull down all the assets from the remote instance of that repository locally to your machine.
And then you can begin working on that project more.
So because I cloned it from that remote Visual Studio Code behind the scenes.
I already set that up as my remote for me.
If I want to manage that though a bit further, I can bring up the command palette again.
And I can say I want to add another remote.
Maybe there's another fork of that repository under my personal account versus one under Cecil's personal GitHub account.
And I want to use that as one remote and push changes there before I push them over to Cecil's.
Because maybe I don't have permission to push to Cecil's repository directly.
And instead I got to push to my own.
So I can change the remote to be that fork instance of it and so forth.
Or maybe I need to remove a remote.
Maybe I'm done working on that project.
That type of thing.
I can go ahead and do that.
I hit enter and it shows the options of which remote repositories I can remove that I have active within this project in Visual Studio Code.
In this case, it's just the one.
It's the origin one that I have from GitHub.
So as you can see, like there's tons of different things that we can do related to source control, related to Git inside of VS Code.
And I know we just kind of ran through a whole bunch of different things.
But the main point of this video was to make you understand that whether you're using the command line or you're using some of the built-in menus or the command palette, you have different options and Visual Studio Code is here to help you as you're trying to navigate your GitHub workflow.
Now, in the next video, we're going to go a little bit more in depth in terms of viewing changes and showing you how Visual Studio and some of the built-in things inside of the editor makes it much more apparent and really nice.
so you can see exactly what's happening inside of your repository.
|
|
show
|
6:12 |
One of the things I really love about the Git integration side of VS Code is that not only does it allow us to pull down and commit changes, but it also allows us to see what changes were made and collaborate a little bit better with our teammates.
So what's happened so far, what we're going to take a look at now is that Brian and I have been working on this API, and I made some changes on my machine.
So now on Brian's side, he doesn't have my changes, and so he had to go and pull them down.
But obviously, it might be useful for him to know what exactly I did change.
So luckily, inside of VS Code, we have the ability to kind of look and have these little annotations and these little hints inside of Editor that allow us to see that.
So Brian, why don't we take a look and see some of those changes that I made, and we could kind of take a look through how the Editor visualizes those things.
Absolutely.
So one of the things to help people understand that we didn't visualize in a past video or demonstrate in a past video is the status bar.
We were covering it.
I moved the Editor.
So that we can see it now.
We can see which branch I'm on.
In the bottom here of the screen, I'm on the main.
If I want to synchronize changes, meaning I want to pull down any changes and at the same time push changes up to the remote repository, I can click on this button.
So that's what I did to get Cecil's changes that he made.
And in order for me to see specifically those changes, well, I can just open up the files and start looking at what's going on here.
And in particular, with the Git lens extension that we talked about previously, that offers up little annotations on each line that gives me details on that.
Well, who made those changes?
What commit affected that line of code?
In this case, Cecil, an hour ago, made a commit that impacted this line of code here.
Oh, and I just changed it by accident by pressing the wrong button.
And he put a commit message of update status router.
And when I hover over it, you can see some more details about that.
Again, this is all provided not natively by VS Code, but through the Git lens extension that adds these nice little touches on top of your project.
So one of the cool things that I love about it, and Brian, if you highlight that change that you did just now, like highlight that thing.
So notice, if we can go on a line-by-line basis, and we can see what exactly changed on this specific line.
Obviously, we could go and see what changed in the whole project.
But if we're going down on a line-by-line basis, we can see that.
And I'm actually kind of wondering, those...
icons or those little things that are highlighted in blue, can we click on those?
Like, can we click on that little hash or one of those things and see like some more context?
Yeah.
What does that do?
That brings up the Git lens inspect view on the sidebar.
And now I can see the commit details from one hour ago.
I can scroll through, look at files changing.
I had the unit.
Well, I have an extra extension that does some AI stuff.
We get line history on that particular line.
We can look at the whole file history.
And more.
We can search through the commits, all kinds of great added features that Git lens provides when you're using Git as your source control management system in VS Code.
And so that's one of the great things I love about like having that collaborative power inside of our editor.
So again, I can make changes on my machine.
Brian can make changes on his machine.
We can merge them together.
We can see who's making what changes.
We can see what changed.
And then now we can continue to collaborate in different places on different parts of the world.
And all.
And that's what we're doing within the power of VS Code.
It just kind of makes it a seamless experience.
All right, Brian.
So why don't we go ahead and make a change, an additional change to the status writer that's here?
Okay.
So on top of that annotation, right?
Why don't you add a comment?
And inside of that comment, let's just say, you know, set routes to the default route, right?
Essentially, that just means that whenever I hit slash status, this is the this is the method that's going to get invoked.
Right.
Because for folks that are familiar with using, you know, web APIs and routers, it could be like, you know, a slash get or slash do this or slash do that.
But this one's just the default route.
So we're just adding a comment to let, you know, other teammates know that this is what's happening here.
Yeah.
And that way, when when somebody uses this function, maybe somewhere else in here, if they wanted to, they know what that is intended to do with little annotations over the top.
Right.
VS Code will provide that.
Now, the one thing that I want to call out now that I made those changes, one, Git Lens is showing their little inline annotation that I made that change 24/7.
Four seconds ago and it's uncommitted changes.
But VS Code, what's built into it natively is this little gutter indication that's showing that I have made some changes.
It's this blue based on the theme.
It's that's what's deciding there.
And then I can click on it and see the diff of what what's what those changes entail.
And so we can see it goes from red, which was nothing to green the comment there.
So that's what VS Code does.
But the other thing that also ends up happening is in the source control view on the sidebar from the activity bar on the sidebar.
So if I go to the side panel, rather, you can see the changes that are pending.
They're not staged yet for commit.
But if I wanted to.
I can do that.
Another way that VS Code indicates these Git changes, source control management changes is by annotating or not annotating, but highlighting that file in a different color based on the theme.
In this case, it's like a tint of orange or so.
And then there's also an M to indicate like it's been modified.
Right.
And when you hover over it, you can see that detail, too.
So that's what VS Code shows and indicates to you changes you've made that are affecting your source control management system and your project history.
Now, in the next video, what we want to do is talk about how we can manage pull requests.
For folks that aren't familiar with pull requests, it's kind of like saying, hey, I made a change and I want you to review it before we merge it.
In this particular video, I was a little bit gung ho.
I was just like, take my change.
Right.
Like, that's just kind of what it is.
In the next one, it's we're going to be a little bit more polite.
A little bit more developer etiquette.
So I'm going to create a PR.
I'm going to send it over to Brian.
He's going to review it.
And then we'll see using the GitHub pull request extension how we can merge those in.
And now we can continue with our workflow.
|
|
show
|
5:15 |
So one of the things that we want to do as developers, particularly when we're using Git, is sometimes you want to be able to create what are called pull requests.
Now with pull requests, I can create a separate branch, I can make some changes, but I might want Brian or one of my other teammates to review it.
So how do we do that?
Well, I went ahead and created a pull request and now using the GitHub pull request extension for VS Code, you can go in and install that from the extension marketplace, and we've talked about that in previous videos.
You can go ahead and create pull requests inside of VS Code, you can review them inside of VS Code, and you can pretty much assign reviewers and do everything inside of VS Code, right?
I hope you get the point there.
We're doing everything inside of VS Code, and we don't have to switch contexts going to different browsers or windows or anything of the sort.
So Brian, why don't we go ahead and take a look at that pull request I sent and show folks how we can work with those things in the editor and then merge them and kind of keep our workflow going.
- Sure.
So I was just showing it in the GitHub marketplace extensions view.
If you wanted to search it that way, this is the official one from GitHub.
I already have it installed.
I'm gonna go over to it.
When you have it installed, you'll see the little GitHub icon in the activity bar.
If it's not showing, it might be in these additional views that you would slide down through in there to open it up.
Now, once I do that, let's close this tab, you'll notice that there's pull requests and then there's issues.
And in this case, we wanna look at the pull request and automatically, if it's not showing there for you, you can click the little refresh icon in the top of that collapsible region there, and then it should show up in all the open PRs that are there.
And now I can see Cecil's PR.
I can click on the description and read it directly, guess where, inside of VS Code.
I could see what the PR is about.
It's adding a custom header, the branch that's being used for that.
What's really nice about this is I don't have to go to my terminal to do the whole git commands to pull down, check out this branch, pull it, get the latest changes, and then start being able to review it and run it locally.
I can just click a button directly in this view right here.
I'm gonna do it right now, actually.
It's fetching that branch, doing it for me.
It might notify you to periodically run git fetch if you'd like.
I'm gonna say yes for now.
And then it automatically brings me right to the changed files.
This particular file, status router.py, is what had changes that Cecil pushed to this branch and opened up the PR for.
Now I can review them.
I can add comments by clicking on the little plus sign or the plus icon in the gutter area in the editor here.
And now let's close this so we get some better room.
Do that again.
And you can see I can start a discussion.
In here I can make a suggestion.
All these things you might find familiar, if you're familiar with GitHub, and you're using that as your source control management system and the UI on their website, a lot of, pretty much all, at least that I've had to use as a developer operating within a project and doing things within a PR, all those capabilities that I'm used to using there in the UI, I can just click on that and it's done.
And I can see that the UI and the website are found here in VS Code, allowing me not to have to switch contexts, and therefore just staying within my development environment.
So I can start a discussion, make a suggestion, start a review, or just add a comment on here.
So I'm gonna say, hey, this is looking good to me.
Add that comment.
But I'm gonna start a review.
And what that does is it puts it in a pending mode until I'm ready to officially send the review over to Cecil.
I'm gonna say go to review on this.
And in this case, I can say, I can see what other comments maybe I had or as part of that review, I can send it as I wanna request changes.
There's a different statuses that you have with GitHub, right, when you're reviewing a PR.
You can approve it, you can request changes, or you can just submit a review like standalone.
So in this case, I'm gonna approve it.
That's great.
So you do it all right in Visual Studio Code, Cecil.
Isn't that amazing?
Like I don't have to jump out of anywhere.
Maybe it looks so good to me that I'm ready to merge this.
I can merge it from here.
I can choose what type of merge method I'm using.
Maybe it's a merge commit, a squash and merge, a rebase and merge, all that fun stuff, right in Visual Studio Code.
Or you know what, Cecil?
I'm sorry, but I can't accept these changes.
I'm gonna have to close the pull request, man.
- No way, no.
So I'm gonna have to submit another one.
Is that what you, are you gonna do that to me, for real?
- Yeah, or Michael might merge it on us.
- Oh.
Michael, leave our PRs alone, please, and thank you very much.
But folks, hopefully you've seen how just staying within the editor, staying within VS Code allows you to work very easily with Git, with GitHub, and you can create PRs, you could submit PRs, you could review PRs, you could look at changes and branches and pull requests, and all these great types of things.
And again, this is just additive to your workflow.
If you wanna use the command line, you could still do that.
If you wanna go into the browser and use GitHub, GitLab, Bitbucket, whatever, you can still do that as well.
This is just another option for you to add.
So depending on how you like to work or whatever your preferences, you could pick your poison, right?
You can kinda choose the way that you wanna do it.
- Yep, and with that, folks, that will conclude this section of the course.
We'll have one more video to kinda do a rehash, recap of what we learned in this section, and then you can move on to the next one.
Thanks.
|
|
show
|
3:03 |
All right, folks, we've now come to the end of this chapter, which talks about source control with Git for Visual Studio Code.
Now, in this chapter, what we did was really just give you a really quick summary around some of the things that VS Code supports for GitHub.
As you can see, you can still use your regular terminal commands if you wanted to, but there's also tons of other options for using the menu or looking at the different editors and see different highlights inside of VS Code that makes your workflow a little bit better.
We talked about the different actions you can take within Visual Studio Code around source control management, whether you're using Git, which is natively built into Visual Studio Code or other source control management solutions that are out there, like SVN or whatnot that you would add to it via plugins or extensions in Visual Studio Code Marketplace.
We also covered how you can sync your changes back and forth.
If Brian and I are working on a project together, we're completely different places.
We can make use of remotes to either send them to a centralized server or GitHub or maybe using GitLab or Bitbucket or whatever the case is.
It really doesn't matter.
VS Code is able to sync your changes back and forth between those projects.
You can also take a look and see what your other teammates have checked in or committed, and then find a way to integrate those into your personal workspace.
Last but not least, we demonstrated the use of the GitHub pull request extension, pull request and issues extension rather, that enhances this, and it's a great way to get your users to use the extension.
You can also use it to create a new feature set and the overall experience when you're interacting with GitHub in particular, as your source control management solution for remote repositories that you would have, where you can look at the PRs directly in Visual Studio Code and do those types of things that you normally would have to switch contexts for by going to your browser and understanding more about that pull request that you are assigned or want to review.
You do that all inside of Visual Studio Code with this extension.
I'm going to be honest with you.
So Brian, I feel like you use this extension a little bit more than I did.
I only started using it for the course, but now I think I'm hooked.
I'm going to start using it to the side of all of my projects.
There we go.
I'm glad I'm glad I could help you.
Now, before we let you all go, we want to give you a couple of resources to enhance or further your education and knowledge around source control management.
Now, before we end this video here and move on to the next chapter, we want to share two resources with you to help you further your knowledge and education around Git.
And if you like, right on this platform here on Talk Python, you can see the course.
It's up and running with Git to help you learn more about that type of tooling that you can use for source control management in your projects.
Visual Studio Code also has a resource up on their website that will intro you further into Git inside of VS Code if you'd like to read up on that or use it as a reference.
And with that, we're going to move on to chapter nine, which is going to be the course conclusion, rehash all the things and recap all the things that we learned throughout the rest of this course that you enjoyed so much.
And I don't know why I added that.
But we'll keep that in there too.
Have a good one.
See you in the next video.
|
|
|
6:05 |
|
show
|
6:05 |
All right, folks, you made it.
It's the end of the course, and we really want to thank you for making it this far and watching all throughout all the videos, all the chapters up to this point.
We're going to leave you with a couple of things to recap what we and summarize what we covered so that you can reinforce that information, some resources and ways that you can get in contact with folks if you have questions as a result of the course.
So let's start off with the recap, Cecil.
First of all, we started out with getting set up, right?
What do we cover in that one?
So we just talked about like some of the basics, right?
Like, you know, making sure we have Python on our machines, making sure that we have VS Code because, well, it's a VS Code course, right?
We might need to have those things on our machine.
And then talking about the different operating systems that supports and like all of these different types of things.
And I think we even talked about the different versions of VS Code, right?
Like we talked about insiders a little bit.
We talked about like the main train version.
Right.
And stuff like that.
Yeah.
After that, we dove deep into the editor to understand it visually and all the different capabilities within it, the menus, the options that are there, what the names are of the different components visually of Visual Studio Code so that we can get acquainted with it and understand when those things are called out later on in the course.
Following up on that, we dived into editing code.
So what's it like?
What's the experience like out of the box writing Python code in Visual Studio Code?
And some of the things that can make that a bit of a richer experience for us as Python developers so that we can make our workflows as efficient as possible.
And after that, Cecil, I think you talked about managing environments in Visual Studio Code, right?
Yeah.
And then when we talk about environments, we're talking about like your workspace, right?
And that could be a little confusing, right?
Because VS Code has a concept of workspace.
But as developers, we have our own, you know, somewhat implicit workspace as well, right?
Like, where do our code go?
Where do our assets go?
And so we talked about some of the different options that are available for Python developers using VS Code to be able to manage those things effectively.
Excellent.
After that, you learned about running and debugging Python in Visual Studio Code, what that cycle and workflow is like.
And Cecil, anything more to add to that?
Yeah, I kind of just figured that, you know, if we're going to write the code, we may as well debug it, maybe.
Might be a thing we want to do, right?
But again, when it comes down to debugging, some of the things that like make the Python extension a little bit more, like the code itself, but we're going to need to do some more of that.
So, you know, the first thing that we're going to do is we're going to build in a little bit more of a code from the application.
So, we're going to build in a little bit more of a code from the application.
And then we're going to build in a little bit more of a code from the application.
And then we're going to build in a little bit more of a code from the application.
And then we're going to build in a little bit more of a code from the application.
And then we're going to build in a little bit more of a code from the application.
So, that's kind of the first step.
And then we're going to build in a little bit more of a code from the application.
So, that's kind of the first step.
where I just run the application, print the thing.
Oh, did it change?
Run the application, print the thing, right?
So even though VS Code is an editor and not a full-fledged IDE, these are just some of the features that we still expect to make our development cycle a little bit more efficient.
Quick note on that, I have a confession, Cecil.
To this day, I still have like my knee-jerk reaction to debugging something is to write a print statement to like log it out.
And then I realized, oh, I should use these resources that make this a lot simpler for me.
So I'm glad you called that out.
It'll be a further reminder for me too to use that in my workflow.
I'm just trying to help you out, man.
That's all.
That's what friends are for.
Yeah.
Then once you had your code running and you're debugging it, maybe you want to write some tests, right?
And how do you learned in that module with Cecil, how to test your code and how to set that up in Visual Studio Code?
What are the extension capabilities that you might want to use to enhance that experience and so forth?
Anything I'm missing there?
Yeah, no, you hit it right on the head, right?
Like we talked about like test discovery, like how does VS Code discover tests?
You know, we talked about the different test frameworks it supports.
And also like, again, some of those other features that we kind of build upon in the last one, right?
How do I run and debug my tests?
Like, what does that look like?
You know what I mean?
How do I look at my test results?
You know what I mean?
Like, how can I, you know, use those little code lens hints to see what exactly is happening in my application?
And then how can I, again, use some of the, some of the tools I might have been using outside of VS Code in VS Code and then, you know, bring a little bit of sauce on it to make it a little bit more efficient for me.
And to close things out with the course, we covered source control with Git.
Cecil and I stepped you through what that experience is like working on a team, for instance, where you have a remote repository that somebody else is pushing changes to.
How do you get those changes down through Visual Studio Code and how Visual Studio Code provides a lot of the source control capabilities directly in the UI of the application?
So, you know, if you're a developer, you can use the built-in terminal and Visual Studio Code to do a lot of the work of it.
Or if you'd like to directly, you know, keep going with the terminal-based approach with your Git commands and that sort of thing, you can use the built-in terminal in Visual Studio Code.
Many different options.
And that's the theme throughout this with Visual Studio Code is it wants to just be an editor or it could be a full-blown integrated development environment for you, depending on how, where you want it on that spectrum in that scale when you're working on your project.
So in this case, when you want to enhance that, you pull in plugins pull in extensions that will help that are geared towards Python development.
And that's the overall theme we're hoping to get out of this course is that VS Code can be made your own and help you be efficient and productive as a Python developer.
If you all have any questions or if you want to share any feedback with us about the course, we'd love to hear what you think.
We'd love to hear what you've built and learned and, you know, what has happened since you've taken this course.
Definitely feel free to contact us through folks at TopPython at this email that's floating above my head.
Magically right now.
Again, let us know what you're doing, what you've built and like what you've thought about the course in general.
Yep.
And that's it, folks.
We want to thank you again for watching this long, taking the time in reviewing and viewing this course and learning from us.
We hope you enjoyed and got a lot of value out of it.
And maybe we'll see in the next course.
Thanks.
Bye, folks.
|