Skip to content

Commit

Permalink
Merge pull request #3 from justgigio/v0.0.2
Browse files Browse the repository at this point in the history
V0.0.2
  • Loading branch information
justgigio authored Nov 8, 2023
2 parents 8981ee4 + be80992 commit d5ce557
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 118 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build 🐍
on: push
jobs:
tests:
uses: ./.github/workflows/tests.yml
build:
name: Build distribution 📦
needs:
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/awesome_git_mosaic
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test 🐍
on: [workflow_call]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python3 -m venv $POETRY_HOME
$POETRY_HOME/bin/pip install poetry==1.7.0
$POETRY_HOME/bin/poetry --version
$POETRY_HOME/bin/poetry install
- name: Check Code style
run: >-
$POETRY_HOME/bin/poetry run pycodestyle --statistics --ignore=E501,W503,E902 --count src
- name: Check MyPy
run: >-
$POETRY_HOME/bin/poetry run mypy src
- name: Check Black
run: >-
$POETRY_HOME/bin/poetry run black --check src
- name: Check isort
run: >-
$POETRY_HOME/bin/poetry run isort --ac --check-only src
- name: Execute tests
run: >-
$POETRY_HOME/bin/poetry run py.test tests
--cov=.
--cov-report xml
--cov-report term
--cov-fail-under=90
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
POETRY_HOME: /opt/poetry
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

.awesome_folder
.__testing_modify_folder
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

.PHONY: code-style
code-style:
poetry run pycodestyle --statistics --ignore=E501,E902 --count src
poetry run pycodestyle --statistics --ignore=E501,W503,E902 --count src

.PHONY: setup
setup:
poetry install

.PHONY: test
test: code-style
poetry run py.test tests --cov=. --cov-report xml --cov-report term --cov-report html --cov-fail-under=90

.PHONY: test-only
test-only:
poetry run py.test tests --no-cov
Expand All @@ -20,11 +16,12 @@ build:
poetry build

.PHONY: mypy
mypy: poetry run mypy src
mypy:
poetry run mypy src

.PHONY: black-check
black-check:
poetry run black --check src
poetry run black --check --diff src

.PHONY: black
black:
Expand All @@ -39,7 +36,11 @@ isort:
poetry run isort --ac src

.PHONY: check
check: isort-check black-check mypy
check: code-style isort-check black-check mypy

.PHONY: format
format: black isort
format: isort black

