%define scl rh-python36 %{?scl:%scl_package %{name}} %{!?scl:%global pkg_name %{name}} %define name python-editor %define version 1.0.4 %define unmangled_version 1.0.4 %define unmangled_version 1.0.4 %define release 1 Summary: Programmatically open an editor, capture the result. %{?scl:Requires: %{scl}-runtime} %{?scl:BuildRequires: %{scl}-runtime} Name: %{?scl_prefix}python-editor Version: %{version} Release: %{release} Source0: python-editor-%{unmangled_version}.tar.gz License: Apache Group: Development/Libraries BuildRoot: %{_tmppath}/python-editor-%{version}-%{release}-buildroot Prefix: %{_prefix} BuildArch: noarch Vendor: Peter Ruibal Packager: Martin Juhl Url: https://github.com/fmoo/python-editor %description `python-editor` is a library that provides the `editor` module for programmatically interfacing with your system's $EDITOR. Examples -------- ```python import editor commit_msg = editor.edit(contents=b"# Enter commit message here") ``` Opens an editor, prefilled with the contents, `# Enter commit message here`. When the editor is closed, returns the contents (bytes) in variable `commit_msg`. Note that the argument to `contents` needs to be a bytes object on Python 3. ```python editor.edit(file="README.txt") ``` Opens README.txt in an editor. Changes are saved in place. If there is a `contents` argument then the file contents will be overwritten. ```python editor.edit(..., use_tty=True) ``` Opens the editor in a TTY. This is usually done in programs which output is piped to other programs. In this case the TTY is used as the editor's stdout, allowing interactive usage. How it Works ------------ `editor` first looks for the ${EDITOR} environment variable. If set, it uses the value as-is, without fallbacks. If no $EDITOR is set, editor will search through a list of known editors, and use the first one that exists on the system. For example, on Linux, `editor` will look for the following editors in order: * vim * emacs * nano When calling `editor.edit`, an editor will be opened in a subprocess, inheriting the parent process's stdin, stdout. %prep %{?scl:scl enable %{scl} - << \EOF} set -ex %setup -n python-editor-%{unmangled_version} -n python-editor-%{unmangled_version} %{?scl:EOF} %build %{?scl:scl enable %{scl} - << \EOF} set -ex python3 setup.py build %{?scl:EOF} %install %{?scl:scl enable %{scl} - << \EOF} set -ex python3 setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES %{?scl:EOF} %clean %{?scl:scl enable %{scl} - << \EOF} set -ex rm -rf $RPM_BUILD_ROOT %{?scl:EOF} %files -f INSTALLED_FILES %defattr(-,root,root)