Skip to content

Remove kaptan -> ConfigReader #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

- _Insert changes/features/fixes for next release here_

**Maintenance release, no features or fixes**

### Internal

- Add `ConfigReader`: Our clean, typed parser for raw strings and files (#828)

This is our shiny, new, 200-line, doctested and typed parser that replaces `kaptan`.

### Packaging

- Drop kaptan dependency (#828)

## tmuxp 1.15.3 (2022-10-01)

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def socket_name(request) -> str:
def add_doctest_fixtures(
request: pytest.FixtureRequest,
doctest_namespace: t.Dict[str, t.Any],
tmp_path: pathlib.Path,
) -> None:
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
doctest_namespace["server"] = request.getfixturevalue("server")
Expand All @@ -71,3 +72,4 @@ def add_doctest_fixtures(
doctest_namespace["window"] = session.attached_window
doctest_namespace["pane"] = session.attached_pane
doctest_namespace["test_utils"] = test_utils
doctest_namespace["tmp_path"] = tmp_path
1 change: 0 additions & 1 deletion docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ from JSON and YAML.
`$ tmuxp -f<config-file>` for config file.

[attempt at 1.7 test]: https://travis-ci.org/tmux-python/tmuxp/jobs/12348263
[kaptan]: https://github.com/emre/kaptan
[mit-licensed]: http://opensource.org/licenses/MIT
[tmuxinator]: https://github.com/aziz/tmuxinator
[teamocil]: https://github.com/remiprev/teamocil
Expand Down
6 changes: 6 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ If you need an internal API stabilized please [file an issue](https://github.com
.. automethod:: tmuxp.config.import_tmuxinator
```

## Configuration reader

```{eval-rst}
.. automodule:: tmuxp.config_reader
```

## Workspace Builder

```{eval-rst}
Expand Down
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@

# sphinx.ext.autodoc
toc_object_entries_show_parents = "hide"
autodoc_default_options = {
"undoc-members": True,
"members": True,
"private-members": True,
"show-inheritance": True,
"member-order": "bysource",
}

# sphinxext.opengraph
ogp_site_url = about["__docs__"]
Expand Down
4 changes: 2 additions & 2 deletions docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ tmux(1)
The tmux binary. Used internally to distinguish tmuxp is only a
layer on top of tmux.

kaptan
configuration management library, see [kaptan on github](https://github.com/emre/kaptan).
ConfigReader
configuration management class.

Server
Tmux runs in the background of your system as a process.
Expand Down
96 changes: 49 additions & 47 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ tmuxp = 'tmuxp:cli.cli'
[tool.poetry.dependencies]
python = "^3.7"
click = "~8"
kaptan = ">=0.5.10"
libtmux = "~0.15.7"
colorama = ">=0.3.9"

Expand Down Expand Up @@ -90,6 +89,7 @@ flake8-comprehensions = "*"
mypy = "*"
types-colorama = "*"
types-docutils = "*"
types-PyYAML = "*"

[tool.poetry.extras]
docs = [
Expand Down Expand Up @@ -118,6 +118,7 @@ lint = [
"mypy",
"types-colorama",
"types-docutils",
"types-PyYAML",
]

[tool.coverage.run]
Expand All @@ -142,9 +143,13 @@ exclude_lines = [
"def parse_args",
]

[tool.mypy]
files = [
"src/tmuxp/config_reader.py",
]

[[tool.mypy.overrides]]
module = [
"kaptan",
"aafigure",
"libtmux.*",
"IPython.*",
Expand Down
18 changes: 9 additions & 9 deletions src/tmuxp/cli/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import pathlib

import click
import kaptan

from tmuxp.config_reader import ConfigReader

from .utils import ConfigPath

Expand All @@ -25,20 +27,18 @@ def command_convert(confirmed, config):
f"Unknown filetype: {ext} (valid: [.json, .yaml, .yml])"
)

configparser = kaptan.Kaptan()
configparser.import_config(config)
newfile = config.replace(ext, ".%s" % to_filetype)
configparser = ConfigReader.from_file(pathlib.Path(config))
newfile = config.replace(ext, f".{to_filetype}")

export_kwargs = {"default_flow_style": False} if to_filetype == "yaml" else {}
newconfig = configparser.export(to_filetype, indent=2, **export_kwargs)
new_config = configparser.dump(format=to_filetype)

if not confirmed:
if click.confirm(f"convert to <{config}> to {to_filetype}?"):
if click.confirm("Save config to %s?" % newfile):
if click.confirm(f"Save config to {newfile}?"):
confirmed = True

if confirmed:
buf = open(newfile, "w")
buf.write(newconfig)
buf.write(new_config)
buf.close()
print("New config saved to <%s>." % newfile)
print(f"New config saved to <{newfile}>.")
11 changes: 5 additions & 6 deletions src/tmuxp/cli/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys

import click
import kaptan

from libtmux.server import Server
from tmuxp.config_reader import ConfigReader
from tmuxp.exc import TmuxpException

from .. import config, util
Expand Down Expand Up @@ -71,9 +71,8 @@ def command_freeze(
return

sconf = freeze(session)
configparser = kaptan.Kaptan()
newconfig = config.inline(sconf)
configparser.import_config(newconfig)
configparser = ConfigReader(newconfig)

if not quiet:
print(
Expand Down Expand Up @@ -126,11 +125,11 @@ def command_freeze(
)

if config_format == "yaml":
newconfig = configparser.export(
"yaml", indent=2, default_flow_style=False, safe=True
newconfig = configparser.dump(
format="yaml", indent=2, default_flow_style=False, safe=True
)
elif config_format == "json":
newconfig = configparser.export("json", indent=2)
newconfig = configparser.dump(format="json", indent=2)

if yes or click.confirm("Save to %s?" % dest):
destdir = os.path.dirname(dest)
Expand Down
Loading