.PHONY: test
test: check
poetry run py.test tests --cov=. --cov-report xml --cov-report term --cov-report html --cov-fail-under=90
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[![codecov](https://codecov.io/gh/justgigio/awesome-git-mosaic/graph/badge.svg?token=0ON0YL8EAH)](https://codecov.io/gh/justgigio/awesome-git-mosaic)
![build](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/build.yml/badge.svg)
- Pypi badge
- python version badge
- docs badge
# awesome-git-mosaic
A simple tool to make cool tricks with your GitHub activity mosaic
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "awesome_git_mosaic"
version = "0.0.1"
version = "0.0.2"
description = "An awesome tool to write small texts on GitHub mosaic"
authors = ["Giovane Costa <[email protected]>"]
license = "MIT License"
Expand All @@ -26,3 +26,6 @@ build-backend = "poetry.core.masonry.api"
[[tool.mypy.overrides]]
module = "unidecode,awesome_git_mosaic.*"
ignore_missing_imports = true

[tool.isort]
line_length = 120
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[pycodestyle]
ignore=W291,W293,E501,W292,W391,W503,E902
exclude=.tywin,venv,.env,node_modules,alembic,scripts,deploy
max-line-length=80

[tool:pytest]
pythonpath = src

Expand Down
13 changes: 11 additions & 2 deletions src/awesome_git_mosaic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from awesome_git_mosaic.usecases.write_mosaic import WriteMosaic


def write(text: str, strength: int = 5, multiply: int = 1, background: bool = False):
WriteMosaic().write(text, strength, multiply, background) # pragma: no cover
def write(
text: str,
strength: int = 5,
multiply: int = 1,
with_spaces: bool = True,
background: bool = False,
inverted: bool = False,
):
WriteMosaic().write(
text, strength, multiply, with_spaces, background, inverted
) # pragma: no cover
3 changes: 1 addition & 2 deletions src/awesome_git_mosaic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@


def main():

if len(sys.argv) > 1:
write(sys.argv[1], 45, 1, True)
else:
print('You need to give something to write')
print("You need to give something to write")


if __name__ == "__main__":
Expand Down
28 changes: 18 additions & 10 deletions src/awesome_git_mosaic/adapters/console/console_adapter.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
from typing import TYPE_CHECKING, Optional

from awesome_git_mosaic.charmaps.basic.basic_charmap import BasicCharmap
from typing import Optional, TYPE_CHECKING

if TYPE_CHECKING:
from awesome_git_mosaic.charmaps.charmap import Charmap


CONSOLE_PIXEL = '▉'
CONSOLE_SPACE = ' '
CONSOLE_PIXEL = "▉"
CONSOLE_SPACE = " "
CONSOLE_BG = "░"


class ConsoleAdapter:

def __init__(self, charmap: Optional['Charmap'] = None):
def __init__(self, charmap: Optional["Charmap"] = None):
self.charmap = charmap or BasicCharmap()

def output(self, message: str, with_spaces: bool = True) -> str:
lines = self.charmap.translate(message, with_spaces)
def output(
self,
message: str,
with_spaces: bool = True,
background: bool = False,
inverted: bool = False,
) -> str:
lines = self.charmap.translate(message, with_spaces, inverted)

bg = CONSOLE_BG if background else CONSOLE_SPACE
output = []
for line in lines:
output_line = ''
output_line = ""
for char in line:
output_line += CONSOLE_PIXEL if self.charmap.is_pixel(char) else CONSOLE_SPACE
output_line += CONSOLE_PIXEL if self.charmap.is_pixel(char) else bg
output.append(output_line)

return '\n'.join(output)
return "\n".join(output)
30 changes: 22 additions & 8 deletions src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from random import randint
from typing import List, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional

from awesome_git_mosaic.charmaps.basic.basic_charmap import BasicCharmap

Expand All @@ -9,29 +9,43 @@


class GitMosaicAdapter:

def __init__(self, charmap: Optional['Charmap'] = None):
def __init__(self, charmap: Optional["Charmap"] = None):
self.charmap = charmap or BasicCharmap()

def output(self, message: str, reference_day: Optional[datetime] = None, with_spaces: bool = True, background: bool = False) -> List[datetime]:
def output(
self,
message: str,
reference_day: Optional[datetime] = None,
with_spaces: bool = True,
inverted: bool = False,
) -> List[datetime]:
reference_day = reference_day or datetime.today()
lines = self.charmap.translate(message, with_spaces, background)
lines = self.charmap.translate(message, with_spaces, inverted)

output = []
y_offset = 0
for line in lines:
x_offset = 0
for char in line:
if self.charmap.is_pixel(char):
output.append(self._timestamp_for_pixel(x_offset, y_offset, reference_day))
output.append(
self._timestamp_for_pixel(x_offset, y_offset, reference_day)
)
x_offset += 1
y_offset += 1

return output

def _timestamp_for_pixel(self, x_offset: int, y_offset: int, reference_day: datetime) -> datetime:
def _timestamp_for_pixel(
self, x_offset: int, y_offset: int, reference_day: datetime
) -> datetime:
last_sunday = reference_day - timedelta(days=reference_day.weekday() + 1)
top_left_square = last_sunday - timedelta(weeks=51)

target_date = top_left_square + timedelta(weeks=x_offset) + timedelta(days=y_offset) + timedelta(microseconds=randint(0, 300))
target_date = (
top_left_square
+ timedelta(weeks=x_offset)
+ timedelta(days=y_offset)
+ timedelta(microseconds=randint(0, 300))
)
return target_date
Loading

0 comments on commit d5ce557

Please sign in to comment.