42 PyCharm Tips and Tricks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay let's have some fun hi everyone and welcome to today's webinar organized by JetBrains maybe you've thought I spent a lot of time in pycharm and gosh if I just learned a few pro tips I could be so much more productive and you're right if so this webinar is for you today we're covering 42 PyCharm tips and tricks productivity boosters that speed up your python development and help you get into the coding flow we're all about getting into the coding flow if you'd like to follow along this URL helpfully labeled follow along is a repository with the code samples I'm going to be going through as well as a link to a playlist that we'll talk about a little bit later so go ahead and follow that along this is the repository that I was talking about on github this is the URL it's also here github.com slash Paul Everett 42 workshop you don't really have to follow along but if you'd like to that would be probably a better way to learn additionally there's this link and this is the surprise the big secret every tip every one of the 42 tips in this webinar has a page associated with it for example the very first one we're going to cover find action has an entire page with a short video a write-up links to related things an in-depth discussion with extra information and then me narrating a 30-second 45 maybe a minute video talking about the things discussed up here that will let you just relax pay attention learn and then if you want to follow up on the details come back to the playlist later all right here we go going over to pycharm let me go ahead and close some of these and each one of the tips are numbered or a module that's numbered in the 42 directory and we'll go ahead and begin tip number on fine action the tip of all tips I am a man of a certain age I can't be counted upon to remember any new thing because I will have to forget an old thing I can't remember shortcuts anymore let's say I want to find all instances of the string marry in this directory find in path what's it shortcut who knows how should I know instead use the one action that gets you to all other actions which is find action and this is on the Mac command shift a and let me make sure that I've done yeah down at the bottom you'll see as I go through this something called description of actions the presentation assistant plug-in that I use for my presentations and it tells you the name of the action and the keyboard sequence so in this case I want to do find the action command shift a and I'm covering that up but I now say okay I don't want to remember find in path so I'll type find in path oh it's shift command F I'll hit enter I'll type Mary and it shows me at that location in the directory tree all the files with the name Mary I could double click on it to go open it now some variations on this sometimes the thing you want to go find the action you want to find is kind of long like find in path don't want to type all that instead use speed typing and type parts of each word fi PA look it's the first one fine and path speed typing in hump case and other names speed typing is something that will be very frequent in this webinar and all of these tips is a way to speed you up little-known tip you can find not just actions but preferences will see this in the third tip but for now let's say I want to look at the Python imports preferences import preferences I could go down to this one and if I just hit enter right now it will toggle that preference from the on status to the off status a pretty cool way to quickly change a certain preference back and forth all right that's the first one fine action let's go to the second step reduce clutter it's all the rage these days getting into Zen mode having an editor which doesn't have a whole bunch of stuff on the screen we are an IDE integrated development environment we do a lot which means there's a lot on the screen but if you want to have that kind of lean and mean mode we can have that as well and that's what we will show in 42 tips and tricks so I'm going to turn some of this stuff off I'm going to turn off the tool bar I'm going to turn off the tool bar to a windows bar I'm going to turn off the status bar actually now I'll keep the status bar but I will turn off the navigation bar and I like that one and now I get a little bit more of a Zen mode because I've done these three actions and from this point forward I'm going to learn some of the tools to make those things appear only when I need them not have them in my face all the time all right here we go the big one doesn't you see I've got tabs up here people like tabs and I walk up to I see people that have you know five thousand files on their Windows desktop and four hundred tabs open and Chrome and you got a wonder can you really keep all that in your head we're going to show a mode of development which is Tablas turning off these tabs and using other techniques to move around in your code and to get to the thing that you want to get to so how do I change the tabs behavior and change it from placement top to placement none I can go to preferences and go to editor and then what's the next one general editor tabs and then change the placement from top to none or and you can tell because I forgot the path to get to this that was a lot of work instead let's use the tip we saw before find action can also change settings for some of your preferences so I'm going to look for window placement none and you see how I did speed typing on that to only get to the thing that I needed and when I hit enter my tabs go away because that preference was set let's see that one again we see now that is changed from off to on because I used find actions to select a preference and then to actually change the preference in the middle of find actions pretty cool now at this point I've got my layout in a pretty good mode we're gonna do one more big thing we're gonna turn off the project tool because I don't need to think about files that's another theme in this webinar navigate by code not by files so I could turn that off I can go into full-screen mode and let's let's admit it this is a pretty nice workflow everything is lean and mean so I need to get to that let me turn project back on okay I'm going to go to recent files because I need to show you one or two other things before we can turn off the project tool recent files command e ctrl a this is the first one the first tool that lots of people turn to for jumping around in their code and not having to double click on files open directory trees have tabs go back and forth so for example I want to go to the last file that I just visited and that happens a lot in development you're developing one thing that imports another thing you're jumping back and forth between the two command e OOP wrong way command E brings up this dialog called recent files and it defaults to be the not the one that I'm sitting on but the last one that I was sitting on and if I hit enter I jump back and forth between two things that I'm working on or I can go further back using my mouse or my keyboard to get to that one or go back to the one that I was on or much better I can use speed search so command e so2 jumps me to reduce clutter or I could have said reduce clutter or I could have said CLU and it filters the list to match the speed search condition this is a pervasive idiom in our IDE and all of our ideas when confronted with a list don't use your mouse don't use your down arrow start typing and filter the list and there's also a variation which you can see from this checkbox maybe you don't want to do just recently visited but only recently changed so there's a variation of recent files which is recently changed files and I can get to that with command e alright we also can do getting to tools so I turned off the project okay I turned off the project tool how do I get to it I could memorize a shortcut but I'm tired of memorizing shortcuts I want just a couple of things that can lead me to the other things in this case I can use recent files but you may have noticed in this left-hand column those aren't files those are the tool windows that I turned off when I was doing reduced clutter if I start typing at this point for example terminal then I will open the terminal that is the way I get to the terminal 500 times a day command goodness command e ter enter and I have my terminal now navigate symbol and navigate file gets into the heart of the matter and I'm going to leave the project tool open a little bit more until we get down to the nav bar stuff and to show you how you can get back to files navigate simple you don't want to navigate your project by code or by files you want to navigate by code who knows what that file name is who knows what its parent in grandparent directory was who cares it's got a class in it and I know the name of the class and I will jump to that by class name not by file name so for example I've got a class called greeter that's in 42 models which I import from here that's imported and under Annette so there's this thing right here and I want to go jump to it well I could go and double-click on here and then find out well it was actually in there and then scroll down to the class and then I've forgotten what I was doing instead navigate by code not by files in this case greeter is a symbol and one of these shortcuts alt command Oh will find not by filename or anything like that assemble so if I start typing greeter it will find I should say greeter it will find that symbol and if I hit enter it will open that file and put my cursor directly on the line that defines that simple and now I've seen everything I need so I want to go right back to where I was and recent files will put me right back where I was now what's also interesting and this is the difference between an IDE integrated development environment and an editor we index your code in your project but we also index the code in your dependencies to allow you to navigate to symbol for anything anywhere so for example I've got something called a service registry in one of my dependencies and I want to go jump to that symbol so I can bring up navigate to symbol and type in parts of service registry and there I have a dependency called wired there's a module in there called container and that defines a symbol called service registry when I press ENTER I go to the dunder Annette that defines service registry so go back with recent files and what that was showing when I did this search for capital ser capital or eg that this hump case camel hump speed typing also works as a way to narrow a list instead of having to type out service registry altogether okay onward that is Oh six let's go to navigate by file maybe you do need to look for the name of a file so for example oh one that's not going to be an assemble it's in the file name maybe I want to get to that and what we saw before when I did navigate to assemble you may have noticed that there are other tabs up here like the find action thing that we did in tip number one is just a tab its unified find anything anywhere a pop up window so we want to navigate by files and I type in oh one and there is or I could say s oh one and it finds the file starting with s o1 and I press ENTER and it opens that file and it puts the cursor in the last place I was sitting in the last time I visited this file what are some other things we can do well there's a richer speed type syntax let's take a look for anything for a file that has mo under a directory that has FO so I'll bring up find by files and I'll type fo slash mo and look there's my 42 dot models which is this file right here it's under 42 which starts with fo and then it's models which starts with mo I want to take a look at something in the dependencies to see if I can find files over in my dependencies that have a substring in them so I bring up that same navigate to file dialog and I type in pool m and look it's the pool manager file module in the URL URL Lib 3 vendor import of the PIP package and I could jump directly to that file as well so that's navigate to file we saw navigate symbol navigate file navigate action they are all variations of the same pop-up window that has a lot of the same behavior looking outside of your project speed typing hump casing directory path slashing etc alright navigate to cursor this is a fun one when you get into the flow a lot of times when you're debugging for example in our awesome visual debugger you will start going down a rabbit hole and keep clicking and keep clicking and keep navigating and keep opening and then forget where you were in last too short I can't remember what I was doing 20 seconds ago can my tool help me yes it can so for example I have this simple app and I'm going to use command B to navigate to symbol which is the symbol that you're sitting on and then I'm going to navigate to another symbol called service registry and then I'm going to see how to get back up to this spot and then change my mind and go back down to that spot so command B jumps to the definition of app here's something called service registry I'm going to do command B jump to its definition and I'm gonna make oh yeah okay I understand let's go where was I huh well tabs are off which is good but maybe the IDE if I do command left bracket will walk me back up the breadcrumb trail that I just went down oh wait no actually I wanted to be down there command right bracket will go back down the last breadcrumb trail that you went very very useful way to navigate without having to have files or tabs and keep all that context in your head all right activating the nav bar this is gonna be the sequence unless you want 6 tips all focused on the thing that I turned off I turned off the navigation bar did I turn it off because it's not useful no I didn't it's very useful I use it all the time but I don't need it all the time I just need it when I need it on demand so I'll turn it back off yeah and I will bring it up on demand temporarily use it and it will go away so for example I want I want to browse files and I've got the project tool turned off at long last and now I got plenty of real estate I could put my run tool window or my test window over here or something like that but if I do actually need to browse the files what am I gonna do well I could bring the project tool back up huh that's just no fun cuz then I got to turn it back off instead I could jump to the navigation bar using command up on Mac OS alt home on when licks so command up and look I get a little transient pop up version of the navigation bar which is preview it was previously a permanent entry in the tool bar and then I can dismiss it by hitting or clicking somewhere else either way I use escape now what can we do with that let me turn this back on before I do the big reveal this is the one where I get to turn it off I can navigate files with the navigation bar instead of this monstrosity the project tool window so for example let's say I'm sitting on s10 navigate files and I want to go to so9 I could hit command up to get the navigation bar I could go to the directory and I can hit down and go to that file which means I can turn off the project tool window and whenever I actually do want to think about files not symbols and I don't have anything in recent files to jump to or I just want to look around cuz I'm browsing not searching bring the navigation bar back up go to the place you need to go hit down choose the file and hit enter one little point this point is when you bring it up you may be tempted to if you want to go to a sibling of the current file like s not oh nine you may be tempted to go up to 42 but you don't have to sorry you may be tempted to go up to 42 and then down but you don't have to you can just hit activate the nav bar and immediately hit down and it will open the current directory you know in the little pop-up drop-down what else can we do with this turns out a whole lot I can for example now go to the next tip without having to open the project tool window let's say I want to open up on this one I just didn't open a file with the navigation bar I can activate the navigation bar find the file that I want to open for example this file and hit enter or I can go up down and hit enter several other we can do with that let's go on to tip number 12 speed search this gets a lot easier after this when I'm in this navigation bar and I've got a long listing we mentioned that anytime in the IDE that you're faced with a long listing you can just be type so for example I'm about to go to s 13 I could type s 13 in here there or s 42 and hit enter so speed typing I don't have speed typing is a great way when you're using the navigation bar to quickly look at these little e that's not a word quickly move around your directories in your file system so I need to go now to s 13 what else can I do well just about anything that you want to do in the project tool window which we we don't like anymore so we'll turn it back off anything you can do over there you can do over here in the navigation bar without having to use the mouse and that's part of the whole point of this is Tablas and all this other stuff keep your hands on the keyboard so that you stay in the flow so I'm going to add a navigation bar here and let's say I want to go somewhere in the project tree like the route and I want to make a to-do txt file what would I do if it was the project tool I would click on that directory and I would do command in file type in the name and there I am and I'll say no don't know one but that VCS so in this case I used the navigation bar to go up to something I could have gone down to another directory back down into 42 whatever I could have gone into tests and then I could have created the file there all right that's creating a new file with the navigation bar what else we got with the navigation bar we can find in path the thing that we did and the very first step actually but we don't have to use the project tool window to do it so for example that will recreate the exact one that we did activate the navigation bar go to the place that I want to start searching and what's the key sequence it shift command F and it brings up finding path same thing we saw before and remember you can go up down into and then do your your search finding paths from anywhere any directory anywhere in your tree you may think hey wow that's pretty cool can I do other things like rename a file using the navigation bar not using the mouse sure of course I could go up to this file that I just made to do txt and I could do ctrl T refactor rename and upper case it to make it and make it a markdown file and I've refactored renamed that file again not using the mouse but instead using the keyboard alright that finishes the part about using the navigation bar let's move on to adding a line this is a tip that happens all the time my son writes Python games with me and he has to remember this one saves a lot of time what usually happens is let's say that I'm on this line and I want to put a statement indented on the next line usually what you do is use your mouse and click to the end or you what he does is buh-buh-buh oh I've got it wrong oh wait I got a I got it wrong hit enter and then you get the indentation or maybe you're a little faster and you got Emacs ki bodies or something and you hit ctrl e to go to the end of the line and then you hit enter instead there is an action start new line which is shift enter on all three operating systems put your cursor there hit shift enter and get kind of a smart start new line it understands the context what the indentation should be and can be run from the middle of a line here's one that I I struggled to remember this one and I fall back to find action all the time a lot of times I've got some code where there's an import and I want an import before this and I'm like here and I'm like okay I will go here's what I do I go to the end of the line hit my right cursor key up enter up and then I type the import which is all pretty done instead you can do and see I have to go back and get the start new line action alt command enter alts command enter adds a new line in the same concept of being in the right indentation but above the line that you want so if I'm on this line and I do alt command alt command enter then it will start a new line indented correctly above the current cursor position as you saw with me fumbling around ridiculously here's the way I do it all you have to do is find action and type what is that s DB e ste e start new line before current and hit enter let's do that again s tbe alright great alright so that's tip number 15 let's go on 16 may can extend selection let's say I want to select some code and my cursor is in the middle and I want to select these three lines here's what everybody does use the mouse and make a big block there's a little bit of an easier way let's say I want to select the whole block or the line or just the word or whatever you can make and extend a selection using the keyboard it's actually pretty easy alt up goes from the cursor to the symbol alt up again gets a little bigger alt up again gets a little bigger a little bigger a little bigger a little bigger a little bigger believable by oh that's too far alt down goes backwards now this can be pretty useful when you look at the next step moving a block I have a customer definition inside this context manager with thingy doesn't really need to be there it's not part of the context I really should move it up how would we usually do it triple click cut move enter paste all newline crud all that stuff instead use what we just learned and my cursor is somewhere in here I'm going to make extend selection to get the line and then I'm going to use move line up alt shift up alt shift down on Mac OS alt shift up and now I do tab to fix the indentation works for a block so for example if I had gosh we'll just do this whole block here I could move this whole thing out to there for example does it make sense but you can select a block and move a block at a time back to where you were that is a surprisingly useful tip that happens a lot selecting code and moving code do it without the mouse do it with your keyboard do it efficiently all right let's go on to 18 reformat code oh yeah this is the one that everybody does a trillion times a day I do it even when I don't need to do it just because it makes me feel like things are clean probably says a little bit about me so this code has three warnings plaques worm has set a warning here a warning here and a warning here so what are these well what are they always pep eight-mile Asians they're supposed to be two lines here got some white space that's not needed and then down here indentation is not a multiple of four it's only two spaces well I could be the janitor and go and fix these things okay now you let me do it now are you happy oh no now you're happy now are you happy okay now you're happy now are you happy all right good now are you happy okay good things instead life's too short let us be your janitor let PyCharm be a janitor reformat code alt command L Mac OS ctrl alt L on Windows one shot everything is formatted nicely no more pep eight violations I can improve that by clicking here no problems found reformat code covers a lot of things and it covers them according to the settings that you have for the project so you get to tell it what things you like all right nineteen optimized imports another janitorial task that it's awesome to let the IDE do for you in this case I've got some unused import import OS it's not used I have another import violation I have an unsorted import lists time should be after cess and maybe in this project I want to take multiple imports from the same module and split them into different import lines so optimized imports is right up there with reformat code something I do all the time on the Mac ctrl alt oh I've certainly worn out my keyboard on this one ctrl alt Oh watch carefully as those two line 24 line 25 line 26 change there we go import OS was removed as an import because it was unused and my imports were sorted correctly how can I get this let's say my projects style is to split these I can go to I'll skip the undo redo I can go to preferences because of imports and make that statement so here structure of from imports it's currently join imports with the same source always split imports I will do that and now when I keep an eye on this when I optimize imports its split and split sorted correctly alright janitorial work let the IDE do your janitorial work more janitorial work we want to random customer right instead of having Larry I want to get a random choice to assign customer from the list of customers and I want to use the Python random package in the standard library to do choice from random so one way I could do it is start typing random but then PyCharm tells me unresolved reference well that's not good I can let pycharm generate the import for me even better though we know not only the name of the package we know the name of the function start typing choice alt enter import this name from random and we see it generated the import using my import style guide but wait there's more what if it's like a long thing I want to import I don't want to type all that I could type this and do control space base and let it present to me an auto completed list of symbols from stuff in my dependencies or my own project and I can hit enter and it will complete the name of the function choice and generate the import so that it works I never come up here and type import let's look at what that would be like otherwise so I'm like okay Troy okay boys oh I gotta stop what I'm doing from Rand or shores what was I doing where was I oh I was down here life's too short to do that janitorial work okay on to 21 well let me get this so we don't see these errors anymore 21 install an import so I showed you how the janitor can do your work to sort your imports and get rid of unused imports the janitor can even generate your imports the janitor can even install the package generate the import for you from the middle of your typing so for example here I've got this thing called Maya that I've typed but pine charms telling me a unresolved reference Maya what can you do to help me I'll do alt enter which is our way into the universe of code insight and janitorial work alt enter well I could import Maya let's see so my mistake was forgetting to get rid of this from the last time I gave this so let me go to the project interpreter and delete Maya and write down that all right so now I've got some code where I've typed in Maya but not only have I not imported it I actually haven't even installed it so when I go to alt enter I don't get any intentions because I did this in the middle of removing it from the project what you would see otherwise is and this is the peril of using an EAP alt enter would bring up an option to install and import the package Maya all right onward adding fields this is one that you'll use a lot if you do a lot of class programming I've got a class customer and I want to initialize it with something called name and store it as an instance variable here's what it looks like the dumb way comma name and then self dot name equal name that's a lot of typing and things like types grits and Python data classes make this a lot easier but if you can't use them what you could do instead is do name alt enter and say hey IDE janitor help me out on this add a field called name to class customer when I press ENTER the first thing it's going to do is maybe I want to rename it to first name and then when I hit enter it accepts everything and it's stored on the instance Reena a file and this was something I was at a conference last week and so I said oh wow I got to make this change and then I've got to go look everywhere and rename the imports no let the janitor do it for you so for example in this file I'm importing something called models but it's only got one thing in it maybe I want to call it model singular and then I think so I'm gonna go to 42 files and fix that maybe I'll just leave it as models fortunately refactoring like that becomes a lot easier with an IDE that looks at all the code in your project I will bring up the nav bar go to 40 to go to models and then I will refactor rename and call this model and I'm going to tell it to search for references don't search there but just search for references to rename the file and all of its usages so it's looked everywhere it's done that it fixed the name here it even fixed get and VCS to do the rename there and you can see that it actually renamed the file because now I have model and then I realize wait no that's dumb because I'm about to add another model and it'll be floral again wouldn't it be nice if I could just undo the naming of the file the renaming of all the imports and the VCS ad that was one IDE transaction so undo undoes the refactor renaming not just of the file but of the imports and the VCS puts it back exactly the way it was before I did refactor rename rename symbol so greener I've got something called greeter but maybe I want to call it welcome er cuz that sounds more welcoming in same kind of thing I think I've got 42 files with this in and I don't want to go to 42 files to do all that renaming I'll just leave it the way it is Oh do what you want go to navigate to the symbol cursor is sitting on it refactor control T then choose rename and call it welcomer hit enter looking for all the usages and then when I go back to the file that I was just sitting on I see that what the class is the class is being imported is named welcome or in fact when you so in recent files see that's all blue we'll talk about that later that means that those all change from a VCS perspective it changed everything because everything uses welcomer now I realize I hate welcome our greeter was better I want to go back to the way it was same thing applies undo does an entire IDE transaction changes not just the name of the symbol where it was declared here but all the imports that used it as well this is a pretty good in will I'll show one more thing I was doing this by refactor rename by going to the class and doing refactor rename there but I could actually do it on a usage of the class I could put my cursor right there say refactor rename welcomer hit enter it's gonna look for everything and now when I go visit welcomer I see that it did it same rules apply for undo undo renaming class etc this kind of an importing important part about the difference between an editor and an IDE we index everything and that's that lovely little indexing thing that you get when you open a project and what that gives you is symbols instead of strings we can operate on symbols for example if I made a new file called bogus and in there I put class greeter and I did a rename to welcome err if I go look at bogus it didn't get changed just because the string matched the symbol didn't it's a different symbol in Python so let me put this back to the way it was all right it's been a little extra time on that one because I like it quick documentation how often does this happen to you you see some kind of symbol like choice what's that stop what you're doing you go look at the import I'll get random that's in the what is that again is that in the Python standard library or one of my dependencies I think it's in the Python standard library open up a browser Google from the lovely by now you've totally out of the flow forgotten everything instead would it be nice if your IDE could nan the shrubs not disruptively pronounce words non-disruptive lee show you a little bit of documentation about the thing that you're sitting on so in on the Mac that's f1 my cursors on choice I hit f1 it's fetching the documentation tells me what the signature of of it is the dot string and a little bit more information including a link to jump directly to that in my browser a little variation on that parameter info so for example choices is kind of weird don't know what it wants so I'm sitting here typing and what are some of the things that I might be able to get from this I want to view parameter info which is a few parameter info so I'm sitting in here if I do command P on the Mac or ctrl P on windows links it tells me what this crazy statistical joycie thing wants and I can say customers and as I type the bold is moving to show me the parameter that I need if I move back to here it tells me that over to running code we've done a lot about editing code and navigating code let's talk about running some code using the keyboard instead of the mouse I turned everything off I don't have that tool bar up there that I love so much that lets me click to run things but now I'm going to run things from the keyboard so for example let's say I've run this and I want to rerun it control or reruns your active run configuration so it runs it again but what if you want to go to a different run configuration well that might mean something like turn it on baby toolbar go and find the drop-down selecting it making it active and running it but there's another choice when you look under the run there it tells you some of these other choices so for example ctrl alt R is the one I do all the time ctrl alt r brings up a little non-disruptive pop-up window that lets you for example run this one instead or I want to run that one instead or I want to do more than just run it I hit right arrow because this has a submenu I could debug it I can run it under coverage I can edit the run configuration or I could delete it so lots of things that are possible from that and in fact there's another thing that I do quite a lot which is speed type 25 right that's the way I switch between especially in test running that's the way I switch between run configurations alright let's speed up a little bit I've got some conditional breakpoints I'm debugging but I only want to only want to stop in certain points so I'm in the greeter but I want to stop only when I'm greeting Larry so I've got a breakpoint here and if I run and once if I run it normally or I should say debug it normally it will run it will stop on that line and it's Alice oh crap okay next time oh it's Sam crap still Sam where's Larry Sam again oh this random thing it's always Sam it's never Larry come on keep going until it's actually going to be eventually Larry so instead I can control click on the breakpoint come to this thing called condition and type in a condition only when the value of customer equals Larry do I want this breakpoint to stop note that it remembers some of the previous things that you've done so now when I run the debugger we're gonna stop on Larry hey Larry alright so next let's do evaluate expression lots of times when you're debugging you stop on a great point you poke around unfortunately I'm not saying you do it but people have been known to use print statements as a way for poking around instead you can do evaluate expression so for example I'm going to I'm going to poke around before this line is actually run now put a breakpoint here and I'm going to debug this it's gonna stop on that line I want to see what that line actually does before it does it so I'm gonna highlight it and I'm gonna right-click on it and say evaluate expression it brings up this dialog box with that expression chosen I type evaluate and I get a result in fact I could do something like name equal and look in the background in my scope I have a new value or I could override an existing value so evaluate expression is a good way to poke around when you're debugging split-screen I love this one I like to do test-driven development TDD and I like to get into a mode where my code is on the left my test is on the right and the test runner is on the bottom and that kind of signals to my reptilian brain it's testing time baby so we want to do side by side but we turned off tabs how can we get two files on the screen without tabs you can use split vertically so I'm going to do the action split vertically another one I do all the time and I'm going to go up to my tests and here are my tests and good for example I don't get that out of there run my tests right click run tests and at the bottom I get my test output codes on one side tests on the other side test runner at the bottom nice and familiar how do you go from code to test so let's say I'm sitting here and I'm thinking all right I need to make a change in main well you know it's probably the last thing that you had open so you can use ctrl e commit or recent files to jump back and forth between things but if it isn't if you want to say I don't care which thing it is on the right just go to it I can use alt tab to go to the next splitter so if I've got it split into five windows alt tab will cycle through them to run a single test what if I just I'm focused on this thing just this one thing disable tabs and I don't want to spend time slowing down on my test running I can walk up to it and I can say run the tests or I can right-click anywhere in it and say run the test and in this both cases I'm generating a temporary one configuration you can tell it's temporary because it's got a ghosted icon for running those tests all a run this is the magic of TDD test-driven development I'm getting into testing mode and I I'm writing some things and I'm fixing some things and this is in 32 tests sorry - right and things aren't going as expected I run this tests and it fails or I make another change and I rerun it and it fails why are these things failing I want to have things run automatically as I fix things so I come over here I click on this button toggle auto test next time when I run it will run but as I type it will wait two seconds and rerun my tests until I fix it so I made a little change but it's not fixed yet now I made another change I didn't even have to save and it's fixed this autorun test doesn't even require me to save what's the toggle for setting the time I've got the delay on one it defaults to three so for example if I do that one two three and now it will redo it so that all cut becomes a factor of how long do your tests take to run or am i kind of deep in thinking and I don't know what I'm doing versus I'm just doing janitorial test work all right spot coverage we also have we have visual running visual debugging we have visual testing we also have visual coverage so for example I want to run this all my code and see the coverage and spot that I don't have any tests for foo how can I do that I can right-click in here and I can say run with coverage and it will chug along and chug along a little Oh gonna run the tests pause for a bit while it's collecting all the coverage information and we'll talk about this in a second and it will give me a browsable table saying well in the 42 package 75% or cover 90 the blah blah this thing is not covered at all and there's this file called these things aren't covered at all spot coverage the thing I'm on is 76 percent cover well I don't even have to look at this thing to tell why because the IDE visual coverage helped me it put color coding in the gutter to tell me what has coverage and what doesn't in fact I could click on that and get a little more information in some options about the coverage on this to speed up the coverage you can put a file in the root of your project to govern the coverage information and tell it not to look in your virtual environment local history this is the one that everyone let me unsplit everything and close this and go to my coverage tool and kill that suite to get rid of the color coding local history how to save your life when VCS can't save it for you maybe you're not using VCS maybe you didn't put something under control of VCS or maybe you made a really horrible change since the last time you committed and going back to the last commit won't help you so for example I'm in Maine and let's say I accidentally delete the whole thing and now I'm going on to do 407 other changes undo won't help me because the undo point is so far back that it's beyond the time horizon and I didn't commit so I can't get back to it instead let's bring up show history which is also available under right-click and local history and show history and it lets me for the file that I'm sitting on have a listing of every editor transaction back to a configurable point in time across everything in your project and then it gives me a diff showing me the current state and the state of that example or the state of where it was at that point in the state of where it was at that point and I can use the diff to recover from my mistake and we're all good again this will even handle files that are deleted via the ID so let's say I do this I'm like hey life's too short Yolo delete anyway oh my god I just deleted a file that wasn't even under version control yet I am so screwed no you're not because what you can do is go to the container and go to local history at the container level and the container knows that a file was deleted from it right click revert add it to VCS and I've got my models file back that's pretty cool create project from github and this takes a little bit of time and we're already at an hour so I'll speed up a little bit you can go to the verge control menu and you can say checkout from version control get and put in the URL to get to your repository or you can use it by fine action CH ve checkout from version control will take you to a dialog asking you which kind of system I jus just get same thing and what this is doing is going to get hub and looking for all of my projects and repositories across all my organizations that I'm a member of so for example I could start typing wired and autocomplete that if I don't have something under version control I can open an uninitialized project and then type in this sequence en VEC Oh check out or no oh that that's because this project is already under version control it would do the same thing as a menu option that would appear if this project was an under version control I do a commit it has a mistake in the message so for example I say re words and I commit I don't push I just commit and I'm like oh my god that was a stupid message what am I going to do now you can go to the VCS tool and see in the log tab this message and I can right click on it and then I can choose reword and take that off and it says if it never happened undo commit even worse that whole commit was stupid now what do I do do I go back in time find the hash of the prisoner oh my gosh I haven't pushed yet so the verse control tab can help me again select that commit and then go to it and choose undo commit now in this case there were some changes there they got to go somewhere the ID has a concept of change lists with a default change list or you can make a new change list that defaults to the name of the commit message or something else I'll skip that onward partial commit this is a fun one too this happens to me all the time I do a whole bunch of work and I'm like squirrel and go do some other work and I'm on a branch or I'm in an atomic commit and that had no business being in there so for example I could do commit and let me put a change in here and I go to commit and I want to commit the change in here but I don't want to do anything with this guy so let's say it was selected I only want to do that one so I would unselect choose that and maybe I also made a change up here but I don't want to include that so I would say only include this file and in here do not include that line in the commitment and then I would do commit two more to go run npm scripts this gets into web stuff so i'll turn back on the project tool so you can see it and i've got a package dot JSON in this project i can right click on it and i can say show npm scripts and get a little tool window here to browse and run in a dedicated window some of my scripts and what it's really doing is creating a temporary run configuration for that npm thing what's interesting is serve is actually the automatically discovered as an action and I could say run SE and it will go look at my package dot JSON in PM scripts and prompt that as something that's runnable last one nope next to the last one wrap with a tag let's say that demo because you know or spam will say span this is the web and everything has to have 57 divs on it I can use extend selection to select that line and I can search for an action surround width and then choose a tag and say div I could also use this Emmet thing this is even cooler surround with Emmet and say div columns and it will surround it and then autocomplete some of the information that's needed last one the part you just saw was because pycharm professional includes webstorm our ide for the web we also include data grip our IDE for sequel databases for development of sequel databases it has gives us this tool called database which is for wreaking magic and working with sequel Lite is magically magical I can I could say add datasource equal well I'm already confused or I could just take my database sequel Lite file drag drop it onto the database tool it will do the work to discover it the work to connect it and now I can browse and go to a table and do all of my magical visual database things that's your forty second tip don't forget that you can get all of these in the playlist alright so back to the presentation alright that was a lot of fun thanks everyone for sticking around going through this series of tips if you have any questions later please don't hesitate to reach out to us by email or social media hopefully we've answered most of the questions so far maybe you've got some ideas about a tip that I shouldn't cover it's one of your favorites if you'd like to get more information on pycharm please go to our website at jeb rains comm slash PyCharm we'd love your feedback on this webinar hint give me a high grade so maybe I can catch Michael Kennedy if you give me a high grade so please feel free to contact us on Twitter or in the after webinar survey the recording will be made available on our YouTube channel soon if you haven't already please check out our pycharm blog the blog you can find up-to-date pycharm news about releases and events in addition to educational resources so for example if you want the recording of this webinar it will be published there in a few days and we'll also tweet about it we'll also provide some additional links and information from the presentation on the blog for example the that's all from us today thank you very much for joining us staying until the end and hope you have a nice day you
Info
Channel: JetBrainsTV
Views: 58,124
Rating: 4.9490447 out of 5
Keywords: JetBrains, software development, developer tools, programming, developer, PyCharm, webinar, Python, tips and trick, tips, shortcuts, productivity
Id: NoDx0MEESDw
Channel Id: undefined
Length: 68min 8sec (4088 seconds)
Published: Wed May 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.