- 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.
- 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:
- # install dependencies
- install:
- pip install -r requirements.txt
- # run tests
- test:
- pytest
- # build distribution package
- dist:
- python setup.py sdist
- 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.
- 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.
- Here is an example of a GitHub Action that runs the test suite defined in the above Makefile:
- on: [push]
- jobs:
- test:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Install dependencies
- run: make install
- - name: Run tests
- run: make test
- This action will run the install and test targets of the Makefile every time you push code to your repository.
- You can find more examples of using Makefiles and GitHub Actions for Python projects in the official documentation:
- Makefile for Python projects
- https://docs.python-guide.org/writing/makefiles/
- Automating your workflow with GitHub Actions
- https://docs.github.com/en/actions/getting-started-with-github-actions/configuring-a-workflow
- Here is an example of a setup.py file for a Python project:
- import setuptools
- with open("README.md", "r") as fh:
- long_description = fh.read()
- setuptools.setup(
- name="my-project",
- version="1.0.0",
- author="John Doe",
- author_email="johndoe@example.com",
- description="A short description of my project",
- long_description=long_description,
- long_description_content_type="text/markdown",
- url="https://github.com/johndoe/my-project",
- packages=setuptools.find_packages(),
- classifiers=[
- "Programming Language :: Python :: 3",
- "License :: OSI Approved :: MIT License",
- "Operating System :: OS Independent",
- ],
- python_requires=">=3.6",
- )
- 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.
- 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:
- python setup.py sdist
- 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:
- python setup.py sdist upload
- 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