Skip to content

Commit

Permalink
v0.2.0 (#2)
Browse files Browse the repository at this point in the history
* fix: remove agg binary

* fix: ignore WPS232 inside `setup.py`
fix: add the `build` folder to ignore

* fix: add the `bin` folder to ignore

* fix: fix agg path

* feat: add a multiplatform agg executable

* fix: fix agg path

* fix: fix agg version

* feat: add the `PROJECT_ROOT` constant

* feat: add `LocalCommandBuilder`

* feat: add functional tests

* fix: fix typings

* feat: now the example is using jetbrains mono

* fix: remove `FontFamily`

* fix: remove `FontFamily`
feat: add validators for the `font_family` field

* style: fix flake8 issues

* test: run tests on MacOS

* Update main.yml

* fix: fix typo

* fix: fix typo

* fix: fix typo

* fix: remove a windows "support"

* docs: add a note for JetBrains Mono usage

* fix: remove todos

* docs: change `font_family` description

* feat: add new WIP themes (JetBrains Light and JetBrains Dark)
  • Loading branch information
GirZ0n authored Mar 13, 2023
1 parent 53ffd0f commit f450601
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 51 deletions.
7 changes: 5 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ ignore=WPS100, # Found wrong module name
E402, # Module level import not at top of file.

# WPS226: Found string literal over-use
per-file-ignores=anderson/config/choices.py:WPS226
# WPS232: Found module cognitive complexity that is too high
per-file-ignores=
anderson/config/choices.py:WPS226
setup.py:WPS232

application-import-names=anderson

exclude=.venv,venv,test,examples
exclude=.venv,venv,test,examples,build
94 changes: 70 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,63 @@ name: Python build

on: [push]

env:
JETBRAINS_MONO_VERSION: 2.304
PYTHON_VERSION: "3.8"

jobs:
setup:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Install virtualenv
run: |
sudo apt update
sudo apt install python3-pip
python -m pip install virtualenv
- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Python virtual environment
id: pip-cache
uses: actions/cache@v3
with:
path: ./.venv
path: ./venv
key: ${{ runner.os }}-pip-cache-${{ hashFiles('./requirements*.txt') }}

- name: Install Python requirements
if: steps.pip-cache.outputs.cache-hit != 'true'
run: |
virtualenv ./.venv
source ./.venv/bin/activate
pip install -r ./requirements.txt -r ./requirements-code-style.txt
python3 -m venv venv
source venv/bin/activate
pip install -r ./requirements.txt -r ./requirements-code-style.txt -r ./requirements-test.txt
code-style:
needs: setup

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Python virtual environment
id: pip-cache
uses: actions/cache@v3
with:
path: ./.venv
path: ./venv
key: ${{ runner.os }}-pip-cache-${{ hashFiles('./requirements*.txt') }}

- name: Run python static code analyzers
- name: Run Flake8
run: |
source ./.venv/bin/activate
source ./venv/bin/activate
flake8 . --count --statistics --config ./.flake8
- name: Run Black
Expand All @@ -54,17 +68,49 @@ jobs:

test:
needs: code-style
runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3


- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Python virtual environment
id: pip-cache
uses: actions/cache@v3
with:
path: ./venv
key: ${{ runner.os }}-pip-cache-${{ hashFiles('./requirements*.txt') }}

- name: Install anderson
run: pip install .

- name: Check anderson is working
run: anderson "python3 ./examples/python_bot/main.py" ./examples/python_bot/out/ ./examples/python_bot/config.yaml --debug
run: |
source ./venv/bin/activate
pip install .
- name: Download JetBrains Mono
run: |
curl -sLO https://github.com/JetBrains/JetBrainsMono/releases/download/v$JETBRAINS_MONO_VERSION/JetBrainsMono-$JETBRAINS_MONO_VERSION.zip
unzip JetBrainsMono-$JETBRAINS_MONO_VERSION.zip
- uses: actions/upload-artifact@v3
with:
name: python-bot-gifs
path: ./examples/python_bot/out/
- name: Install JetBrains Mono on MacOS
if: matrix.os == 'macos-latest'
run: cp fonts/ttf/JetBrainsMono-Regular.ttf /Library/Fonts/

- name: Install JetBrains Mono on Linux
if: matrix.os == 'ubuntu-latest'
run: |
sudo cp fonts/ttf/JetBrainsMono-Regular.ttf /usr/local/share/fonts/
fc-cache -f -v
- name: Test anderson
run: |
source ./venv/bin/activate
pytest . -vv
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ fabric.properties
*.egg-info/
*.installed.cfg
*.egg

# Custom
anderson/bin/*
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ The `gifs` list item consists of the following arguments:
The names of the available themes are listed in the `Theme` enum-class located [here](anderson/config/choices.py).
More information about the list of colors can be found [here](https://github.com/asciinema/agg#color-themes).
By default, `dracula`.
- `font_family`Name of the font family. The available values are given in the `FontFamily` enum-class located
[here](anderson/config/choices.py). **Note**: the selected font family must be installed on your system.
By default, `Liberation Mono`.
- `font_family`Names of font families. It can either be a string of names separated by a comma, or a list of strings.
By default, `JetBrains Mono,Liberation Mono,Andale Mono`.
**Note**: if some font family is not installed on the system, the next one after it will be used to create the GIF.
- `font_size` – Font size (in pixels). By default, `14`.
- `fps_cap` – FPS cap. By default, `30`.
- `line_height` – Line height. By default, `1.4`.
Expand Down
Binary file removed anderson/bin/agg
Binary file not shown.
55 changes: 44 additions & 11 deletions anderson/config/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Theme(Enum):
MONOKAY = 'monokai'
SOLARIZED_DARK = 'solarized_dark'
SOLARIZED_LIGHT = 'solarized_light'
# Custom themes
JETBRAINS_DARK = 'jetbrains_dark'
JETBRAINS_LIGHT = 'jetbrains_light'

@classmethod
def values(cls) -> List[str]:
Expand Down Expand Up @@ -116,17 +119,47 @@ def to_hex(self) -> List[str]:
'93a1a1',
'fdf6e3',
],
# TODO: Fix a color palette for JetBrains Dark and JetBrains Light
self.JETBRAINS_DARK: [
'3c3f41',
'bbbbbb',
'073642',
'dc322f',
'859900',
'b58900',
'268bd2',
'd33682',
'2aa198',
'eee8d5',
'002b36',
'cb4b16',
'586e75',
'657b83',
'839496',
'6c71c4',
'93a1a1',
'fdf6e3',
],
self.JETBRAINS_LIGHT: [
'fafafa',
'000000',
'073642',
'dc322f',
'859900',
'b58900',
'268bd2',
'd33682',
'2aa198',
'eee8d5',
'002b36',
'cb4b16',
'586e75',
'657c83',
'839496',
'6c71c4',
'93a1a1',
'fdf6e3',
],
}

return theme_to_hex[self]


class FontFamily(str, Enum): # noqa: WPS600
# Consistent with https://github.com/asciinema/agg/blob/4b605b6eb670bfaba2cfda1cb258cfbfdfc1f2d4/src/main.rs#L136
JETBRAINS_MONO = 'JetBrains Mono'
FIRA_CODE = 'Fira Code'
SF_MONO = 'SF Mono'
MENLO = 'Menlo'
CONSOLAS = 'Consolas'
DEJAVU_SANS_MONO = 'DejaVu Sans Mono'
LIBERATION_MONO = 'Liberation Mono'
26 changes: 20 additions & 6 deletions anderson/config/model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
from typing import Any, List

from pydantic import BaseModel, PositiveFloat, PositiveInt, conlist, validator
from pydantic import BaseModel, NonNegativeInt, PositiveFloat, PositiveInt, conlist, validator

from anderson.config.action import ActionType
from anderson.config.choices import FontFamily, Theme
from anderson.config.choices import Theme


class TerminalConfig(BaseModel):
Expand All @@ -13,21 +13,35 @@ class TerminalConfig(BaseModel):


class InteractionConfig(BaseModel):
keystroke_delay: PositiveInt = 150
keystroke_std: PositiveInt = 60
action_delay: PositiveInt = 80
keystroke_delay: NonNegativeInt = 150
keystroke_std: NonNegativeInt = 60
action_delay: NonNegativeInt = 80


class Gif(BaseModel):
name: str
theme: List[str] = Theme.DRACULA.to_hex()
font_family: FontFamily = FontFamily.LIBERATION_MONO
font_family: str = 'JetBrains Mono,Liberation Mono,Andale Mono'
font_size: PositiveInt = 14
fps_cap: PositiveInt = 30
line_height: PositiveFloat = 1.4
speed: PositiveFloat = 1.0
no_loop: bool = False

@validator('font_family', pre=True)
def check_font_family_list(cls, value: Any) -> Any: # noqa: N805
if isinstance(value, list) and not all(isinstance(elem, str) for elem in value):
raise ValueError('the list must contain only strings')

return value

@validator('font_family', pre=True)
def convert_font_family(cls, value: Any) -> Any: # noqa: N805
if isinstance(value, list):
return ','.join(value)

return value

@validator('theme', pre=True)
def convert_string_theme_to_list(cls, value: Any) -> Any: # noqa: N805
if isinstance(value, str):
Expand Down
4 changes: 2 additions & 2 deletions anderson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path
from typing import List


AGG_PATH = Path(__file__).parent / 'bin' / 'agg'
PROJECT_ROOT = Path(__file__).parents[1]
AGG_PATH = PROJECT_ROOT / 'anderson' / 'bin' / 'agg'

logger = logging.getLogger(__name__)

Expand Down
7 changes: 6 additions & 1 deletion examples/python_bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ Just run the following command:
```bash
anderson "python3 main.py" ./gifs ./config.yaml
```
And in the gifs folder you will get the following gifs:

**Note**: You need to have the `JetBrains Mono` font in your system in order for the GIFs to be generated.
You can download the font [here](https://www.jetbrains.com/lp/mono/).
You can also change the font in the config to any other font that is installed in your system.

In the `gifs` folder you will get the following gifs:
- `light.gif`:
![light.gif](gifs%2Flight.gif)
- `dark.gif`:
Expand Down
1 change: 1 addition & 0 deletions examples/python_bot/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
gif_config:
common:
font_size: 32
font_family: JetBrains Mono

gifs:
- name: 'dark'
Expand Down
Binary file modified examples/python_bot/gifs/dark.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/python_bot/gifs/light.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.2.2
pillow==9.4.0
Loading

0 comments on commit f450601

Please sign in to comment.