DEV Community 👩‍💻👨‍💻

Aahnik Daw
Aahnik Daw

Posted on

Is there a makefile alternative where we can run code in python?

Makefiles are fantastic tools. They help us automate stuff.

I often run commands like : make epub or make docs or make site etc

I have a simple makefile where I write in shell code. And make simplifies my life

The commands we write inside makefile are actually shell commands.

Is there a way to write a python file. and run its functions like make.

For example:

Makefile

hi:
   echo hi this is makefile 

func:
   # ... some work
Enter fullscreen mode Exit fullscreen mode
  • We can run make which would execute stuff under hi,
  • while running make func would execute lines under func.
  • If there is no Makefile, make would do nothing

Now A python alternative would look like this


'''
hi this is python do file
'''

def func():
   # stuff here

Enter fullscreen mode Exit fullscreen mode
  • Running ado would print the docstring.
  • and running ado func would run func.

  • If there is no do.py file in current directory then ado would do nothing

https://stackoverflow.com/questions/64556791/is-there-a-makefile-alternative-where-we-can-run-code-in-python

Top comments (3)

Collapse
yaythomas profile image
yaythomas • Edited on

check out pypyr.io/

it's free + open-source. What you describe is pretty much exactly what it does :-)

(declaration of interest: I created it. :-) If you have questions/need help, just ask!)

GitHub is here: github.com/pypyr/pypyr

Collapse
aahnik profile image
Aahnik Daw Author

Thanks a lot @yaythomas
pypyr is really great

Collapse
aahnik profile image
Aahnik Daw Author

Today, I found invoke github.com/pyinvoke/invoke

DEV runs on 100% open source code known as Forem.

 
Contribute to the codebase or host your own.
 
Check these out! 👇