Productive Day: Website Deployment and Python Tool Enhancement

Automating processes and improving workflow efficiency

Posted by Michael S on September 16, 2024

Woke up at 10:05 today. Finished editing and updating a picture for a Macroaxis author in the codebase. Didn't get any articles done, so I'm expecting a barrage of angry clients when I wake up tomorrow morning. Fun times ahead.

2:47 PM: Git-based Website Deployment

Today, I implemented a Git-based workflow to deploy my website to my DigitalOcean droplet. All of this work setting up my website these past few days was just with the ultimate goal of running a single file that retrieves descriptions for every site in the Tranco list lol.

I created a custom post-receive hook script that automates the deployment of my website to the /var/www/smolkin.org/html directory. The script handles file checkout, sets appropriate permissions, and restarts Nginx automatically. I troubleshot issues with the initial setup, refined the script to use variables for better maintainability, and incorporated error handling. This project essentially involved resurrecting my website and making it easily editable.

By the end of the "day," (well, I can't really say "morning" now can I, it's almost 3 p.m.!) I now have a streamlined, one-command deployment process that significantly improves my workflow efficiency, all driven by the desire to run that one tranco-list description-grabber file.

11:06 PM: Python Tool Enhancement and Package Distribution

Later in the evening, after a breakfast of two eggs, some hummus, and a bit of salsa on chips, and a lunch consisting of a bowl of soup, I enhanced my Python command-line tool, super-grep, by implementing improved error handling for unexpected flags and adding a recommendation for users to include the -C flag for prettier output. I updated the tool's documentation and examples to reflect these changes.

Additionally, I reviewed (learned again) how to prepare my Python package for distribution by configuring setup.py, building the package using setuptools and wheel, and uploading it to PyPI using twine. I also created a shell function to streamline the PyPI upload process, which prompts for confirmation of a setup.py file and executes the necessary commands. In case you'd like to use this shell function, here it is:

function upload_to_pypi() {
                        read -p "Have you created a setup.py file? (Y/n): " answer
                        case $answer in
                            [Yy]* ) 
                                echo "Upgrading setuptools, wheel, and twine..."
                                pip install --upgrade setuptools wheel twine
                                echo "Removing old distribution files..."
                                rm -rf dist
                                echo "Building the package..."
                                python setup.py sdist bdist_wheel
                                echo "Uploading to PyPI..."
                                twine upload dist/*
                                ;;
                            [Nn]* ) 
                                echo "Please create a setup.py file before proceeding."
                                ;;
                            * ) 
                                echo "Invalid input. Please answer Y or n."
                                ;;
                        esac
                    }
                    

You can add this function to the bottom of your ~/.bashrc or ~/.zshrc file to simplify the PyPI app upload and update process.

Throughout the day, I strengthened my skills in server administration, Git version control (including creating a Git server and using it), bash scripting, Python packaging, command-line tool development, and process automation. But more importantly, it's nice to have a more efficient workflow.

11:40 PM: In closing

It took me 35 minutes to write this blog post and the surrounding HTML boilerplate. I think I'm going to try to make a habit of writing a blog post at least once a week. I'm getting the hang of this whole "actually publish your work" thing.

11:45 PM: What's next?

I'm not sure what I'm going to do for the rest of the evening. I think I'm done with the Python package for now. I'll probably work on my website some more tomorrow. Good night!

...12:05 AM: Git commit

I just wasted 10 minutes updating the commit message. So slow. There's no reason to do that. I need to learn not to lose time.

Enjoyed this post?

Get notified when I publish something new. No spam, unsubscribe anytime.