Code Monkey home page Code Monkey logo

cookiecutter-hypy's Introduction

Alexander the Great cuts the Gordian Knot

Problems well-defined are problems solved.

The standard that our analytic work aspires to achieve, can best be illustrated through our namesake: Diogenes. A famous (or infamous) Greek philospher, Diogenes the Cynic is the paragon of the two virtues that best represent our standard: minimalism, and logical rigor ๐ŸŽฒ

cookiecutter-hypy's People

Contributors

benjaminrose avatar cclauss avatar cito avatar cjolowicz avatar dependabot-preview[bot] avatar dependabot[bot] avatar diogenesanalytics avatar eyllanesc avatar jasonwashburn avatar jooh avatar nilsdebruin avatar oncleben31 avatar paw-lu avatar rng0x17 avatar sgraaf avatar shivamdurgbuns avatar staticdev avatar yeskunall avatar

cookiecutter-hypy's Issues

Feature: Add Build Command for Docker Image to Makefile

Problem

At times it is necessary to build the Docker image instead of pulling it down from ghcr.io.

Solution

Simply need to add a build command to make file:

build:
    docker build -t ${DCKRIMG} . --load

References

  • .PHONY: all jupyter pause address containers list-containers stop-containers \
    restart-containers lint tests pytest isort black flake8 mypy shell clear-nb \
    clean
    # Usage:
    # make # just alias to containers command
    # make jupyter # startup Docker container running Jupyter server
    # make pause # pause PSECS (to pause between commands)
    # make address # get Docker container address/port
    # make containers # launch all Docker containers
    # make list-containers # list all running containers
    # make stop-containers # simply stops all running Docker containers
    # make restart-containers # restart all containers
    # make lint # run linters
    # make tests # run full testing suite
    # make pytest # run pytest in docker container
    # make isort # run isort in docker container
    # make black # run black in docker container
    # make flake8 # run flake8 in docker container
    # make mypy # run mypy in docker container
    # make shell # create interactive shell in docker container
    # make clear-nb # simply clears Jupyter notebook output
    # make clean # combines all clearing commands into one
    ################################################################################
    # GLOBALS #
    ################################################################################
    # make cli args
    DCTNR := $(notdir $(PWD))
    INTDR := notebooks
    PSECS := 5
    # notebook-related variables
    CURRENTDIR := $(PWD)
    NOTEBOOKS := $(shell find ${INTDR} -name "*.ipynb" -not -path "*/.ipynb_*/*")
    # docker-related variables
    JPTCTNR = jupyter.${DCTNR}
    SRCPATH = /usr/local/src/{{cookiecutter.project_name|lower}}
    DCKRIMG = ghcr.io/{{cookiecutter.github_user|lower}}/{{cookiecutter.project_name|lower}}:master
    JPTRSRV = docker run --rm -v ${CURRENTDIR}:/home/jovyan -it ${DCKRIMG}
    DCKRTST = docker run --rm -v ${CURRENTDIR}:${SRCPATH} -it ${DCKRIMG}
    # jupyter nbconvert vars
    NBCLER = jupyter nbconvert --clear-output --inplace
    ################################################################################
    # COMMANDS #
    ################################################################################
    # launch jupyter
    all: containers
    # launch jupyter notebook development Docker image
    jupyter:
    @ echo "Launching Jupyter in Docker container -> ${JPTCTNR} ..."
    @ if ! docker ps --format={{ "{{.Names}}" }} | grep -q "${JPTCTNR}"; then \
    docker run -d \
    --rm \
    --name ${JPTCTNR} \
    -e JUPYTER_ENABLE_LAB=yes \
    -p 8888 \
    -v "${CURRENTDIR}":/usr/local/src/{{cookiecutter.project_name}} \
    ${DCKROPT} \
    ${DCKRIMG} && \
    if ! grep -sq "${JPTCTNR}" "${CURRENTDIR}/.running_containers"; then \
    echo "${JPTCTNR}" >> .running_containers; \
    fi \
    else \
    echo "Container already running. Try setting DCTNR manually."; \
    fi
    # simply wait for a certain amount of time
    pause:
    @ echo "Sleeping ${PSECS} seconds ..."
    @ sleep ${PSECS}
    # get containerized server address
    address:
    @ if [ -f "${CURRENTDIR}/.running_containers" ]; then \
    while read container; do \
    if echo "$${container}" | grep -q "${JPTCTNR}" ; then \
    echo "Server address: $$(docker logs $${container} 2>&1 | \
    grep http://127.0.0.1 | tail -n 1 | \
    sed s/:8888/:$$(docker port $${container} | \
    grep '0.0.0.0:' | awk '{print $$3}' | sed 's/0.0.0.0://g')/g | \
    tr -d '[:blank:]')"; \
    else \
    echo "Could not find running container: ${JPTCTNR}." \
    "Try running: make list-containers"; \
    fi \
    done < "${CURRENTDIR}/.running_containers"; \
    else \
    echo ".running_containers file not found. Is a Docker container running?"; \
    fi
    # launch all docker containers
    containers: jupyter pause address
    # list all running containers
    list-containers:
    @ if [ -f "${CURRENTDIR}/.running_containers" ]; then \
    echo "Currently running containers:"; \
    while read container; do \
    echo "--> $${container}"; \
    done < "${CURRENTDIR}/.running_containers"; \
    else \
    echo ".running_containers file not found. Is a Docker container running?"; \
    fi
    # stop all containers
    stop-containers:
    @ if [ -f "${CURRENTDIR}/.running_containers" ]; then \
    echo "Stopping Docker containers ..."; \
    while read container; do \
    echo "Container $$(docker stop $$container) stopped."; \
    done < "${CURRENTDIR}/.running_containers"; \
    rm -f "${CURRENTDIR}/.running_containers"; \
    else \
    echo "${CURRENTDIR}/.running_containers file not found."; \
    fi
    # restart all containers
    restart-containers: stop-containers containers
    # run linters
    lint: isort black flake8 mypy
    # run full testing suite
    tests: pytest lint
    # run pytest in docker container
    pytest:
    @ ${DCKRTST} pytest
    # run isort in docker container
    isort:
    @ ${DCKRTST} isort src/ tests/
    # run black in docker container
    black:
    @ ${DCKRTST} black src/ tests/
    # run flake8 in docker container
    flake8:
    @ ${DCKRTST} flake8
    # run mypy in docker container
    mypy:
    @ ${DCKRTST} mypy src/ tests/
    # create interactive shell in docker container
    shell:
    @ ${DCKRTST} bash || true
    # remove output from executed notebooks
    clear-nb:
    @ echo "Removing all output from Jupyter notebooks."
    @ ${JPTRSRV} ${NBCLER} ${NOTEBOOKS}
    # cleanup everything
    clean: clear-nb

Bug: Pre-commit Complaints

Problem

The pre-commit command is complaining about some things in the README.md and .github/workflow/docker-publish.yml files (related to white space and double vs. single qoutes)

Code

Solution

Just need to change these lines ...

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.