Skip to content

Commit

Permalink
Merge pull request #107 from pappasam/migrate-to-argparse
Browse files Browse the repository at this point in the history
Migrate to argparse
  • Loading branch information
pappasam authored Mar 26, 2021
2 parents 4e8f82b + 99fe1d1 commit 327daf9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 89 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.28.8

### Changed

- Updated cli to use `argparse` instead of `click`.
- Required pygls version updated to `0.10.2` to accommodate recent bugfixes / prevent users from filing issues based on old version.

### Removed

- Removed `click` from dependencies.

## 0.28.7

### Changed
Expand Down
52 changes: 43 additions & 9 deletions jedi_language_server/cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
"""Jedi Language Server command line interface."""

import click

import argparse
import sys

from .server import SERVER


@click.command()
@click.version_option()
def cli() -> None:
"""Jedi language server.
def get_version() -> str:
"""Get the program version."""
# pylint: disable=import-outside-toplevel
try:
# Type checker for Python < 3.8 fails.
# Since this ony happens here, we just ignore.
from importlib.metadata import version # type: ignore
except ImportError:
try:
# Below ignored both because this a redefinition from above, and
# because importlib_metadata isn't known by mypy. Ignored because
# this is intentional.
from importlib_metadata import version # type: ignore
except ImportError:
print(
"Error: unable to get version. "
"If using Python < 3.8, you must install "
"`importlib_metadata` to get the version.",
file=sys.stderr,
)
sys.exit(1)
return version("jedi-language-server")

Examples:

Run from stdio : jedi-language-server
"""
SERVER.start_io() # type: ignore
def cli() -> None:
"""Jedi language server cli entrypoint."""
parser = argparse.ArgumentParser(
prog="jedi-language-server",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="Jedi language server: an LSP wrapper for jedi.",
epilog="""\
Examples:
Run from stdio: jedi-language-server
""",
)
parser.add_argument("--version", action="store_true")
args = parser.parse_args()
if args.version:
print(get_version())
sys.exit(0)
SERVER.start_io()
108 changes: 32 additions & 76 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ line_length = 79

[tool.poetry]
name = "jedi-language-server"
version = "0.28.7"
version = "0.28.8"
description = "A language server for Jedi!"
authors = ["Sam Roeca <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -41,9 +41,8 @@ license = "MIT"

[tool.poetry.dependencies]
python = "^3.6.1"
click = ">=7.0"
jedi = "0.18.0"
pygls = "^0.10.0"
pygls = "^0.10.2"
pydantic = "^1.7"
docstring-to-markdown = "0.*"

Expand Down
7 changes: 6 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Test the CLI."""

from jedi_language_server.cli import cli
from jedi_language_server.cli import cli, get_version


def test_get_version() -> None:
"""Test that the get_version function returns a string."""
assert isinstance(get_version(), str)


def test_cli() -> None:
Expand Down

0 comments on commit 327daf9

Please sign in to comment.