The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Python Makefile examples with github actions
By Guest on 15th December 2022 07:07:18 AM | Syntax: PYTHON | Views: 210



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. A Makefile is a file that contains a set of instructions that are used to build and manage other programs or files. In the context of Python, a Makefile can be used to automate tasks such as installing dependencies, running tests, and building distribution packages.
  2.  
  3. Here is an example of a simple Python Makefile that installs the required dependencies using pip, runs the test suite using pytest, and builds a distribution package using setuptools:
  4.  
  5.  
  6. # install dependencies
  7. install:
  8.   pip install -r requirements.txt
  9.  
  10. # run tests
  11. test:
  12.   pytest
  13.  
  14. # build distribution package
  15. dist:
  16.   python setup.py sdist
  17.  
  18.  
  19. To use this Makefile, you would simply run make install to install the dependencies, make test to run the tests, and make dist to build the distribution package.
  20.  
  21. You can use GitHub Actions to automate the execution of a Makefile. For example, you can set up a workflow that runs the test suite every time you push code to your repository, or build a distribution package and publish it to PyPI whenever you create a new release.
  22.  
  23. Here is an example of a GitHub Action that runs the test suite defined in the above Makefile:
  24.  
  25. on: [push]
  26.  
  27. jobs:
  28.   test:
  29.     runs-on: ubuntu-latest
  30.     steps:
  31.     - uses: actions/checkout@v2
  32.     - name: Install dependencies
  33.       run: make install
  34.     - name: Run tests
  35.       run: make test
  36.  
  37.  
  38. This action will run the install and test targets of the Makefile every time you push code to your repository.
  39.  
  40. You can find more examples of using Makefiles and GitHub Actions for Python projects in the official documentation:
  41.  
  42. Makefile for Python projects
  43. https://docs.python-guide.org/writing/makefiles/
  44.  
  45. Automating your workflow with GitHub Actions
  46. https://docs.github.com/en/actions/getting-started-with-github-actions/configuring-a-workflow
  47.  
  48.  
  49. Here is an example of a setup.py file for a Python project:
  50.  
  51. import setuptools
  52.  
  53. with open("README.md", "r") as fh:
  54.     long_description = fh.read()
  55.  
  56. setuptools.setup(
  57.     name="my-project",
  58.     version="1.0.0",
  59.     author="John Doe",
  60.     author_email="johndoe@example.com",
  61.     description="A short description of my project",
  62.     long_description=long_description,
  63.     long_description_content_type="text/markdown",
  64.     url="https://github.com/johndoe/my-project",
  65.     packages=setuptools.find_packages(),
  66.     classifiers=[
  67.         "Programming Language :: Python :: 3",
  68.         "License :: OSI Approved :: MIT License",
  69.         "Operating System :: OS Independent",
  70.     ],
  71.     python_requires=">=3.6",
  72. )
  73.  
  74.  
  75. This setup.py file defines metadata for your project, such as its name, version, author, and description. It also specifies the packages that should be included in the distribution and the required Python version.
  76.  
  77. You can use the setup.py file with the setuptools module to build a distribution package for your project. For example, you can run the following command to build a .tar.gz archive containing your project:
  78.  
  79.  
  80. python setup.py sdist
  81.  
  82.  
  83. You can also use the setup.py file to publish your project to the Python Package Index (PyPI), which allows other users to easily install your project using pip. To do this, you will need to create a PyPI account and a ~/.pypirc file with your PyPI credentials, and then run the following command:
  84.  
  85.  
  86. python setup.py sdist upload
  87.  
  88.  
  89. For more information, see the setuptools documentation: https://setuptools.readthedocs.io/en/latest/setuptools.html#id1
















Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.

Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.

See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license
  • Recent Pastes