diff --git a/package/python/readme.rst b/package/python/readme.rst deleted file mode 100644 index 6037536..0000000 --- a/package/python/readme.rst +++ /dev/null @@ -1,11 +0,0 @@ -################## -Packaging with PIP -################## - -To install nerd-dictaiton as a package from pip, run: - -.. code-block:: sh - - pip install package/python - -On a typical Linux system this will install nerd-dictation to ``~/.local/bin``. diff --git a/package/python/setup.py b/package/python/setup.py deleted file mode 100644 index 697d2b6..0000000 --- a/package/python/setup.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-or-later - -import os -import setuptools -import shutil -import tempfile - - -def read_file_as_utf8(filepath): - with open(filepath, encoding="utf-8") as fh: - return fh.read() - - -def main(base_dir): - root_dir = os.path.normpath(os.path.join(base_dir, "..", "..")) - - if not os.path.exists(os.path.join(root_dir, "nerd-dictation")): - root_dir = base_dir - CWD = os.getcwd() - - NERD_DICTATION_DST = os.path.join(base_dir, "nerd-dictation") - README_DST = os.path.join(base_dir, "doc", "readme.rst") - os.makedirs(os.path.join(base_dir, "doc"), exist_ok=True) - - # Path pairs to copy. - COPY_PATH_PAIRS = ( - # As this is a single, self contained script, this is all that's needed. - (os.path.join(root_dir, "nerd-dictation"), NERD_DICTATION_DST), - (os.path.join(root_dir, "readme.rst"), README_DST), - ) - - if root_dir != base_dir: - for src, dst in COPY_PATH_PAIRS: - shutil.copy2(src, dst) - - # `setuptools` expects relative paths. - NERD_DICTATION_DST = os.path.relpath(NERD_DICTATION_DST, CWD) - README_DST = os.path.relpath(README_DST, CWD) - - setuptools.setup( - name="nerd-dictation", - version="0.0.0", - maintainer="Campbell Barton", - maintainer_email="ideasman42@gmail.com", - description="Offline Speech to Text for Desktop", - long_description=read_file_as_utf8(README_DST), - long_description_content_type="text/x-rst", - url="https://github.com/ideasman42/nerd-dictation", - classifiers=[ - "Programming Language :: Python :: 3", - "Topic :: Office :: Productivity", - "Topic :: Accessibility :: Voice", - "Operating System :: POSIX :: Linux", - "License :: OSI Approved :: GPL v3.0", - ], - scripts=[NERD_DICTATION_DST], - data_files=[("nerd-dictation", [NERD_DICTATION_DST, README_DST])], - packages=[""], - package_data={"": [NERD_DICTATION_DST, README_DST]}, - include_package_data=True, - install_requires=["vosk"], - python_requires=">=3.8", - ) - - -if __name__ == "__main__": - main(os.path.abspath(os.path.dirname(__file__))) diff --git a/package/readme.rst b/package/readme.rst index bf74ee7..c7a1c39 100644 --- a/package/readme.rst +++ b/package/readme.rst @@ -5,5 +5,10 @@ Packaging While nerd-dictation is intended to run without the need for a build/packaging step, some users may find it convenient. -- `Python's pip (setup-tools) `_. +- Python's pip (setup-tools) + +From the parent of the project directory, run: + + pip3 install ./nerd-dictation + - `GNU Guix `_. diff --git a/pyproject.toml b/pyproject.toml index c228223..950aff6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,6 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + [tool.black] line-length = 119 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0926a52 --- /dev/null +++ b/setup.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +import setuptools +import os +import re +import glob +import shutil + +def read_file_as_utf8(filepath): + with open(filepath, encoding="utf-8") as fh: + return fh.read() + + +def main(base_dir): + + doc_dir="share/doc/nerd-dictation" + fn="nerd-dictation.py" + doc_list=[(doc_dir,list(filter(re.compile(r'.*rst').match, os.listdir("./"))))] + for ex in glob.glob("examples/*/"): + doc_list.append((os.path.join(doc_dir,ex), [os.path.join(ex,fn)])) + + if os.geteuid()!=0 and os.name=="posix": + config_dir=os.path.join(os.path.expanduser("~"),".config/nerd-dictation") + if not os.path.isdir(config_dir): + os.makedirs(config_dir) + shutil.copy("examples/default/nerd-dictation.py",config_dir) + # For cross-platform assistance, see: (pypi: appdirs) (github: platformdirs) + # For root install, first support /etc/nerd-dictation + + setuptools.setup( + name="nerd-dictation", + version="0.0.0", + maintainer="Campbell Barton", + maintainer_email="ideasman42@gmail.com", + description="Offline Speech to Text for Desktop", + long_description=read_file_as_utf8("readme.rst"), + long_description_content_type="text/x-rst", + url="https://github.com/ideasman42/nerd-dictation", + classifiers=[ + "Programming Language :: Python :: 3", + "Topic :: Office :: Productivity", + "Topic :: Accessibility :: Voice", + "Operating System :: POSIX :: Linux", + "License :: OSI Approved :: GPL v3.0", + ], + scripts=["nerd-dictation"], + data_files=doc_list, + packages=[""], + package_data={"nerd-dictation": [""]}, + install_requires=["vosk"], + python_requires=">=3.8", + ) + + +if __name__ == "__main__": + main(os.path.abspath(os.path.dirname(__file__)))