fix: runs in dkrfile & tstng.yml, md fmt err, rm distutils, time delay
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/testing.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/testing.yml
									
									
									
									
										vendored
									
									
								
							@@ -21,7 +21,7 @@ jobs:
 | 
				
			|||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.1.13
 | 
					          curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.1.13
 | 
				
			||||||
          echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin"
 | 
					          echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin"
 | 
				
			||||||
          source $HOME/.poetry/env"
 | 
					          source $HOME/.poetry/env
 | 
				
			||||||
          poetry install
 | 
					          poetry install
 | 
				
			||||||
      - name: Run unit tests
 | 
					      - name: Run unit tests
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								Dockerfile
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
FROM python:3.10.2-slim-bullseye as base
 | 
					FROM python:3.10.2-slim-bullseye
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENV PYTHONFAULTHANDLER=1 \
 | 
					ENV PYTHONFAULTHANDLER=1 \
 | 
				
			||||||
    PYTHONUNBUFFERED=1 \
 | 
					    PYTHONUNBUFFERED=1 \
 | 
				
			||||||
@@ -11,12 +11,9 @@ ENV PYTHONFAULTHANDLER=1 \
 | 
				
			|||||||
    # poetry:
 | 
					    # poetry:
 | 
				
			||||||
    POETRY_VERSION=1.1.13 \
 | 
					    POETRY_VERSION=1.1.13 \
 | 
				
			||||||
    POETRY_NO_INTERACTION=1 \
 | 
					    POETRY_NO_INTERACTION=1 \
 | 
				
			||||||
    POETRY_VIRTUALENVS_CREATE=false \
 | 
					 | 
				
			||||||
    POETRY_CACHE_DIR='/var/cache/pypoetry' \
 | 
					    POETRY_CACHE_DIR='/var/cache/pypoetry' \
 | 
				
			||||||
    PATH="$PATH:/root/.local/bin"
 | 
					    PATH="$PATH:/root/.local/bin"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /src
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# install poetry
 | 
					# install poetry
 | 
				
			||||||
# RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
 | 
					# RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
 | 
				
			||||||
RUN pip install pipx
 | 
					RUN pip install pipx
 | 
				
			||||||
@@ -24,9 +21,9 @@ RUN pipx install "poetry==$POETRY_VERSION"
 | 
				
			|||||||
RUN pipx ensurepath
 | 
					RUN pipx ensurepath
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# install dependencies
 | 
					# install dependencies
 | 
				
			||||||
COPY pyproject.toml poetry.lock /src/
 | 
					COPY pyproject.toml poetry.lock /
 | 
				
			||||||
RUN poetry install --no-dev --no-root --no-interaction --no-ansi
 | 
					RUN poetry install --no-dev --no-root --no-interaction --no-ansi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# copy and run program
 | 
					# copy and run program
 | 
				
			||||||
COPY main.py /src/
 | 
					ADD main.py /main.py
 | 
				
			||||||
CMD [ "python", "/src/main.py" ]
 | 
					CMD [ "poetry", "run", "python", "/main.py" ]
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										41
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								main.py
									
									
									
									
									
								
							@@ -33,11 +33,11 @@ Other      35 mins         ⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# standard
 | 
					# standard
 | 
				
			||||||
from distutils.util import strtobool
 | 
					 | 
				
			||||||
from dataclasses import dataclass
 | 
					from dataclasses import dataclass
 | 
				
			||||||
from datetime import datetime
 | 
					from datetime import datetime
 | 
				
			||||||
from base64 import b64encode
 | 
					from base64 import b64encode
 | 
				
			||||||
import logging as logger
 | 
					import logging as logger
 | 
				
			||||||
 | 
					from time import sleep
 | 
				
			||||||
