ideasman42 / nerd-dictation

Simple, hackable offline speech to text - using the VOSK-API.
GNU General Public License v3.0
1.27k stars 106 forks source link

Packaging #60

Closed papoteur-mga closed 2 years ago

papoteur-mga commented 2 years ago

Hello, I have the idea to package nerd-dictation for Pypi.org. I tested adding a setup.py and setup.cfg file. Thus I tried to consider nerd-dictation file as a module, adding a console script entry. At this step, I'm facing a problem that the name nerd-dictation is not allowed because of the dash, the name generates syntax error with `import nerd-dictation". Can it be considered to change the name in nerd_dictation instead of nerd-dictation? I didn't yet explored another way to not use module/console script, but to install directly the nerd-dictation script. What do you think about that? The background idea is to distribute it with easy installation with pip install, and also that elograf can require it as dependency.

ideasman42 commented 2 years ago

Hi, thanks for looking into this. Could you submit a PR that adds the setup script? (including the rename), I'd be surprised if there isn't some way to workaround the dash in the name.

papoteur-mga commented 2 years ago

Hi, You're right, there is the scripts directive, which isn't well documented, I find. This is my proposition for setup.cfg

[metadata]
name = nerd-dictation
version = 0.0.0
author = Campbell Barton
author_email =
description = Offline Speech to Text for Desktop
long_description = file: readme.rst
long_description_content_type = text/x-rst
url = https://github.com/ideasman42/nerd-dictation
classifiers =
        Programming Language :: Python :: 3
        License :: OSI Approved :: GPL v3.0
        Operating System :: POSIX :: Linux
        Topic :: Office :: Productivity
        Topic :: Accessibility :: Voice

[options]
scripts= 
    nerd-dictation
install_requires=
    vosk

python_requires = >=3

This needs the setup.py

#!/usr/bin/env python3
import setuptools

if __name__ == "__main__":
    setuptools.setup()

Tests could be also added.

ideasman42 commented 2 years ago

Could you check: https://github.com/ideasman42/nerd-dictation/commit/f05a70cb6ae044570800308cb5442aed3b0f787b

This can be testing using: pip install package/python

papoteur-mga commented 2 years ago

Hello, Thanks, this works for the installation. I get the "binary" in ~/.local/bin/nerd-dictation

ideasman42 commented 2 years ago

Committed 0c26652023e10d2779e0c03eee5627fc95698c74, closing.

papoteur-mga commented 2 years ago

Hi, I didn't try for now. For building a pypi pacakge, the command fails.

python3 -m build package/python   
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for sdist...
running egg_info
writing nerd_dictation.egg-info/PKG-INFO
writing dependency_links to nerd_dictation.egg-info/dependency_links.txt
writing requirements to nerd_dictation.egg-info/requires.txt
writing top-level names to nerd_dictation.egg-info/top_level.txt
package init file 'build_bvv3rhi1/__init__.py' not found (or not a regular file)
reading manifest file 'nerd_dictation.egg-info/SOURCES.txt'
writing manifest file 'nerd_dictation.egg-info/SOURCES.txt'
* Building sdist...
running sdist
running egg_info
writing nerd_dictation.egg-info/PKG-INFO
writing dependency_links to nerd_dictation.egg-info/dependency_links.txt
writing requirements to nerd_dictation.egg-info/requires.txt
writing top-level names to nerd_dictation.egg-info/top_level.txt
package init file 'build_xiawnuij/__init__.py' not found (or not a regular file)
reading manifest file 'nerd_dictation.egg-info/SOURCES.txt'
writing manifest file 'nerd_dictation.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md

running check
creating nerd-dictation-0.0.0
creating nerd-dictation-0.0.0/nerd_dictation.egg-info
copying files to nerd-dictation-0.0.0...
copying setup.py -> nerd-dictation-0.0.0
copying nerd_dictation.egg-info/PKG-INFO -> nerd-dictation-0.0.0/nerd_dictation.egg-info
copying nerd_dictation.egg-info/SOURCES.txt -> nerd-dictation-0.0.0/nerd_dictation.egg-info
copying nerd_dictation.egg-info/dependency_links.txt -> nerd-dictation-0.0.0/nerd_dictation.egg-info
copying nerd_dictation.egg-info/requires.txt -> nerd-dictation-0.0.0/nerd_dictation.egg-info
copying nerd_dictation.egg-info/top_level.txt -> nerd-dictation-0.0.0/nerd_dictation.egg-info
Writing nerd-dictation-0.0.0/setup.cfg
Creating tar archive
removing 'nerd-dictation-0.0.0' (and everything under it)
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for wheel...
Traceback (most recent call last):
  File "/home/yves/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 363, in <module>
    main()
  File "/home/yves/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 345, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/home/yves/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
    return hook(config_settings)
  File "/tmp/build-env-8eulfo8r/lib64/python3.8/site-packages/setuptools/build_meta.py", line 177, in get_requires_for_build_wheel
    return self._get_build_requires(
  File "/tmp/build-env-8eulfo8r/lib64/python3.8/site-packages/setuptools/build_meta.py", line 159, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-8eulfo8r/lib64/python3.8/site-packages/setuptools/build_meta.py", line 281, in run_setup
    super(_BuildMetaLegacyBackend,
  File "/tmp/build-env-8eulfo8r/lib64/python3.8/site-packages/setuptools/build_meta.py", line 174, in run_setup
    exec(compile(code, __file__, 'exec'), locals())
  File "setup.py", line 55, in <module>
    main(temp_dir)
  File "setup.py", line 28, in main
    shutil.copy2(src, dst)
  File "/usr/lib64/python3.8/shutil.py", line 435, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib64/python3.8/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/nerd-dictation'

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel

This is the same with the no isolation option.

ideasman42 commented 2 years ago

I'm getting the error too, must have been caused by recent changes. They're now resolved.

papoteur-mga commented 2 years ago

Fine. I prepared the package for test in Testpypi. https://test.pypi.org/project/nerd-dictation/0.0.0/ It still need some adjustments to readme.rst Are you OK for publishing it in pypi.org