DEV Community

Cover image for Maintaining a Python Package with GitHub Actions
Vinicius Koji Enari
Vinicius Koji Enari

Posted on

Maintaining a Python Package with GitHub Actions

What I built

A hangman game created using Python and distributed as a Python package through PyPI. It utilizes GitHub actions to test and lint the code whenever there is a push or pull request to the main branch. Additionally, whenever a new release is created, the new version of the package is automatically deployed to PyPI.

Category Submission:

Wacky Wildcards

App Link

Package on PyPI: https://pypi.org/project/hangman-package/

Screenshots

Demonstration of the game in GitHub Codespaces:
Demonstration

Description

The game can be installed using pip.

pip install hangman-package
Enter fullscreen mode Exit fullscreen mode

To play, you just need to import the package, create an instance of the Hangman class and call the play method.

from hangman import Hangman

hangman = Hangman()
hangman.play()
Enter fullscreen mode Exit fullscreen mode

You can pass a list of words to the Hangman class to utilize custom words. By default, the words are a list of programming language names.

hangman = Hangman(words=['apple', 'banana', 'orange', 'melon'])
Enter fullscreen mode Exit fullscreen mode

Link to Source Code

Github repository: https://github.com/viniciusenari/hangman-package

Permissive License

MIT License

Background (What made you decide to build this particular app? What inspired you?)

I wanted to build something with GitHub Actions to learn the basics of how it works. Since I am most comfortable working with Python, I looked for workflow templates available for Python and found two that could be helpful in maintaining a Python package.

Workflow templates

I wasn't sure what to build for a package, so I ended up going with the first idea that came to mind—a hangman game. While it's not an original idea, it served its purpose of allowing me to utilize and learn more about GitHub Actions.

How I built it (How did you utilize GitHub Actions or GitHub Codespaces? Did you learn something new along the way? Pick up a new skill?)

I utilized two GitHub actions workflows, one for testing and linting and another one for publishing my package. The workflow for testing and linting is triggered whenever there is a push or a pull request to the main branch. It utilizes the pytest library to run tests and flake8 to lint, ensuring that the code follows conventions and works correctly. It runs against multiple Python versions.

The workflow for publishing is triggered when a new release is created. It utilizes the build command to create a distributable version of the package and publishes it to PyPI.

Overall, I learned how to utilize these workflows to automate important tasks in my development process, making it easier to maintain code quality and distribute my package.

In addition to GitHub Actions, I also utilized GitHub Codespaces to experiment with my package. Without needing to rely on my local development environment, I was able to test the package.

Additional Resources/Info

https://en.wikipedia.org/wiki/Hangman_(game)

Top comments (0)