Skip to content

completion #125

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 2 commits into from
Jul 30, 2023
Merged

completion #125

merged 2 commits into from
Jul 30, 2023

Conversation

Freed-Wu
Copy link
Contributor

@Freed-Wu Freed-Wu commented Jul 18, 2023

  • Add completion
  • Support PEP621

Demo:

$ pip install build installer
$ git clone --branch=completion https://github.com/Freed-Wu/py-doq
$ cd py-doq
$ pyproject-build
$ python -m installer --prefix=/tmp/test dist/doq-0.9.2.dev1+g74db2e6.d20230718-py2.py3-none-any.whl
$ tree /tmp/test
 /tmp/test
├──  bin
│  └──  doq
├──  lib
│  └──  python3.11
│     └──  site-packages
│        ├──  doq
│        │  ├──  __init__.py
│        │  ├──  __pycache__
│        │  │  └── ...
│        │  ├──  _shtab.py
│        │  ├──  _version.py
│        │  ├── ...
│        │  └──  templates
│        │     └── ...
│        └──  doq-0.9.2.dev1+g74db2e6.d20230718.dist-info
│           ├──  entry_points.txt
│           ├──  LICENSE
│           ├──  METADATA
│           ├──  RECORD
│           ├──  top_level.txt
│           └──  WHEEL
└──  share
   ├──  bash-completion
   │  └──  completions
   │     └──  doq
   ├──  man
   │  └──  man1
   │     └──  doq.1
   └──  zsh
      └──  site-functions
         └──  _doq
# You get your bash/zsh completion scripts and man page.
$ PYTHONPATH=/tmp/test/lib/python3.11/site-packages /tmp/test/bin/doq --help
usage: doq [-h] [-f FILE] [--start START] [--end END] [-t TEMPLATE_PATH]
           [-s STYLE] [--formatter FORMATTER] [--indent INDENT] [--omit OMIT]
           [-r] [-d DIRECTORY] [-w] [-v] [-c CONFIG] [--ignore_exception]
           [--ignore_yield] [--ignore_init]

Docstring generator.

options:
  -h, --help            show this help message and exit
  --print-completion {bash,zsh,tcsh}
                        print shell completion script
...

@heavenshell
Copy link
Owner

@Freed-Wu
Thank you so much!
I will check out locally and give it a try. Please wait a moment 🙏

@heavenshell
Copy link
Owner

@Freed-Wu Could you help me?

$ git clone --branch=completion https://github.com/Freed-Wu/py-doq
$ cd py-doq
$ python3 -m venv .venv
(.venv) $ pip install build installer
...
[notice] A new release of pip available: 22.3.1 -> 23.2
[notice] To update, run: pip install --upgrade pip
(.venv) $ pyproject-build
* Creating venv isolated environment...
* Installing packages in isolated environment... (parso, setuptools-generate == 0.0.6, setuptools_scm)
* Getting build dependencies for sdist...
no [tool.setuptools-generate.write-to] in pyproject.toml, skip writing metainfo!
subcommands:_shtab_doq:['_shtab_doq']
....
Successfully built doq-0.9.2.dev2+gbe7b0eb.tar.gz and doq-0.9.2.dev2+gbe7b0eb-py2.py3-none-any.whl
(.venv) $ python -m installer --prefix=/opt/tmp/test dist/doq-0.9.2.dev2+gbe7b0eb-py2.py3-none-any.whl 
$ tree /opt/tmp/test 
/opt/tmp/test
├── bin
│   └── doq
├── lib
│   └── python3.11
│       └── site-packages
│           ├── doq
│           │   ├── __init__.py
│           │   ├── __pycache__
│           │   │   ├── __init__.cpython-311.opt-1.pyc
│           │   │   ├── __init__.cpython-311.pyc
│           │   │   ├── _shtab.cpython-311.opt-1.pyc
│           │   │   ├── _shtab.cpython-311.pyc
│           │   │   ├── _version.cpython-311.opt-1.pyc
│           │   │   ├── _version.cpython-311.pyc
│           │   │   ├── cli.cpython-311.opt-1.pyc
│           │   │   ├── cli.cpython-311.pyc
│           │   │   ├── config.cpython-311.opt-1.pyc
│           │   │   ├── config.cpython-311.pyc
│           │   │   ├── outputter.cpython-311.opt-1.pyc
│           │   │   ├── outputter.cpython-311.pyc
│           │   │   ├── parser.cpython-311.opt-1.pyc
│           │   │   ├── parser.cpython-311.pyc
│           │   │   ├── template.cpython-311.opt-1.pyc
│           │   │   └── template.cpython-311.pyc
│           │   ├── _shtab.py
│           │   ├── _version.py
│           │   ├── cli.py
│           │   ├── config.py
│           │   ├── outputter.py
│           │   ├── parser.py
│           │   ├── template.py
│           │   └── templates
│           │       ├── google
│           │       │   ├── class.txt
│           │       │   ├── def.txt
│           │       │   └── noarg.txt
│           │       ├── numpy
│           │       │   ├── class.txt
│           │       │   ├── def.txt
│           │       │   └── noarg.txt
│           │       └── sphinx
│           │           ├── class.txt
│           │           ├── def.txt
│           │           └── noarg.txt
│           └── doq-0.9.2.dev2+gbe7b0eb.dist-info
│               ├── LICENSE
│               ├── METADATA
│               ├── RECORD
│               ├── WHEEL
│               ├── entry_points.txt
│               └── top_level.txt
└── share
    ├── bash-completion
    │   └── completions
    │       └── doq
    ├── man
    │   └── man1
    │       └── doq.1
    └── zsh
        └── site-functions
            └── _doq

