DEV Community

Kyle Homen
Kyle Homen

Posted on

OSD600: Lab 5

This week we are returning to working on our own repository context packager project in an attempt to refactor our code in a bit to improve code maintainability and practice rebasing and amending commits.

I had a lot of fun with this one. I like making really elaborate doc strings, something I didn't have time to do for the first release, so this was the perfect time to actually do that.

Before I could do that, though, I needed to split my one monolithic script into smaller modules. This is what I consider my first improvement, going from a single repo-scan.py file to this:

Screenshot of project files

First things first, I wanted to rename the main file to scan-repo.py. It feels more.. on the nose?

Next I broke the logic up into their separate modules under the directory analyzer/. I tried to test each module as I went but just kind of full sent it at the end and did a bunch of them all at once. Outside of breaking the logger for a bit (just needed to configure the logging BEFORE calling the config), I didn't have much trouble moving stuff around.

The second improvement I made was then breaking up some longer functions like content_output() and analyze_path_args() into smaller functions within a content.py or paths.py module. This also included some improvements to the code, and I moved or removed global variables that were no longer necessary.

And of course the third improvement was to add comments, doc strings and typing to all functions like so:

Code example

The interactive rebase went well, it was just a pain to use vim. People used to write code like this? Demonic. I was able to squash everything into a single commit, and amend that commit to make a cohesive and polished final commit message.

No bugs found yet.. I got ahead of myself and made a tests/ directory to write some unit tests but since that is something we're doing in the future I'll just wait and see (I actually didn't have time, but the manual testing I did went well).

Top comments (0)