This is a simple Python boilerplate project that can be used as a starting point for various types of Python applications.
├── .github
│ └── workflows
│ └── build_and_test.yml
├── src
│ └── app.py
├── tests
│ └── test_app.py
├── main.py
├── Dockerfile
├── docker-compose.yml
├── poetry.lock
├── pyproject.toml
├── .pylintrc
├── build_project.sh
└── README.md
- Docker: Installation guide
- Poetry: Installation guide
-
Clone the repository:
git clone git@.github.com:acn3to/python-boilerplate.git
-
Navigate to the project directory:
cd python-boilerplate
-
Install dependencies using Poetry:
poetry install
-
Build and Start the Docker containers:
docker compose up
-
Run the Python application locally:
poetry run python main.py
To run the tests, execute the following command:
poetry run pytest
This project includes automated testing using GitHub Actions. Whenever changes are pushed to the main branch, the following steps are executed:
- Dependencies are installed using Poetry.
- Pylint is run to check for code quality in the
src
directory. - Unit tests are run using pytest.
This ensures that code quality is maintained and that tests pass before merging changes into the main branch.
The .pylintrc file in the root directory of the project contains configuration settings for pylint, a Python code quality checker. Pylint uses this file to determine which checks and conventions to apply when analyzing your code.
You can customize the .pylintrc file to adjust the linting rules according to your preferences. For example, you can enable or disable specific checks, set the severity level for violations, and configure various aspects of pylint's behavior.
For detailed documentation on the configuration options available in the .pylintrc file, refer to the official pylint documentation.
To streamline the setup and testing of your Python project, you can run an automated process using the provided shell script build_project.sh
. This script automates the following steps:
-
Cloning the Repository (if necessary):
- If you haven't already cloned the repository, the script will clone it into a directory named
python-boilerplate
in the current directory.
- If you haven't already cloned the repository, the script will clone it into a directory named
-
Installing Poetry:
- The script checks if Poetry is installed. If not, it automatically installs Poetry.
-
Installing Dependencies:
- Once Poetry is installed, the script installs all project dependencies specified in the
pyproject.toml
file.
- Once Poetry is installed, the script installs all project dependencies specified in the
-
Running Pylint:
- Pylint is a tool that checks for errors and enforces coding standards. The script runs Pylint on the source code located in the
src
directory.
- Pylint is a tool that checks for errors and enforces coding standards. The script runs Pylint on the source code located in the
-
Running Tests:
- Unit tests are executed using pytest to verify the functionality of the Python application.
-
Building and Running with Docker:
- Docker containers are built using the Dockerfile and docker-compose.yml provided in the project.
- The containers are started to run your Python application.
To run the automated process, follow these steps:
-
Download the Script:
- Right-click on the following link and select "Save link as..." to download the script: build_project.sh
- Alternatively, you can create a new file named
build_project.sh
in the root directory of your project and copy the content of the script from the provided instructions.
-
Make the Script Executable:
- Open your terminal or command prompt.
- Navigate to the directory where you saved the
build_project.sh
file. - Run the following command to give execute permissions to the script:
chmod +x build_project.sh
-
Run the Script:
- Once the script is executable, you can run it using the following command:
./build_project.sh
- This will initiate the automated process, handling all the setup and testing steps for your Python project.
- Once the script is executable, you can run it using the following command:
By using this automated process, you can ensure consistency and efficiency in setting up and testing your Python projects.