From a11b1bdc3b2bcc7f6f323029f0e9f93796e95be6 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 18:25:24 -0300 Subject: [PATCH 01/15] Add github action --- .github/workflows/publish.yml | 124 ++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d50e790 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,124 @@ +name: Test and Publish Python 🐍 distribution 📦 to PyPI +on: push +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["pypy3.9", "pypy3.10", "3.9", "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: >- + export POETRY_HOME=/opt/poetry + 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,E902 --count src + $POETRY_HOME/bin/poetry run mypy src + $POETRY_HOME/bin/poetry run black --check src + $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-report html --cov-fail-under=90 + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + build: + name: Build distribution 📦 + needs: + - test + 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/gh-action-sigstore-python@v1.2.3 + 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 }}' diff --git a/pyproject.toml b/pyproject.toml index 06e3af8..25e5890 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT License" From 47a638ceca39d6f66f0953ccc65e79257085f480 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 18:30:29 -0300 Subject: [PATCH 02/15] Fix action shell commands --- .github/workflows/publish.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d50e790..2f9d79b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Display Python version run: python -c "import sys; print(sys.version)" - name: Install dependencies - run: >- + run: | export POETRY_HOME=/opt/poetry python3 -m venv $POETRY_HOME $POETRY_HOME/bin/pip install poetry==1.7.0 @@ -26,12 +26,22 @@ jobs: - name: Check Code style run: >- $POETRY_HOME/bin/poetry run pycodestyle --statistics --ignore=E501,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-report html --cov-fail-under=90 + $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: From b57b70619b21b05b15cb7feaa4ffc9aa867b3bf4 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 18:35:23 -0300 Subject: [PATCH 03/15] Fix env var --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2f9d79b..6b6108e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["pypy3.9", "pypy3.10", "3.9", "3.10", "3.11", "3.12"] + python-version: ["pypy3.10", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -18,7 +18,6 @@ jobs: run: python -c "import sys; print(sys.version)" - name: Install dependencies run: | - export POETRY_HOME=/opt/poetry python3 -m venv $POETRY_HOME $POETRY_HOME/bin/pip install poetry==1.7.0 $POETRY_HOME/bin/poetry --version @@ -45,6 +44,7 @@ jobs: - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: + POETRY_HOME: /opt/poetry CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} build: name: Build distribution 📦 From 1d7a3d699c289acdd9b778c89ddf1894bc25a71d Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 18:37:15 -0300 Subject: [PATCH 04/15] Fix env var location --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6b6108e..fb86d23 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,9 +43,9 @@ jobs: --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 }} + env: + POETRY_HOME: /opt/poetry + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} build: name: Build distribution 📦 needs: From d13d736f5a910c2f9159bac4736130d2ed20c62c Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 18:58:17 -0300 Subject: [PATCH 05/15] Fix code style --- Makefile | 6 +-- pyproject.toml | 3 ++ setup.cfg | 5 --- src/awesome_git_mosaic/__main__.py | 3 +- .../adapters/console/console_adapter.py | 18 +++++---- .../adapters/git_mosaic/git_mosaic_adapter.py | 28 ++++++++++---- .../charmaps/basic/basic_charmap.py | 37 ++++++++++++------- src/awesome_git_mosaic/charmaps/charmap.py | 1 - .../gateways/git/git_gateway.py | 25 +++++++------ .../usecases/make_commit.py | 1 - .../usecases/modify_file.py | 3 +- .../usecases/write_in_console.py | 1 - .../usecases/write_mosaic.py | 31 ++++++++++------ 13 files changed, 94 insertions(+), 68 deletions(-) diff --git a/Makefile b/Makefile index 5080756..e75a839 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .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: @@ -24,7 +24,7 @@ mypy: poetry run mypy src .PHONY: black-check black-check: - poetry run black --check src + poetry run black --check --diff src .PHONY: black black: @@ -42,4 +42,4 @@ isort: check: isort-check black-check mypy .PHONY: format -format: black isort +format: isort black diff --git a/pyproject.toml b/pyproject.toml index 25e5890..04921b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/setup.cfg b/setup.cfg index 8a42570..7e53643 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/awesome_git_mosaic/__main__.py b/src/awesome_git_mosaic/__main__.py index 5a79506..5698176 100644 --- a/src/awesome_git_mosaic/__main__.py +++ b/src/awesome_git_mosaic/__main__.py @@ -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__": diff --git a/src/awesome_git_mosaic/adapters/console/console_adapter.py b/src/awesome_git_mosaic/adapters/console/console_adapter.py index 376e13c..2a18a0a 100644 --- a/src/awesome_git_mosaic/adapters/console/console_adapter.py +++ b/src/awesome_git_mosaic/adapters/console/console_adapter.py @@ -1,17 +1,17 @@ +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 = " " 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: @@ -19,9 +19,11 @@ def output(self, message: str, with_spaces: bool = True) -> str: 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 CONSOLE_SPACE + ) output.append(output_line) - return '\n'.join(output) + return "\n".join(output) diff --git a/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py b/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py index be37b87..5236bdd 100644 --- a/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py +++ b/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py @@ -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 @@ -9,11 +9,16 @@ 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, + background: bool = False, + ) -> List[datetime]: reference_day = reference_day or datetime.today() lines = self.charmap.translate(message, with_spaces, background) @@ -23,15 +28,24 @@ def output(self, message: str, reference_day: Optional[datetime] = None, with_sp 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 diff --git a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py index 9207dbb..229e2a8 100644 --- a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py +++ b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py @@ -5,39 +5,48 @@ from awesome_git_mosaic.charmaps.charmap import Charmap -CHARMAP_PIXEL = 'o' +CHARMAP_PIXEL = "o" class BasicCharmap(Charmap): - - def __init__(self, model_file: Optional[str] = None, char_width: int = 5, char_height: int = 7, - char_list: str = ' abcdefghijklmnopqrstuvwxyz0123456789#') -> None: + def __init__( + self, + model_file: Optional[str] = None, + char_width: int = 5, + char_height: int = 7, + char_list: str = " abcdefghijklmnopqrstuvwxyz0123456789#", + ) -> None: if not model_file: current_dir = path.dirname(path.abspath(__file__)) - model_file = path.join(current_dir, 'char_model.txt') - self.chars = self._load_char_model(model_file, char_width, char_height, char_list) - - def translate(self, string: str, with_spaces: bool = True, background: bool = False) -> list: + model_file = path.join(current_dir, "char_model.txt") + self.chars = self._load_char_model( + model_file, char_width, char_height, char_list + ) + + def translate( + self, string: str, with_spaces: bool = True, background: bool = False + ) -> list: string = unidecode(string).lower() mapped_chars = [self.chars[c] for c in string] if with_spaces: - space = CHARMAP_PIXEL if background else ' ' + space = CHARMAP_PIXEL if background else " " else: - space = '' + space = "" output = [] for line in range(len(mapped_chars[0])): - output.append(space.join([''.join(char[line]) for char in mapped_chars])) + output.append(space.join(["".join(char[line]) for char in mapped_chars])) return output def is_pixel(self, char: str) -> bool: return char == CHARMAP_PIXEL - def _load_char_model(self, model_file: str, char_width: int, char_height: int, char_list: str) -> dict[str, list[list]]: - - f = open(model_file, 'r') + def _load_char_model( + self, model_file: str, char_width: int, char_height: int, char_list: str + ) -> dict[str, list[list]]: + f = open(model_file, "r") lines = f.read().splitlines(keepends=False) f.close() diff --git a/src/awesome_git_mosaic/charmaps/charmap.py b/src/awesome_git_mosaic/charmaps/charmap.py index 49b907e..00bf2d1 100644 --- a/src/awesome_git_mosaic/charmaps/charmap.py +++ b/src/awesome_git_mosaic/charmaps/charmap.py @@ -1,3 +1,2 @@ class Charmap(object): - chars: dict[str, list[list]] diff --git a/src/awesome_git_mosaic/gateways/git/git_gateway.py b/src/awesome_git_mosaic/gateways/git/git_gateway.py index 0f2343f..21f6537 100644 --- a/src/awesome_git_mosaic/gateways/git/git_gateway.py +++ b/src/awesome_git_mosaic/gateways/git/git_gateway.py @@ -4,32 +4,33 @@ class GitGateway: - - def add(self, path: str = '.'): - return self._git('add', path) + def add(self, path: str = "."): + return self._git("add", path) def commit(self, message: str, date: Optional[datetime] = None): - commit_args = [f"-m\"{message}\""] + commit_args = [f'-m"{message}"'] if date: - commit_args += ['--date', f'"{date.ctime()}"'] - return self._git('commit', *commit_args) + commit_args += ["--date", f'"{date.ctime()}"'] + return self._git("commit", *commit_args) def push(self, branch: Optional[str] = None): if not branch: branch = self._current_branch() - return self._git('push', 'origin', branch) + return self._git("push", "origin", branch) def disable_garbage_collector(self): - return self._git('config', '--local', 'gc.auto', '0') + return self._git("config", "--local", "gc.auto", "0") def enable_garbage_collector(self): - return self._git('config', '--local', 'gc.auto', '1') + return self._git("config", "--local", "gc.auto", "1") def _current_branch(self): - return self._git('rev-parse', '--abbrev-ref', 'HEAD') + return self._git("rev-parse", "--abbrev-ref", "HEAD") def _git(self, command: str, *args): - call_args = ['git', command] + call_args = ["git", command] call_args.extend(args) - return subprocess.run(call_args, stdout=subprocess.PIPE, universal_newlines=True).stdout.rstrip() + return subprocess.run( + call_args, stdout=subprocess.PIPE, universal_newlines=True + ).stdout.rstrip() diff --git a/src/awesome_git_mosaic/usecases/make_commit.py b/src/awesome_git_mosaic/usecases/make_commit.py index 9b8a6cc..095af70 100644 --- a/src/awesome_git_mosaic/usecases/make_commit.py +++ b/src/awesome_git_mosaic/usecases/make_commit.py @@ -4,7 +4,6 @@ class MakeCommit: - def __init__(self, git_gateway: GitGateway = None): self.git_gateway = git_gateway or GitGateway() diff --git a/src/awesome_git_mosaic/usecases/modify_file.py b/src/awesome_git_mosaic/usecases/modify_file.py index a84d835..dd38519 100644 --- a/src/awesome_git_mosaic/usecases/modify_file.py +++ b/src/awesome_git_mosaic/usecases/modify_file.py @@ -4,8 +4,7 @@ class ModifyFile: - - def __init__(self, filename: str = '.awesome_file'): + def __init__(self, filename: str = ".awesome_file"): self.filename = filename def modify(self, content: Optional[str] = None): diff --git a/src/awesome_git_mosaic/usecases/write_in_console.py b/src/awesome_git_mosaic/usecases/write_in_console.py index eac709e..c7da4bc 100644 --- a/src/awesome_git_mosaic/usecases/write_in_console.py +++ b/src/awesome_git_mosaic/usecases/write_in_console.py @@ -2,7 +2,6 @@ class WriteInConsole: - def __init__(self, console_adapter: ConsoleAdapter = None): self.console_adapter = console_adapter or ConsoleAdapter() diff --git a/src/awesome_git_mosaic/usecases/write_mosaic.py b/src/awesome_git_mosaic/usecases/write_mosaic.py index 4de3797..c4d5e30 100644 --- a/src/awesome_git_mosaic/usecases/write_mosaic.py +++ b/src/awesome_git_mosaic/usecases/write_mosaic.py @@ -1,30 +1,38 @@ from datetime import datetime from random import random -from awesome_git_mosaic.adapters.git_mosaic.git_mosaic_adapter import \ - GitMosaicAdapter +from awesome_git_mosaic.adapters.git_mosaic.git_mosaic_adapter import GitMosaicAdapter from awesome_git_mosaic.gateways.git.git_gateway import GitGateway from awesome_git_mosaic.usecases.modify_file import ModifyFile class WriteMosaic: - - def __init__(self, git_mosaic_adapter: GitMosaicAdapter = None, git_gateway: GitGateway = None, - modify_file: ModifyFile = None): - + def __init__( + self, + git_mosaic_adapter: GitMosaicAdapter = None, + git_gateway: GitGateway = None, + modify_file: ModifyFile = None, + ): self.git_mosaic_adapter = git_mosaic_adapter or GitMosaicAdapter() self.git_gateway = git_gateway or GitGateway() self.modify_file = modify_file or ModifyFile() - def write(self, message: str, strength: int = 15, multiply: int = 1, background: bool = False): - + def write( + self, + message: str, + strength: int = 15, + multiply: int = 1, + background: bool = False, + ): timestamps = [] if background: - bgstr = '#' * (len(message) * multiply) - timestamps += self.git_mosaic_adapter.output(bgstr, datetime.today(), True, True) + bgstr = "#" * (len(message) * multiply) + timestamps += self.git_mosaic_adapter.output( + bgstr, datetime.today(), True, True + ) for i in range(strength): - timestamps += self.git_mosaic_adapter.output(f'{message} ' * multiply) + timestamps += self.git_mosaic_adapter.output(f"{message} " * multiply) timestamps.sort() @@ -34,7 +42,6 @@ def write(self, message: str, strength: int = 15, multiply: int = 1, background: print(f"Creating {total} commits...") self.git_gateway.disable_garbage_collector() for timestamp in timestamps: - # print(f"Commit {timestamp}") self.modify_file.modify() self.git_gateway.add() self.git_gateway.commit(f"{timestamp.ctime()} {random()}", timestamp) From 6c84be7a394468c07155456c96eb842aca6534d4 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 19:00:17 -0300 Subject: [PATCH 06/15] Add missing param --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fb86d23..8fdf4e6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,7 @@ jobs: $POETRY_HOME/bin/poetry install - name: Check Code style run: >- - $POETRY_HOME/bin/poetry run pycodestyle --statistics --ignore=E501,E902 --count src + $POETRY_HOME/bin/poetry run pycodestyle --statistics --ignore=E501,W503,E902 --count src - name: Check MyPy run: >- $POETRY_HOME/bin/poetry run mypy src From 18aa389ee6a0630a94cf0288b013f0fecaa29f7d Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 19:11:29 -0300 Subject: [PATCH 07/15] Remove pypy from matrix --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8fdf4e6..057ba22 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["pypy3.10", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 From b902577033fbcb195c42662e621f7a59ac679a7c Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 19:11:49 -0300 Subject: [PATCH 08/15] Add codecov badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8d558aa..af584e2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ +[![codecov](https://codecov.io/gh/justgigio/awesome-git-mosaic/graph/badge.svg?token=0ON0YL8EAH)](https://codecov.io/gh/justgigio/awesome-git-mosaic) + # awesome-git-mosaic A simple tool to make cool tricks with your GitHub activity mosaic From e2d6bebc8cc6f4240d0d75d03a0c86f5b5c6ad35 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 20:06:52 -0300 Subject: [PATCH 09/15] Split actions --- .github/workflows/{publish.yml => build.yml} | 51 ++------------------ .github/workflows/tests.yml | 48 ++++++++++++++++++ README.md | 6 ++- 3 files changed, 57 insertions(+), 48 deletions(-) rename .github/workflows/{publish.yml => build.yml} (61%) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/build.yml similarity index 61% rename from .github/workflows/publish.yml rename to .github/workflows/build.yml index 057ba22..86a2273 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/build.yml @@ -1,55 +1,12 @@ -name: Test and Publish Python 🐍 distribution 📦 to PyPI +name: Build and Publish Python 🐍 distribution 📦 to PyPI on: push 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 }} + tests: + uses: ./.github/workflows/tests.yml build: name: Build distribution 📦 needs: - - test + - tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..64cb590 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,48 @@ +name: Test Python 🐍 distribution +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 }} diff --git a/README.md b/README.md index af584e2..210c006 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ [![codecov](https://codecov.io/gh/justgigio/awesome-git-mosaic/graph/badge.svg?token=0ON0YL8EAH)](https://codecov.io/gh/justgigio/awesome-git-mosaic) - +- Pypi badge +- python version badge +- docs badge +![tests](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/tests.yml/badge.svg) +![build](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/build.yml/badge.svg) # awesome-git-mosaic A simple tool to make cool tricks with your GitHub activity mosaic From 7ccff2ac81ab3eebe9cc286293569640fd9cfaf5 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 20:12:33 -0300 Subject: [PATCH 10/15] Change action names --- .github/workflows/build.yml | 2 +- .github/workflows/tests.yml | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86a2273..65dad98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build and Publish Python 🐍 distribution 📦 to PyPI +name: Build 🐍 on: push jobs: tests: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 64cb590..dd5291c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Test Python 🐍 distribution +name: Test 🐍 on: [workflow_call] jobs: test: diff --git a/README.md b/README.md index 210c006..03e9423 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ - Pypi badge - python version badge - docs badge -![tests](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/tests.yml/badge.svg) +![tests](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/tests.yml/badge.svg?event=workflow_call) ![build](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/build.yml/badge.svg) # awesome-git-mosaic A simple tool to make cool tricks with your GitHub activity mosaic From 6bc2bcc0ef3308abc7c5880050fbd8233c03d97b Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 20:22:54 -0300 Subject: [PATCH 11/15] Make tests run on push --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd5291c..f1bd973 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,5 @@ name: Test 🐍 -on: [workflow_call] +on: [push, workflow_call] jobs: test: runs-on: ubuntu-latest From 5944c4344087ebfcb287cea6d94b7aa8ecbd361d Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Tue, 7 Nov 2023 20:25:03 -0300 Subject: [PATCH 12/15] Remove test action badge --- .github/workflows/tests.yml | 2 +- README.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1bd973..dd5291c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,5 @@ name: Test 🐍 -on: [push, workflow_call] +on: [workflow_call] jobs: test: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 03e9423..51300e8 100644 --- a/README.md +++ b/README.md @@ -1,8 +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 -![tests](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/tests.yml/badge.svg?event=workflow_call) -![build](https://github.com/justgigio/awesome-git-mosaic/actions/workflows/build.yml/badge.svg) # awesome-git-mosaic A simple tool to make cool tricks with your GitHub activity mosaic From ff2b168ae720a70d828dde569fbae4ec016da577 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Wed, 8 Nov 2023 11:18:02 -0300 Subject: [PATCH 13/15] Implement inverted --- .../adapters/console/console_adapter.py | 8 +++++--- .../adapters/git_mosaic/git_mosaic_adapter.py | 4 ++-- .../charmaps/basic/basic_charmap.py | 19 +++++++++---------- .../usecases/write_in_console.py | 4 ++-- .../usecases/write_mosaic.py | 10 ++++++---- tests/charmaps/test_basic_charmap.py | 16 ++++++++-------- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/awesome_git_mosaic/adapters/console/console_adapter.py b/src/awesome_git_mosaic/adapters/console/console_adapter.py index 2a18a0a..c01b9e9 100644 --- a/src/awesome_git_mosaic/adapters/console/console_adapter.py +++ b/src/awesome_git_mosaic/adapters/console/console_adapter.py @@ -8,21 +8,23 @@ CONSOLE_PIXEL = "▉" CONSOLE_SPACE = " " +CONSOLE_BG = '░' class ConsoleAdapter: 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 = "" for char in line: output_line += ( - CONSOLE_PIXEL if self.charmap.is_pixel(char) else CONSOLE_SPACE + CONSOLE_PIXEL if self.charmap.is_pixel(char) else bg ) output.append(output_line) diff --git a/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py b/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py index 5236bdd..ffa5f40 100644 --- a/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py +++ b/src/awesome_git_mosaic/adapters/git_mosaic/git_mosaic_adapter.py @@ -17,10 +17,10 @@ def output( message: str, reference_day: Optional[datetime] = None, with_spaces: bool = True, - background: bool = False, + 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 diff --git a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py index 229e2a8..8fd4ce5 100644 --- a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py +++ b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py @@ -16,6 +16,7 @@ def __init__( char_height: int = 7, char_list: str = " abcdefghijklmnopqrstuvwxyz0123456789#", ) -> None: + self.char_height = char_height if not model_file: current_dir = path.dirname(path.abspath(__file__)) model_file = path.join(current_dir, "char_model.txt") @@ -23,20 +24,18 @@ def __init__( model_file, char_width, char_height, char_list ) - def translate( - self, string: str, with_spaces: bool = True, background: bool = False - ) -> list: + def translate(self, string: str, with_spaces: bool = True, inverted: bool = False) -> list: string = unidecode(string).lower() mapped_chars = [self.chars[c] for c in string] - if with_spaces: - space = CHARMAP_PIXEL if background else " " - else: - space = "" - output = [] + space = " " if with_spaces else "" - for line in range(len(mapped_chars[0])): - output.append(space.join(["".join(char[line]) for char in mapped_chars])) + output = [] + for line in range(self.char_height): + line_str = space.join(["".join(char[line]) for char in mapped_chars]) + if inverted: + line_str = line_str.translate(str.maketrans(f"{CHARMAP_PIXEL} ", f" {CHARMAP_PIXEL}")) + output.append(line_str) return output diff --git a/src/awesome_git_mosaic/usecases/write_in_console.py b/src/awesome_git_mosaic/usecases/write_in_console.py index c7da4bc..fa1398c 100644 --- a/src/awesome_git_mosaic/usecases/write_in_console.py +++ b/src/awesome_git_mosaic/usecases/write_in_console.py @@ -5,6 +5,6 @@ class WriteInConsole: def __init__(self, console_adapter: ConsoleAdapter = None): self.console_adapter = console_adapter or ConsoleAdapter() - def write(self, text: str, with_spaces: bool = True): - output = self.console_adapter.output(text, with_spaces) + def write(self, text: str, with_spaces: bool = True, background: bool = False, inverted: bool = False): + output = self.console_adapter.output(text, with_spaces, background, inverted) print(output) diff --git a/src/awesome_git_mosaic/usecases/write_mosaic.py b/src/awesome_git_mosaic/usecases/write_mosaic.py index c4d5e30..9bf40a4 100644 --- a/src/awesome_git_mosaic/usecases/write_mosaic.py +++ b/src/awesome_git_mosaic/usecases/write_mosaic.py @@ -22,17 +22,19 @@ def write( message: str, strength: int = 15, multiply: int = 1, + with_spaces: bool = True, background: bool = False, + inverted: bool = False, ): timestamps = [] if background: - bgstr = "#" * (len(message) * multiply) + bgstr = " " * (len(message) * multiply) timestamps += self.git_mosaic_adapter.output( - bgstr, datetime.today(), True, True + bgstr, datetime.today(), with_spaces, True ) - for i in range(strength): - timestamps += self.git_mosaic_adapter.output(f"{message} " * multiply) + for _ in range(strength): + timestamps += self.git_mosaic_adapter.output(f"{message} " * multiply, None, with_spaces, inverted) timestamps.sort() diff --git a/tests/charmaps/test_basic_charmap.py b/tests/charmaps/test_basic_charmap.py index 6bad16c..ff67a93 100644 --- a/tests/charmaps/test_basic_charmap.py +++ b/tests/charmaps/test_basic_charmap.py @@ -20,19 +20,19 @@ def test_translate(self): assert lines == fox - def test_translate_with_background(self): + def test_translate_inverted(self): charmap = BasicCharmap() lines = charmap.translate('FoX', True, True) fox = [ - 'oooooo ooo oo o', - 'o oo ooo o', - 'o oo oo o o ', - 'ooo oo oo o ', - 'o oo oo o o ', - 'o oo ooo o', - 'o o ooo oo o' + ' oo oo ooo ', + ' ooooo ooo o ooo ', + ' ooooo ooo oo o o', + ' ooo ooo ooo oo', + ' ooooo ooo oo o o', + ' ooooo ooo o ooo ', + ' oooooo oo ooo ' ] assert lines == fox From 43e1e4ab0d0f9aa79f82db8d0ceddf089f07b989 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Wed, 8 Nov 2023 11:23:00 -0300 Subject: [PATCH 14/15] Fix codestyle --- Makefile | 13 +++++++------ .../adapters/console/console_adapter.py | 14 +++++++++----- .../charmaps/basic/basic_charmap.py | 8 ++++++-- .../usecases/write_in_console.py | 8 +++++++- src/awesome_git_mosaic/usecases/write_mosaic.py | 4 +++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index e75a839..dbb0c3c 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,6 @@ code-style: 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 @@ -20,7 +16,8 @@ build: poetry build .PHONY: mypy -mypy: poetry run mypy src +mypy: + poetry run mypy src .PHONY: black-check black-check: @@ -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: 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 diff --git a/src/awesome_git_mosaic/adapters/console/console_adapter.py b/src/awesome_git_mosaic/adapters/console/console_adapter.py index c01b9e9..0bbdca7 100644 --- a/src/awesome_git_mosaic/adapters/console/console_adapter.py +++ b/src/awesome_git_mosaic/adapters/console/console_adapter.py @@ -8,14 +8,20 @@ CONSOLE_PIXEL = "▉" CONSOLE_SPACE = " " -CONSOLE_BG = '░' +CONSOLE_BG = "░" class ConsoleAdapter: def __init__(self, charmap: Optional["Charmap"] = None): self.charmap = charmap or BasicCharmap() - def output(self, message: str, with_spaces: bool = True, background: bool = False, inverted: bool = False) -> str: + 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 @@ -23,9 +29,7 @@ def output(self, message: str, with_spaces: bool = True, background: bool = Fals for line in lines: output_line = "" for char in line: - output_line += ( - CONSOLE_PIXEL if self.charmap.is_pixel(char) else bg - ) + output_line += CONSOLE_PIXEL if self.charmap.is_pixel(char) else bg output.append(output_line) return "\n".join(output) diff --git a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py index 8fd4ce5..40986ca 100644 --- a/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py +++ b/src/awesome_git_mosaic/charmaps/basic/basic_charmap.py @@ -24,7 +24,9 @@ def __init__( model_file, char_width, char_height, char_list ) - def translate(self, string: str, with_spaces: bool = True, inverted: bool = False) -> list: + def translate( + self, string: str, with_spaces: bool = True, inverted: bool = False + ) -> list: string = unidecode(string).lower() mapped_chars = [self.chars[c] for c in string] @@ -34,7 +36,9 @@ def translate(self, string: str, with_spaces: bool = True, inverted: bool = Fals for line in range(self.char_height): line_str = space.join(["".join(char[line]) for char in mapped_chars]) if inverted: - line_str = line_str.translate(str.maketrans(f"{CHARMAP_PIXEL} ", f" {CHARMAP_PIXEL}")) + line_str = line_str.translate( + str.maketrans(f"{CHARMAP_PIXEL} ", f" {CHARMAP_PIXEL}") + ) output.append(line_str) return output diff --git a/src/awesome_git_mosaic/usecases/write_in_console.py b/src/awesome_git_mosaic/usecases/write_in_console.py index fa1398c..d0c68ea 100644 --- a/src/awesome_git_mosaic/usecases/write_in_console.py +++ b/src/awesome_git_mosaic/usecases/write_in_console.py @@ -5,6 +5,12 @@ class WriteInConsole: def __init__(self, console_adapter: ConsoleAdapter = None): self.console_adapter = console_adapter or ConsoleAdapter() - def write(self, text: str, with_spaces: bool = True, background: bool = False, inverted: bool = False): + def write( + self, + text: str, + with_spaces: bool = True, + background: bool = False, + inverted: bool = False, + ): output = self.console_adapter.output(text, with_spaces, background, inverted) print(output) diff --git a/src/awesome_git_mosaic/usecases/write_mosaic.py b/src/awesome_git_mosaic/usecases/write_mosaic.py index 9bf40a4..e2decc8 100644 --- a/src/awesome_git_mosaic/usecases/write_mosaic.py +++ b/src/awesome_git_mosaic/usecases/write_mosaic.py @@ -34,7 +34,9 @@ def write( ) for _ in range(strength): - timestamps += self.git_mosaic_adapter.output(f"{message} " * multiply, None, with_spaces, inverted) + timestamps += self.git_mosaic_adapter.output( + f"{message} " * multiply, None, with_spaces, inverted + ) timestamps.sort() From be80992a4a259856077b6207a8aa9df4fe8b0a10 Mon Sep 17 00:00:00 2001 From: Giovane Costa Date: Wed, 8 Nov 2023 12:29:46 -0300 Subject: [PATCH 15/15] Change modify and commit strategy --- .gitignore | 3 ++ src/awesome_git_mosaic/__init__.py | 13 +++++++-- .../usecases/modify_file.py | 28 +++++++++++++++---- .../usecases/write_mosaic.py | 21 ++++++++++---- tests/usecases/test_modify_file.py | 24 +++++++--------- 5 files changed, 62 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index b6e4761..c368065 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +.awesome_folder +.__testing_modify_folder \ No newline at end of file diff --git a/src/awesome_git_mosaic/__init__.py b/src/awesome_git_mosaic/__init__.py index 2b2a150..5383e55 100644 --- a/src/awesome_git_mosaic/__init__.py +++ b/src/awesome_git_mosaic/__init__.py @@ -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 diff --git a/src/awesome_git_mosaic/usecases/modify_file.py b/src/awesome_git_mosaic/usecases/modify_file.py index dd38519..e6ff6e7 100644 --- a/src/awesome_git_mosaic/usecases/modify_file.py +++ b/src/awesome_git_mosaic/usecases/modify_file.py @@ -1,14 +1,30 @@ +import os import uuid -from random import random from typing import Optional +FOLDER_NAME = ".awesome_folder" + class ModifyFile: - def __init__(self, filename: str = ".awesome_file"): - self.filename = filename + def __init__(self, folder_name: str = FOLDER_NAME): + self.folder_name = folder_name + self._mkdir() + + def modify(self, namespace: str = "default", content: Optional[str] = None): + path = self._mkdir(namespace) + filename = str(uuid.uuid4()) + content = content or filename + + self._write(path, filename, content) + + def _mkdir(self, name: str = "") -> str: + path = os.path.join(self.folder_name, name) + if not os.path.exists(path): + os.mkdir(path) + + return path - def modify(self, content: Optional[str] = None): - content = content or f"{uuid.uuid4()} {random()}" - f = open(self.filename, "w+") + def _write(self, path: str, filename: str, content: str): + f = open(os.path.join(path, filename), "w+") f.write(content) f.close() diff --git a/src/awesome_git_mosaic/usecases/write_mosaic.py b/src/awesome_git_mosaic/usecases/write_mosaic.py index e2decc8..2a56827 100644 --- a/src/awesome_git_mosaic/usecases/write_mosaic.py +++ b/src/awesome_git_mosaic/usecases/write_mosaic.py @@ -1,5 +1,4 @@ from datetime import datetime -from random import random from awesome_git_mosaic.adapters.git_mosaic.git_mosaic_adapter import GitMosaicAdapter from awesome_git_mosaic.gateways.git.git_gateway import GitGateway @@ -26,7 +25,7 @@ def write( background: bool = False, inverted: bool = False, ): - timestamps = [] + timestamps: list[datetime] = [] if background: bgstr = " " * (len(message) * multiply) timestamps += self.git_mosaic_adapter.output( @@ -43,12 +42,15 @@ def write( total = len(timestamps) count = 0.0 last_pct = 0 - print(f"Creating {total} commits...") + + print(f"Disabling git Garbage Collector...") self.git_gateway.disable_garbage_collector() + + print(f"Creating {total} commits...") for timestamp in timestamps: - self.modify_file.modify() + self.modify_file.modify(timestamp.ctime()) self.git_gateway.add() - self.git_gateway.commit(f"{timestamp.ctime()} {random()}", timestamp) + self.git_gateway.commit(f"{timestamp.ctime()} {count}", timestamp) count += 1 pct = round(count * 100 / total) @@ -57,5 +59,14 @@ def write( print(f"{pct}%") last_pct = pct + if count % 500 == 0: + print(f"{count} commits created, pushing") + self.git_gateway.push() + + print("All commits created. Last push...") self.git_gateway.push() + + print(f"Re-enabling git Garbage Collector...") self.git_gateway.enable_garbage_collector() + + print("That's all, folks! Bye!") diff --git a/tests/usecases/test_modify_file.py b/tests/usecases/test_modify_file.py index 9617bd8..626ac73 100644 --- a/tests/usecases/test_modify_file.py +++ b/tests/usecases/test_modify_file.py @@ -1,4 +1,5 @@ import os +import shutil from awesome_git_mosaic.usecases.modify_file import ModifyFile @@ -6,20 +7,15 @@ class TestModifyFile: def test_file_is_modified(self): - filename = '.__testing_modify_file' - initial_content = 'initial content' + foldername = '.__testing_modify_folder' - f = open(filename, 'w+') - f.write(initial_content) - f.close() + mf = ModifyFile(foldername) + mf.modify('namespace') + mf.modify('namespace') + mf.modify('namespace', 'something') + mf.modify('namespace2') - mf = ModifyFile(filename) - mf.modify() + assert len(os.listdir(foldername)) == 2 + assert len(os.listdir(os.path.join(foldername, 'namespace'))) == 3 - f = open(filename, 'r') - actual_content = f.read() - f.close() - - os.remove(filename) - - assert initial_content != actual_content + shutil.rmtree(foldername)