Live data from Hacker News

Makefile Tricks for Python Projects

ricardoanderegg.com

11–20 of 35 posts

Re: Makefile Tricks for Python Projects

#13

Or use https://pydoit.org and a virtualenv and be happy.

Hi! Author here.

I've looked into pydoit multiple times and I would love to try it. There are a few reasons that make me go back to make (no pun intended!).

* It comes pre-installed on most UNIX operating systems. Yes, macOS ships an older version, but it works in most cases. This makes bootstrapping projects easier. * I like how simple it's to get started with a Makefile when you just need a few tasks. Although I admit, big Makefiles can become hard to maintain.

I've recently experimented with using Makefiles as an ETL orchestrator, and it's becoming quite messy. I believe pydoit is the perfect replacement candidate. I just haven't had time to try it.

Edit:

Another thing I like about Makefiles is that you can keep the "hackiness" of shell scripts, manipulate the environment [0], etc. I guess you can do the same with other tools, but I find it easier to reason about those useful "hacks" in Makefiles.

[0]: https://ricardoanderegg.com/posts/makefile-python-project-tr...

Re: Makefile Tricks for Python Projects

#14
I’ve used make like this in the past, it’s handy. But zsh auto suggestion obviates the extra maintenance IMO. I type the command one time and it’s in my history. So my common dev actions are more flexibly maintained by recency than editing a file.

You could say the Makefile also serves as a form of (not great) documentation.

Re: Makefile Tricks for Python Projects

#15
post #14

I’ve used make like this in the past, it’s handy. But zsh auto suggestion obviates the extra maintenance IMO. I type the command one time and it’s in my history. So my common dev actions are more flexibly maintained by recency than editing a file. You could say the Makefile also serves as a form of (not great) documentation.

I use it for documentation and simplifying my build flow.

I code in more than a few languages and frameworks, but I don't always memorize the magic build commands for each one.

In my make file, I simply create `make build` and it installs npm, pip,

I run `make clean` and node_modules is deleted or DerivedData are gone.

Otherwise, I'd dump this documentation in an unstructured ReadMe.md.

Re: Makefile Tricks for Python Projects

#16

I recently discovered just ( https://just.systems ), a make alternative that’s much more ergonomic IMO, and have been using it in my personal projects. It’s task-oriented, not goal-oriented, so not a perfect replacement, but works well for my needs.

Author here. I like `just` too, but it's missing a few features:

* It can't run tasks in parallel

* It doesn't handle file dependencies. i.e: it's just a task runner, not a build tool.

* It's another tool you have to install, make comes pre-installed in most UNIX-like operating systems.

Re: Makefile Tricks for Python Projects

#17

Similar in spirit, I made a reusable Makefile for my Python projects: https://github.com/sio/Makefile.venv It's a shame that Python venv workflow is so opaque and unfriendly to new users that it requires extra automation tools.

__pypackages__ is gonna be so nice when it lands.

Re: Makefile Tricks for Python Projects

#18
Don’t do this… unless you have a very specific and non-standard usecase that requires it, like the author:

> I work using git worktrees to have multiple branches checked out at the same time. By using this trick, I can run different commands and make sure the imported package is from that branch, instead of having to python3 -m pip install -e . around all the packages

For most usecases, you can wire up your imports and script entry points in poetry, and manage venvs there too. Or just use pyenv-virtualenv if you’re on MacOS to auto-use your per-project venv.

Again, the author's requirements here are quite esoteric in my experience, and I’d really encourage folks to avoid this particular can of worms if at all possible.

Re: Makefile Tricks for Python Projects

#19
post #17

Similar in spirit, I made a reusable Makefile for my Python projects: https://github.com/sio/Makefile.venv It's a shame that Python venv workflow is so opaque and unfriendly to new users that it requires extra automation tools.

__pypackages__ is gonna be so nice when it lands.

Hate to be the bearer of bad news but the PEP has been rejected https://peps.python.org/pep-0582/

Re: Makefile Tricks for Python Projects

#20
post #17

Similar in spirit, I made a reusable Makefile for my Python projects: https://github.com/sio/Makefile.venv It's a shame that Python venv workflow is so opaque and unfriendly to new users that it requires extra automation tools.

__pypackages__ is gonna be so nice when it lands.

PEP 582 has been rejected, are there any new approach?
Post reply on HN