from typing import Any
 | 
					from typing import Any
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
@@ -106,9 +106,9 @@ class WakaInput:
 | 
				
			|||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.show_title: bool = bool(strtobool(self.show_title))
 | 
					            self.show_title: bool = strtobool(self.show_title)
 | 
				
			||||||
            self.show_time: bool = bool(strtobool(self.show_time))
 | 
					            self.show_time: bool = strtobool(self.show_time)
 | 
				
			||||||
            self.show_total_time: bool = bool(strtobool(self.show_total_time))
 | 
					            self.show_total_time: bool = strtobool(self.show_total_time)
 | 
				
			||||||
        except (ValueError, AttributeError) as err:
 | 
					        except (ValueError, AttributeError) as err:
 | 
				
			||||||
            logger.error(err)
 | 
					            logger.error(err)
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
@@ -128,6 +128,32 @@ class WakaInput:
 | 
				
			|||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def strtobool(val: str) -> bool:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    strtobool
 | 
				
			||||||
 | 
					    ---------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PEP 632 https://www.python.org/dev/peps/pep-0632/ is depreciating distutils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Following code is somewhat shamelessly copied from the original source.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Convert a string representation of truth to True or False.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - True values are `'y', 'yes', 't', 'true', 'on', and '1'`
 | 
				
			||||||
 | 
					    - False values are `'n', 'no', 'f', 'false', 'off', and '0'`
 | 
				
			||||||
 | 
					    - Raises `ValueError` if `val` is anything else.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    val = val.lower()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if val in {'y', 'yes', 't', 'true', 'on', '1'}:
 | 
				
			||||||
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if val in {'n', 'no', 'f', 'false', 'off', '0'}:
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    raise ValueError(f'invalid truth value for {val}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
################### logic ###################
 | 
					################### logic ###################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def make_title(dawn: str, dusk: str, /) -> str:
 | 
					def make_title(dawn: str, dusk: str, /) -> str:
 | 
				
			||||||
@@ -250,12 +276,13 @@ def fetch_stats() -> Any:
 | 
				
			|||||||
                headers={'Authorization': f'Basic {encoded_key}'}
 | 
					                headers={'Authorization': f'Basic {encoded_key}'}
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            logger.debug(
 | 
					            logger.debug(
 | 
				
			||||||
                f'API response at trial #{4 - tries}: {resp.status_code} {resp.reason}'
 | 
					                f'API response @ trial #{4 - tries}: {resp.status_code} {resp.reason}'
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            if resp.status_code == 200 and (statistic := resp.json()):
 | 
					            if resp.status_code == 200 and (statistic := resp.json()):
 | 
				
			||||||
                logger.debug('Fetched WakaTime statistics')
 | 
					                logger.debug('Fetched WakaTime statistics')
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            logger.debug('Retrying ...')
 | 
					            logger.debug('Retrying in 3s ...')
 | 
				
			||||||
 | 
					            sleep(3)
 | 
				
			||||||
            tries -= 1
 | 
					            tries -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if err := (statistic.get('error') or statistic.get('errors')):
 | 
					    if err := (statistic.get('error') or statistic.get('errors')):
 | 
				
			||||||
@@ -283,7 +310,7 @@ def churn(old_readme: str, /) -> str | None:
 | 
				
			|||||||
    print('\n', generated_content, '\n', sep='')
 | 
					    print('\n', generated_content, '\n', sep='')
 | 
				
			||||||
    new_readme = re.sub(
 | 
					    new_readme = re.sub(
 | 
				
			||||||
        pattern=wk_c.waka_block_pattern,
 | 
					        pattern=wk_c.waka_block_pattern,
 | 
				
			||||||
        repl=f'{wk_c.start_comment}```txt\n{generated_content}\n```{wk_c.end_comment}',
 | 
					        repl=f'{wk_c.start_comment}\n\n```text\n{generated_content}\n```\n\n{wk_c.end_comment}',
 | 
				
			||||||
        string=old_readme
 | 
					        string=old_readme
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    # return None  # un-comment when testing with --dev
 | 
					    # return None  # un-comment when testing with --dev
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user