Skip to content

Commit

Permalink
Use dinject (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
cariad authored Oct 10, 2021
1 parent 952845c commit a8d4495
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 319 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ orbs:
jobs:
build:
docker:
- image: cimg/python:3.9.6
- image: cimg/python:3.10.0
environment:
PIPENV_VENV_IN_PROJECT: true
resource_class: small
steps:
- checkout
- restore_cache:
keys:
- pipenv-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
- pipenv-{{ .Branch }}-
- pipenv-
- pipenv-3100-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
- pipenv-3100-{{ .Branch }}-
- pipenv-3100-
- run: pipenv sync --dev
- save_cache:
key: pipenv-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
key: pipenv-3100-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
paths:
- .venv
- run: pipenv run ./lint.sh
- run: pipenv run pytest
- run: pipenv run ./test.sh
- codecov/upload:
file: coverage.xml
- run: pipenv run ./build.sh
Expand Down
2 changes: 2 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
line-length: false
no-trailing-punctuation: false
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ansiscape",
"Blackletter",
"CMYB",
"dinject",
"epilog",
"naughtty",
"RGBA",
Expand Down
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name = "pypi"

[dev-packages]
black = "==21.8b0"
dinject = "~=1.0.4"
flake8 = "*"
isort = "*"
mkdocs = "*"
Expand All @@ -18,4 +19,4 @@ shellcheck-py = "*"
yamllint = "*"

[requires]
python_version = "3.9"
python_version = "3.10"
371 changes: 194 additions & 177 deletions Pipfile.lock

Large diffs are not rendered by default.

46 changes: 16 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,14 @@ For example:
ls --color | ansiscape
```

```json
[
{
"background": -1,
"foreground": 4,
"weight": 1
},
"ansiscape",
{
"background": -1
},
"\n",
{
"foreground": 4,
"weight": 1
},
"ansiscape.egg-info",
{
"background": -1
},
"\n",
{
"foreground": 2,
"weight": 1
},
"build.sh",
...
]
<!--dinject as=markdown host=shell range=start-->

```text
[{"background": -1, "foreground": 4, "weight": 1},"ansiscape",{"background": -1},"\n",{"foreground": 4, "weight": 1},"ansiscape.egg-info",{"background": -1},"\n",{"foreground": 2, "weight": 1},"build.sh",{"background": -1},"\ncoverage.xml\n",{"foreground": 4, "weight": 1},"dist",{"background": -1},"\n",{"foreground": 4, "weight": 1},"docs",{"background": -1},"\n",{"foreground": 4, "weight": 1},"htmlcov",{"background": -1},"\nLICENSE\n",{"foreground": 2, "weight": 1},"lint.sh",{"background": -1},"\nMANIFEST.in\nmkdocs.yml\nmypy.ini\nPipfile\nPipfile.lock\npyproject.toml\nREADME.md\nsetup.py\n",{"foreground": 4, "weight": 1},"tests",{"background": -1},"\n",{"foreground": 2, "weight": 1},"test.sh",{"background": -1}]
```

<!--dinject range=end-->

Full documentation is published at [ansiscape.readthedocs.io](https://ansiscape.readthedocs.io).

## Basic Python usage
Expand All @@ -73,10 +51,14 @@ from ansiscape import heavy
print(heavy("Hello, world!"))
```

<!--dinject as=markdown host=shell range=start-->

```text
\033[1mHello, world!\033[22m
[1mHello, world![22m
```

<!--dinject range=end-->

These functions can be nested to create complex formatted strings. Specific instructions can also be embedded:

```python
Expand All @@ -92,10 +74,14 @@ sequence = Sequence(
print(sequence)
```

<!--dinject as=markdown host=shell range=start-->

```text
\033[1mHello, world!\033[22m
[1mHello, world![22m
```

<!--dinject range=end-->

Full documentation is published at [ansiscape.readthedocs.io](https://ansiscape.readthedocs.io).

## 👋 Hello!
Expand Down
103 changes: 18 additions & 85 deletions docs/cli.md

Large diffs are not rendered by default.

34 changes: 16 additions & 18 deletions docs/read.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ for part in sequence.resolved:
print(part)
```

```python
"Hello world, and "
{"calligraphy": Calligraphy.ITALIC}
"you"
{"calligraphy": Calligraphy.NONE}
" in particular!"
<!--dinject as=markdown host=shell range=start-->

```text
Hello world, and
{'calligraphy': <Calligraphy.ITALIC: 2>}
you
{'calligraphy': <Calligraphy.NONE: 0>}
in particular!
```

<!--dinject range=end-->

Note that strings with embedded escape codes can be passed into the `Sequence` initialiser, but these will be converted to sub-sequences of plain strings and [`Interpretation`](interpretation.md) dictionaries. The `resolved` property will never return strings with embedded escape codes.

## Writing a JSON stream
Expand All @@ -42,19 +46,13 @@ sequence = Sequence("Hello world, and \033[3myou\033[23m in particular!")
sequence.write_json(stdout)
```

```json
[
"Hello world, and ",
{
"calligraphy": 2
},
"you",
{
"calligraphy": 0
},
" in particular!"
]
<!--dinject as=markdown host=shell range=start-->

```text
["Hello world, and ",{"calligraphy": 2},"you",{"calligraphy": 0}," in particular!"]
```

<!--dinject range=end-->

!!! question
**Why not just provide the JSON as a plain string property?** Because it can be _huge_. Chances are, if you want JSON then you want to write it somewhere, and using TextIO can fulfil that while minimising memory usage.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Utilities",
"Typing :: Typed",
]
Expand All @@ -33,9 +34,9 @@

setup(
author="Cariad Eccleston",
author_email="cariad@cariad.io",
author_email="cariad@cariad.earth",
classifiers=classifiers,
description="Python package and CLI tool for creating and interpreting ANSI escape codes",
description="Create and interpret ANSI escape codes",
entry_points={
"console_scripts": [
"ansiscape=ansiscape.__main__:cli_entry",
Expand Down
5 changes: 5 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/env bash
set -euo pipefail

pytest -vv
dinject README.md docs/cli.md docs/read.md

0 comments on commit a8d4495

Please sign in to comment.