🎉 First Python Package 🎉
1/19/25
After many months of on and off hacking, I’ve finally published version 0.1.0
of ourtils
, a Python package I created.
- GitHub repo: https://github.com/ayoskovich/ourtils
- Documentation: https://ourtils.readthedocs.io/en/latest/
When I set out to write this package, had 3 primary objectives:
- Put all the useful code I’ve written over the years into a single place
- I am increasingly frustrated having to copy / paste or resolve the same problem over and over again, so this was an exercise to make my code more re-usable
- Gain experience writing reusable and maintanable code
- For testing, I used
pytest
which integrates really well into VSCode with alaunch.json
file - I initially was building everything with
requirements.txt
files and managing thepyproject.toml
myself but ran in to dependency issues that were over my head. I started usingpoetry
to manage my package dependencies and so far it’s been much easier.
- For testing, I used
- Learn more CI/CD with GitHub Actions
- This was straightforward, and now I have an action to lint and test my code
- The documentation also automagically deploys when there are new PRs and when things are merged
Something important I learned was that running python scripts directly like this:
$ python3 myscript.py
…is fine for small sandboxy scripts, but the moment you’re importing other local code, you should STOP running like that and do this instead:
$ python3 -m myscript
The -m
flag will run the file as a module. I’ve often found myself getting the dreaded ImportError: attempted relative import in non-package
or something similar. Historically, I’ve fixed this two ways:
- Do something gross with
sys.path
:
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
- Lose all sanity and resort to
try / except
try:
from .helpers import myfunc
except ImportError:
from helpers import myfunc
Both of which are no longer allowed to be a part of my life, and I’ll be using the -m
flag much more.
I’ll bump to version 1.0.0
once I do more battle testing, but now that I’ve gotten over the setup/deployment hump I can spend more time working on the actual code.