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
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_version.py
### https://raw.github.com/github/gitignore/85bf08b19a77c62d7b6286c2db8811f2ff373b0f/Python.gitignore

# Byte-compiled / optimized / DLL files
Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ configuration file example::
style = "json"
template_path = "/path/to/template"

Completion
==========

This program provides shell completions. It should be out of box if you install
it from a wheel file.

LICENSE
=======

Expand Down
6 changes: 5 additions & 1 deletion doq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
from doq.parser import parse # noqa F401
from doq.template import Template # noqa F401

__version__ = '0.9.1'
# avoid bug when `pyproject-build`
try:
from ._version import __version__
except ImportError:
__version__ = ""
20 changes: 20 additions & 0 deletions doq/_shtab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from argparse import Action

FILE = DIR = {}


class PrintCompletionAction(Action):
def __call__(self, parser, namespace, values, option_string=None):
print('Please install shtab firstly!') # noqa: T001 print found
parser.exit(0)


def add_argument_to(parser, *args, **kwargs):
Action.complete = None # type: ignore
parser.add_argument(
'--print-completion',
choices=['bash', 'zsh', 'tcsh'],
action=PrintCompletionAction,
help='print shell completion script',
)
return parser
13 changes: 9 additions & 4 deletions doq/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,18 @@ def parse_options():
description='Docstring generator.',
add_help=True,
)
try:
import shtab
except ImportError:
from . import _shtab as shtab
shtab.add_argument_to(parser)
parser.add_argument(
'-f',
'--file',
type=argparse.FileType('r'),
default='-',
help='File or STDIN',
)
).complete = shtab.FILE
parser.add_argument(
'--start',
type=int,
Expand All @@ -275,7 +280,7 @@ def parse_options():
type=str,
default=None,
help='Path to template directory',
)
).complete = shtab.DIR
parser.add_argument(
'-s',
'--style',
Expand Down Expand Up @@ -312,7 +317,7 @@ def parse_options():
'--directory',
default='',
help='Path to directory',
)
).complete = shtab.DIR
parser.add_argument(
'-w',
'--write',
Expand All @@ -331,7 +336,7 @@ def parse_options():
'--config',
default=None,
help='Path to a setup.cfg or pyproject.toml',
)
).complete = shtab.FILE
parser.add_argument(
'--ignore_exception',
action='store_true',
Expand Down
49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[build-system]
requires = ["setuptools_scm", "setuptools-generate == 0.0.6", "parso"]
build-backend = "setuptools.build_meta"

# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
[project]
name = "doq"
description = "Docstring generator"
readme = "README.rst"
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Documentation",
"Topic :: Software Development :: Documentation",
]
dependencies = ["parso", "jinja2", "toml"]
dynamic = ["version"]

[project.optional-dependencies]
completion = ["shtab"]
test = ["parameterized"]

[[project.authors]]
name = "Shinya Ohyanagi"
email = "[email protected]"

[project.license]
text = "BSD"

[project.urls]
Homepage = "http://github.com/heavenshell/py-doq"

[project.scripts]
doq = "doq.cli:main"

[tool.setuptools.data-files]
"share/man/man1" = ["sdist/doq.1"]
"share/bash-completion/completions" = ["sdist/doq"]
"share/zsh/site-functions" = ["sdist/_doq"]

[tool.setuptools.packages.find]
include = ["doq"]

[tool.setuptools_scm]
write_to = "doq/_version.py"
57 changes: 4 additions & 53 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
import os
# https://github.com/heavenshell/py-doq/pull/125
# make CI/CD happy
from setuptools import setup

from setuptools import (
find_packages,
setup,
)

version = ''
with open('doq/__init__.py') as f:
for line in f.readlines():
if line.startswith('__version__'):
version = line.split('=')[1].strip().replace("'", '')

rst_path = os.path.join(os.path.dirname(__file__), 'README.rst')
description = ''
with open(rst_path) as f:
description = f.read()

setup(
name='doq',
version=version,
author='Shinya Ohyanagi',
author_email='[email protected]',
url='http://github.com/heavenshell/py-doq',
description='Docstring generator',
long_description=description,
license='BSD',
platforms='any',
packages=find_packages(exclude=['tests']),
package_dir={'': '.'},
include_package_data=True,
package_data={'doq': [
'templates/google/*.txt',
'templates/numpy/*.txt',
'templates/sphinx/*.txt',
]},
install_requires=['parso', 'jinja2', 'toml'],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Documentation',
'Topic :: Software Development :: Documentation',
],
entry_points="""
[console_scripts]
doq = doq.cli:main
""",
tests_require=['parameterized'],
test_suite='tests',
)
setup()