Skip to content

thetemplates/python-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


A basic template for Python projects; the structure and programs are in line with language standards and team norms.


develop
Templates

master
Templates



Environments

Remote Development

For this Python project/template, the remote development environment requires

An image is built via the command

docker build . --file .devcontainer/Dockerfile -t fundamentals

On success, the output of

docker images

should include


repository tag image id created size
fundamentals latest $\ldots$ $\ldots$ $\ldots$

Subsequently, run a container, i.e., an instance, of the image fundamentals via:


docker run --rm -i -t -p 127.0.0.1:10000:8888 -w /app --mount
    type=bind,src="$(pwd)",target=/app fundamentals


Herein, -p 10000:8888 maps the host port 10000 to container port 8888. Note, the container's working environment, i.e., -w, must be inline with this project's top directory. Get the name of the running instance of fundamentals via:

docker ps --all

Never deploy a root container, study the production Dockerfile; cf. /.devcontainer/Dockerfile


Remote Development & Integrated Development Environments

An IDE (integrated development environment) is a helpful remote development tool. The IntelliJ IDEA set up involves connecting to a machine's Docker daemon, the steps are


  • Settings $\rightarrow$ Build, Execution, Deployment $\rightarrow$ Docker $\rightarrow$ WSL: {select the linux operating system}
  • View $\rightarrow$ Tool Window $\rightarrow$ Services
    Within the Containers section connect to the running instance of interest, or ascertain connection to the running instance of interest.

Visual Studio Code has its container attachment instructions; study Attach Container.



Code Analysis

The GitHub Actions script main.yml conducts code analysis within a Cloud GitHub Workspace. Depending on the script, code analysis may occur on push to any repository branch, or on push to a specific branch.

The sections herein outline remote code analysis.

pylint

The directive

pylint --generate-rcfile > .pylintrc

generates the dotfile .pylintrc of the static code analyser pylint. Analyse a directory via the command

python -m pylint --rcfile .pylintrc {directory}

The .pylintrc file of this template project has been amended to adhere to team norms, including

  • Maximum number of characters on a single line.

    max-line-length=127

  • Maximum number of lines in a module.

    max-module-lines=135


pytest

Study the programs

  • src.algorithms.random
  • tests.algorithms.test_random

Subsequently, test the program src.algorithms.random via the command

python -m pytest tests/algorithms/test_random.py

flake8

For code & complexity analysis. A directive of the form

python -m flake8 --count --select=E9,F63,F7,F82 --show-source --statistics src/data

inspects issues in relation to logic (F7), syntax (Python E9, Flake F7), mathematical formulae symbols (F63), undefined variable names (F82). Additionally

python -m flake8 --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics src/data

inspects complexity.



Delivering Assets

This example illustrates automatic asset delivery. The diagram outlines the delivery routes & actions.

Asset Delivery

Delivery to Amazon ECR (Elastic Container Registry) is conditional. If you do not have an Amazon account and/or you have not set up the GitHub Secrets

  • AWS_ENTRY
  • AWS_ARN_ECR_ACTIONS: Amazon ECR & GitHub Actions interaction role
  • AWS_REGION: region code

that enable delivery to Amazon ECR via the directive

  with:
    role-to-assume: arn:aws:iam::${{ secrets.AWS_ENTRY }}:role/${{ secrets.AWS_ARN_ECR_ACTIONS }}
    aws-region: ${{ secrets.AWS_REGION }}

then set the ecr section of main.yml to false, i.e.,

  ecr:
    name: Amazon Elastic Container Registry
    needs: build
    if: ${{ false }}








About

For fundamental data mining & engineering

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published