18 directories, 43 files

(.venv) $ PYTHONPATH=/opt/tmp/test/lib/python3.11/site-packages /opt/tmp/test/bin/doq --help 
Traceback (most recent call last):
  File "/opt/tmp/test/bin/doq", line 5, in <module>
    from doq.cli import main
  File "/opt/tmp/test/lib/python3.11/site-packages/doq/__init__.py", line 6, in <module>
    from doq.parser import parse   # noqa F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/tmp/test/lib/python3.11/site-packages/doq/parser.py", line 3, in <module>
    import parso
ModuleNotFoundError: No module named 'parso'

Maybe we should separate pyproject.toml and shell completion?

@Freed-Wu
Copy link
Contributor Author

It is not a bug. python -m installer just install the package, not the dependencies of it. Before this PR, I have installed parso in my PC, so I don't met this error. If you want to install dependencies with this package, try pip install -e .. I use installer just because it is simple as a demo. Sorry for missing explanation.

@heavenshell
Copy link
Owner

@Freed-Wu Thank you for helping me 🙏

(.venv) $ pip install -e .
Obtaining file:///opt/tmp/py-doq
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting parso
  Using cached parso-0.8.3-py2.py3-none-any.whl (100 kB)
Collecting jinja2
  Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=2.0
  Using cached MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_universal2.whl (17 kB)
Building wheels for collected packages: doq
  Building editable for doq (pyproject.toml) ... done
  Created wheel for doq: filename=doq-0.9.2.dev2+gbe7b0eb-0.editable-py2.py3-none-any.whl size=5547 sha256=66fe1945c2867e5e042a000b3fca8392db381c03d5720bdb41027fd6aac75f04
  Stored in directory: /private/var/folders/sz/33tb0z855bz4q0yls1y8zcxc0000gn/T/pip-ephem-wheel-cache-agakijfn/wheels/36/a2/1e/aa5d007a1de80afa0a15bf3fb5e959b4241ce895e4cfbec732
Successfully built doq
Installing collected packages: toml, parso, MarkupSafe, jinja2, doq
Successfully installed MarkupSafe-2.1.3 doq-0.9.2.dev2+gbe7b0eb jinja2-3.1.2 parso-0.8.3 toml-0.10.2

$ PYTHONPATH=/opt/tmp/test/lib/python3.11/site-packages /opt/tmp/test/bin/doq --help
Traceback (most recent call last):
  File "/opt/tmp/test/lib/python3.11/site-packages/doq/cli.py", line 254, in parse_options
    import shtab
ModuleNotFoundError: No module named 'shtab'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/tmp/test/bin/doq", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/tmp/test/lib/python3.11/site-packages/doq/cli.py", line 366, in main
    args = parse_options()
           ^^^^^^^^^^^^^^^
  File "/opt/tmp/test/lib/python3.11/site-packages/doq/cli.py", line 256, in parse_options
    import _shtab as shtab
ModuleNotFoundError: No module named '_shtab'

pip install -e . does not install shtab

Also I think it's better to add shtab to requirements.txt

BTW CI is failing because setup.py was deleted.
So, what should we do?

  1. Maintain CI(drop old python3.6)
  2. Split this PR to few PRs, e.g. pyroject-nized PR, and shell completion PR

or re-create setup.py like folloings?

from setuptools import setup

setup()

@Freed-Wu
Copy link
Contributor Author

It's my fault, I have fixed, can you try again?

@Freed-Wu
Copy link
Contributor Author

or re-create setup.py like folloings?

I agree.

@Freed-Wu
Copy link
Contributor Author

I usually use pyproject-build -sw to build sdist and wheel and pytest to unit test. So I am not familiar with python setup.py XXX. Now let we use a fake setup.py to make CI/CD happy.

@heavenshell
Copy link
Owner

@Freed-Wu
Thank you so much!!
I'll check after I finish my day job.

I usually use pyproject-build -sw to build sdist and wheel and pytest to unit test. So I am not familiar with python setup.py XXX. Now let we use a fake setup.py to make CI/CD happy.

Right, setup.py is deprecated, so I'll replace to pyproject completely after your PR merged.
(setup pytest etc)

Copy link
Owner

@heavenshell heavenshell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Freed-Wu
Thank you so much! Sorry for late response.

  1. Could you check my review comments?
  2. Could you remove .github/workflows/main.yml's python-version 3.6?
  3. I would be very happy if you could add the completion instructions to the README.rst

Freed-Wu added 2 commits July 20, 2023 18:15
Assume python is installed in /usr/lib/pythonX.Y, generate completions by:

doq --print-completion bash > /usr/share/bash-completion/completions/doq
doq --print-completion zsh > /usr/share/zsh/site-functions/_doq

Create a fake setup.py
@Freed-Wu
Copy link
Contributor Author

Fixed.

Copy link
Owner

@heavenshell heavenshell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Looks Great to me!
スクリーンショット 2023-07-31 0 23 18

@heavenshell heavenshell merged commit 6ed6e44 into heavenshell:master Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants