termynal / termynal.py

Python markdown terminal. Built for mkdocs
https://termynal.github.io/termynal.py/
MIT License
85 stars 8 forks source link

feat: make the processor configurable to customize termynal.js behavior #6

Closed Guts closed 1 year ago

Guts commented 1 year ago

Hello @daxartio, in this PR, I propose to expose some options related to termynal.js to the markdown processor.

Given this markdown:

# Header

<!-- termynal -->

pip install --upgrade termynal ---> 100%

You can then use this:

def convert(md: str, config: dict = {}):
    return markdown(
        md,
        extensions=[
            "fenced_code",
            TermynalExtension(**{"prompt_literal_start": ["&gt; "]}),
        ],
    )

And so, through the Mkdocs plugin:

[...]
markdown_extensions:
  - admonition
  - codehilite
  - pymdownx.superfences
  - termynal:
      prompt_literal_start:
        - "$ "
        - "&gt; "
[...]

For now, the only supported option is prompt_literal_start, corresponding to the data-ty-prompt of termynal.js.

Sorry for the multiple commits, I've been interrupted so it's quite messy. If you want, I can squash.


About the tooling

As said in my previous PR, I don't use poetry and I'm not willing to. But to play fair, I tried to comply with the required setup to contribute to your project and I've installed poetry (running Ubuntu 22.04).

Still, I'm facing this issue:

termynal on ξ‚  feature/make-it-configurable is πŸ“¦ v0.3.1 via 🐍 v3.8.10 
❯ make all
poetry run ruff --fix termynal tests

  RuntimeError

  The Poetry configuration is invalid:
    - Additional properties are not allowed ('group' was unexpected)

  at ~/.poetry/lib/poetry/_vendor/py3.10/poetry/core/factory.py:43 in create_poetry
       39β”‚             message = ""
       40β”‚             for error in check_result["errors"]:
       41β”‚                 message += "  - {}\n".format(error)
       42β”‚ 
    β†’  43β”‚             raise RuntimeError("The Poetry configuration is invalid:\n" + message)
       44β”‚ 
       45β”‚         # Load package
       46β”‚         name = local_config["name"]
       47β”‚         version = local_config["version"]
make: *** [Makefile:55 : format] Erreur 1

Then I'm using ruff too, but installing it with pip and running it, I do not have the same error than in the CI...

daxartio commented 1 year ago

It is awesome!

I will review of PR in few days

daxartio commented 1 year ago

Can you do a rebase? I separated lint and test jobs in github actions

Guts commented 1 year ago

Can you do a rebase? I separated lint and test jobs in github actions

Done.

Guts commented 1 year ago

@daxartio I've finally fixed every warning but I'm still convinced that setup is overkill for a project of this size!

Your project, your choice, fine. But please, make it more explicit by documenting how to work locally and usable than hidden under the hood of a makefile (not cross-platform) and a 3rd part tool (even as common as poetry is).

(sorry if my ton is too harsh, I'm not native English speaking)

daxartio commented 1 year ago

Thank you for your changes!

I got it about makefile. I will think about it. I usually use code tools in any project, because sometimes i make mistakes.

Also you can run a code tool from cli just copy it from makefile and delete poetry run. E.g. mypy termynal, black --check termynal, ruff termynal

Guts commented 1 year ago

Thank you for your changes!

Thank you for accepting PR and reviewing fast.

I got it about makefile. I will think about it. I usually use code tools in any project, because i sometimes do mistakes.

Thank you for taking it into account!

Also you can run a code tool from cli just copy it from makefile and delete poetry run. E.g. mypy termynal, black --check termynal, ruff termynal

As said in my description, I ran the commands manually (except mypy) but it was not giving the same result.

What about a PR introducing pre-commit? It's another way to check before CI, it's locally, eventually verbose and manage configuration.

daxartio commented 1 year ago

Yeah. But i really don't like pre-commit, sorry. Because it usually works slowly and can be broken. I think about use it only for checking conventional commits.

Can you show some examples?

daxartio commented 1 year ago

As said in my description, I ran the commands manually (except mypy) but it was not giving the same result.

Did you use a common venv for the project? I usually use a venv in the a project in a .venv dir. And i install deps from lock file, cause different deps can give different result

daxartio commented 1 year ago
termynal on ξ‚  feature/make-it-configurable is πŸ“¦ v0.3.1 via 🐍 v3.8.10 
❯ make all
poetry run ruff --fix termynal tests

  RuntimeError

  The Poetry configuration is invalid:
    - Additional properties are not allowed ('group' was unexpected)

  at ~/.poetry/lib/poetry/_vendor/py3.10/poetry/core/factory.py:43 in create_poetry
       39β”‚             message = ""
       40β”‚             for error in check_result["errors"]:
       41β”‚                 message += "  - {}\n".format(error)
       42β”‚ 
    β†’  43β”‚             raise RuntimeError("The Poetry configuration is invalid:\n" + message)
       44β”‚ 
       45β”‚         # Load package
       46β”‚         name = local_config["name"]
       47β”‚         version = local_config["version"]
make: *** [Makefile:55 : format] Erreur 1

I looked at your error again and understood that you used version of poetry less then 1.3.2

Guts commented 1 year ago

Did you use a common venv for the project? I usually use a venv in the a project in a .venv dir. And i install deps from lock file, cause different deps can give different result

Of course I'm in a venv (.venv too). I do not install from the lock, I pin versions.

I looked at your error again and understood that you used version of poetry less then 1.3.2

Indeed:

❯ poetry --version
Poetry version 1.1.13

I've installed poetry using the command available in official documentation. Rerunning it:

❯ curl -sSL https://install.python-poetry.org | python3 -
Retrieving Poetry metadata

The latest version (1.5.1) is already installed.

Running self update:

❯ poetry self update
Updating to 1.5.1

  RuntimeError

  Could not find poetry-1.5.1-linux.sha256sum file

  at .poetry/lib/poetry/console/commands/self/update.py:260 in _update
      256β”‚         try:
      257β”‚             r = urlopen(base_url + "/{}/{}".format(version, checksum))
      258β”‚         except HTTPError as e:
      259β”‚             if e.code == 404:
    β†’ 260β”‚                 raise RuntimeError("Could not find {} file".format(checksum))
      261β”‚ 
      262β”‚             raise
      263β”‚ 
      264β”‚         checksum = r.read().decode().strip()

This is why I don't like this superset of Python environment tooling!

daxartio commented 1 year ago

This is why I don't like this superset of Python environment tooling!

I see! So i think about Rust πŸ˜„