Code Monkey home page Code Monkey logo

python-project-blueprint's Introduction

Blueprint/Boilerplate For Python Projects

Build, Test and Lint Action Push Action Test Coverage Maintainability Quality Gate Status


If you find this useful, you can support me on Ko-Fi (Donations are always appreciated, but never required):

ko-fi

Blog Posts - More Information About This Repo

You can find more information about this project/repository and how to use it in following blog post:

Quick Start

To use this repository as starter for your project you can run configure_project.sh script, which sets up all variables and file names. This way you can avoid configuring and renaming things yourself:

./configure_project.sh MODULE="coolproject" REGISTRY="docker.pkg.github.com/martinheinz/repo-name"

Running

Using Python Interpreter

~ $ make run

Using Docker

Development image:

~ $ make build-dev
~ $ docker images --filter "label=name=blueprint"
REPOSITORY                                                             TAG                 IMAGE ID            CREATED             SIZE
docker.pkg.github.com/martinheinz/python-project-blueprint/blueprint   3492a40-dirty       acf8d09acce4        28 seconds ago      967MB
~ $ docker run acf8d09acce4
Hello World...

Production (Distroless) image:

~ $ make build-prod VERSION=0.0.5
~ $ docker images --filter "label=version=0.0.5"
REPOSITORY                                                             TAG                 IMAGE ID            CREATED             SIZE
docker.pkg.github.com/martinheinz/python-project-blueprint/blueprint   0.0.5               65e6690d9edd        5 seconds ago       86.1MB
~ $ docker run 65e6690d9edd
Hello World...

Testing

Test are ran every time you build dev or prod image. You can also run tests using:

~ $ make test

Pushing to GitHub Package Registry

~ $ docker login docker.pkg.github.com --username MartinHeinz
Password: ...
...
Login Succeeded
~ $ make push VERSION=0.0.5

Cleaning

Clean Pytest and coverage cache/files:

~ $ make clean

Clean Docker images:

~ $ make docker-clean

Kubernetes

Application can be easily deployed on k8s using KinD.

To create cluster and/or view status:

~ $ make cluster

To deploy application to local cluster:

~ $ make deploy-local

To get debugging information of running application:

~ $ make cluster-debug

To get remote shell into application pod:

~ $ make cluster-rsh

To apply/update Kubernetes manifest stored in k8s directory:

~ $ make manifest-update

Setting Up Sonar Cloud

  • Navigate to https://sonarcloud.io/projects
  • Click plus in top right corner -> analyze new project
  • Setup with other CI tool -> other -> Linux
  • Copy -Dsonar.projectKey= and -Dsonar.organization=
    • These 2 values go to sonar-project.properties file
  • Click pencil at bottom of sonar-scanner command
  • Generate token and save it
  • Go to repo -> Settings tab -> Secrets -> Add a new secret
    • name: SONAR_TOKEN
    • value: Previously copied token

Creating Secret Tokens

Token is needed for example for GitHub Package Registry. To create one:

  • Go to Settings tab
  • Click Secrets
  • Click Add a new secret
    • Name: name that will be accessible in GitHub Actions as secrets.NAME
    • Value: value

Resources

python-project-blueprint's People

Contributors

martinheinz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-project-blueprint's Issues

What is base.Dockerfile for?

Excellent project blueprint. I'm looking through the commits and can't find what the base.Dockerfile is used for.

Consider Flask-Rest

Hello,

I consider your work as wonderful but as newbie about Python domain, I had many difficult to have a fully Flask Rest example running right.

As TDD (Java... ) practitioner, It would be great to complete with a such REST example.
Sorry to ask it about an issue. It is not a bad idea but promise it could be a nice thing to add it.

Thanks a lot.
Best regards, Nicolas

Consider versioneer

I noticed you use Git describe to grab the version number (great).... But I'd recommend using a super neat tool called 'versioneer' as it will give you the same version number, but works in development mode (i.e. running python setup.py --version when your package is installed via pip install -e).

configure_project script not working

Hey there, thank you so much for open sourcing this template and for your well written blog posts.

Trying to run the below script:

./configure_project.sh MODULE="coolproject" REGISTRY="docker.pkg.github.com/martinheinz/repo-name"

Leads to the following errors:
on run:

Test: make run

python: No module named blueprint
make: *** [run] Error 1

on test:
pytest.ini file --cov argument needs to be replaced to module name:

Test: make test

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov=blueprint --cov-report=xml --cov-report=term
  inifile: /martinheinz/python-project-blueprint/pytest.ini
  rootdir: /martinheinz/python-project-blueprint

Consider src directory

Consider using a src directory. This facilitates running tests against what is actually installed.

https://hynek.me/articles/testing-packaging/

I have been bitten by this. I've had tests pass locally but fail within a .whl file. I've had them pass in a .whl file and fail in a source tgz file. This typically happens when you start needing to ship non-python files. Configuration, images, documents, templates, etc.

Adding isort and black

Thanks, this is a real game changer for me! :)

If I were to customize it for myself, I would add auto-formatting with black and auto-sorting-imports with isort.

Potentially, I would also add https://github.com/python-poetry/poetry or make it obvious somewhere that it should be used.

Oh, and I think some tools (e.g. flake8, pylint) should also appear in requirements.txt ?

Happy to open a PR if you like any of those ideas. :)

Consider using wemake-python-styleguide

wemake-python-styleguide is the strictest python linter out there.

I see that you already use flake8 and pylint.
That's great! Because wemake-python-styleguide combines these two together.
flake8 is great due to its simplicity and plugin system. And wemake-python-styleguide is just a flake8 plugin on steroids. It just works as a regular plugin. On the other hand, we have more rules than pylint (and mostly compatible with it), so it can be easily replaced. This can save you from the configuration hell in setup.cfg you currently have.

That's how output looks like:

output

We also have a nice Github Action with pre-installed reviewdog that can format errors in a nice human-readable manner like so:

reviewdog

Repo: https://github.com/wemake-services/wemake-python-styleguide
Github Action: https://github.com/marketplace/actions/wemake-python-styleguide
Related to #3, because we already have isort installed.

If it is interesting, I can help with the migration process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.