What does the structure of a modern Python project look like?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey folks serar here in this episode of Dev with  cerar we're going to look at the structure of a   modern python project how to lay out the files in  the directory what the most important pieces are   and how to keep things organized going forward  new python projects should whenever possible be   laid out according to the guidelines listed by  the python packaging Authority even if you don't   plan on Distributing your project this is still a  good idea because it gives you a set of standards   for how things behave and where people expect  things to be found to understand better let's   look at an actual project this is a project that  I've shown here from time to time in different   incarnations it's my implementation of Conway's  Game of Life in Python the first thing you'll ask   is where do I put my actual code all your project  code goes in a subdirectory named Source SRC you   can place your code directly in Source or you can  subdivide it into other directories for the sake   of name spacing parts of the project for this  one I have the core of my project under Conway   that's the main namespace and another piece  of it in render that's a component written in   scyon and compiled to C I do recommend using  at least one namespace directory as it makes   organization easier next we have files in the  root of the repository for python projects the   common and most important thing to have here  is the py project. toml file that's the file   format that's now used to store python specific  metadata about a project don't be intimidated by   all the things you see in this example if you're  just getting a project going these lines here at   the top are the only ones you really need the  project section declaration the name which is   the name that's listed for your project when you  use pip install to install it the version number   and the dependencies if there are any everything  else can be ignored for now there's a link down in   the description for the video about where to  learn more about what goes into a p project.   tomal file another thing that does appear in  the root of a python project is setup.py most of   what's now in py P project. toml used to live in  setup.py not all of it setup.py is run when your   program is installed with Pip and it contains  actual python code instead of just data to do   things that cannot be expressed in py project.  tomomo alone for instance in this project it's   used to compile that c extension module written  in scon so while setup.py is not mandatory it's   there for projects that need it and some projects  really do need it so the next set of items after   this these these are optional but common first  is your get ignore file used to keep some files   out from being checked into Version Control  you generally do not want to check in your   virtual environment you don't want to check in  any pie cach directories or any egg info files   those are generated by pip install I have a few  other file types and directories listed here but   those are specific to this project and uh these  three types are really the things that you need   to keep out of a out of out of Version Control  next is any documentation that goes with the   project in this case all I have is a simple  readme file in markdown format if you have   documentation that's autogenerated using Sphinx  or similar tool you typically place that in a   subdirectory named docs next is a license for  your code I do recommend having a license of   some kind even if you don't plan on Distributing  it you never know I have the MIT license as my   default it's widely used it's easy to set up and  customize and everyone understands it and finally   there's directories for tests one common way to  set up testing is to have a main module in that   directory so you can just run all your tests with  p-m tests my own test suite for this program by   the way is is exceedingly minimal don't take it  as a model for anything but the idea for how to   deploy it should be clear so to sum up modern  python projects have a few mandatory pieces   to make them compliant with python standards  the location of the code and the PIP project.   tomal file those are the two biggest things like  licensing documentation tests and so on can be   added after the fact and they should be but the  layout of the source files and the metadata are   the two things that matter the most and that's it  for this episode if you liked it leave a comment   below and don't forget to follow Dev with Sardar  and infoworld on Facebook YouTube and infoworld [Music] Doc
Info
Channel: InfoWorld
Views: 1,926
Rating: undefined out of 5
Keywords: How to code, Coding tutorial, App dev, App developer, Python, pyproject.toml
Id: Lr1koR-YkMw
Channel Id: undefined
Length: 4min 24sec (264 seconds)
Published: Thu Jan 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.