Skip to content

Commit

Permalink
1. Use Makefile and Python3 virtual env to install package.
Browse files Browse the repository at this point in the history
2. Format python files in this plugion.
  • Loading branch information
Clcanny committed Jun 25, 2020
1 parent 2cc7e57 commit efce995
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
thirdparty/**
config/**
build/**
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Refer to davidhalter/jedi-vim.
BUILD_VIRTUAL_ENV:=build/venv

$(dir $(BUILD_VIRTUAL_ENV)):
mkdir -p $@

$(BUILD_VIRTUAL_ENV): | $(dir $(BUILD_VIRTUAL_ENV))
python3 -m venv $@
# $|/bin/python -m pip upgrade

$(BUILD_VIRTUAL_ENV)/bin/isort: | $(BUILD_VIRTUAL_ENV)
$|/bin/python -m pip install -q isort==4.3.21

$(BUILD_VIRTUAL_ENV)/bin/yapf: | $(BUILD_VIRTUAL_ENV)
$|/bin/python -m pip install -q yapf==0.30.0

isort: $(BUILD_VIRTUAL_ENV)/bin/isort
$(BUILD_VIRTUAL_ENV)/bin/isort --help

yapf: $(BUILD_VIRTUAL_ENV)/bin/yapf
$(BUILD_VIRTUAL_ENV)/bin/yapf --help

check: isort yapf

clean:
rm -rf build

.PHONY: check clean isort yapf
1 change: 1 addition & 0 deletions python/abstract_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import subprocess
import tempfile

import vim


Expand Down
5 changes: 3 additions & 2 deletions python/format_json.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
import collections
import json
import sys

if __name__ == "__main__":
if len(sys.argv) != 3:
raise RuntimeError("Please call format_json.py with arugments: indent and filename.")
raise RuntimeError(
"Please call format_json.py with arugments: indent and filename.")
indent = int(sys.argv[1])
filename = sys.argv[2]

Expand Down
1 change: 0 additions & 1 deletion python/json_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import vim

from abstract_formatter import AbstractFormatter


Expand Down
1 change: 0 additions & 1 deletion python/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import vim

from json_formatter import JsonFormatter
from python_formatter import PythonFormatter

Expand Down
6 changes: 3 additions & 3 deletions python/python_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import vim

from abstract_formatter import AbstractFormatter


Expand All @@ -17,6 +16,7 @@ def _getGuideFilename(self):

def _getFormatCommand(self, formattedFilename, guideFilename):
guideFilename = vim.eval("g:VimFormatterPythonStyle")
cmd = '{} --style="{}" "{}"'.format(self._yapf, guideFilename,
formattedFilename)
isort = "{}/build/venv/bin/isort".format(self._getRootDir())
cmd = '{} --stdout "{}" | {} --style="{}"'.format(
isort, formattedFilename, self._yapf, guideFilename)
return cmd

0 comments on commit efce995

Please sign in to comment.