-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partial transfer of xoipy functionality to this new repository
- Loading branch information
Peter Gaultney
committed
May 18, 2020
0 parents
commit d6fc235
Showing
23 changed files
with
1,037 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
ignore = | ||
E203, | ||
E101, | ||
E111, | ||
E114, | ||
E115, | ||
E116, | ||
E117, | ||
E121, | ||
E122, | ||
E123, | ||
E124, | ||
E125, | ||
E126, | ||
E127, | ||
E128, | ||
E129, | ||
E131, | ||
E133, | ||
E2, | ||
E3, | ||
E5, | ||
E701, | ||
E702, | ||
E703, | ||
E704, | ||
W1, | ||
W2, | ||
W3, | ||
W503, | ||
W504, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
Pipfile.lock | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
.DS_Store | ||
|
||
# IDE artifacts | ||
**/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
fail_fast: true | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.2.3 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: flake8 | ||
- id: check-case-conflict | ||
- id: check-json | ||
- id: mixed-line-ending | ||
- id: check-merge-conflict | ||
|
||
- repo: https://github.com/prettier/prettier | ||
rev: 1.18.2 | ||
hooks: | ||
- id: prettier | ||
exclude: .*\.html | ||
|
||
- repo: https://github.com/ambv/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.7 | ||
args: | ||
- --line-length=100 | ||
|
||
- repo: local | ||
hooks: | ||
- id: mypy-pipenv | ||
name: mypy-pipenv | ||
entry: scripts/pipenv_runner.py mypy | ||
language: system | ||
types: [python] | ||
args: | ||
- --show-traceback | ||
- --ignore-missing-imports | ||
- --check-untyped-defs | ||
- id: pylint-pipenv | ||
name: pylint-pipenv | ||
entry: scripts/precommit_pylint.py | ||
language: system | ||
types: [python] | ||
args: | ||
- --rcfile=.pylintrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[BASIC] | ||
max-line-length=120 | ||
good-names=logger,_,i,j,k,__logger | ||
|
||
# Regular expression matching correct method names. Overrides method-naming style | ||
method-rgx=(([a-z_][a-z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$ | ||
|
||
[MESSAGES CONTROL] | ||
disable= | ||
invalid-name, | ||
too-few-public-methods, | ||
bad-continuation, | ||
logging-fstring-interpolation, | ||
missing-docstring, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 XOi Technologies | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[[source]] | ||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
|
||
[packages] | ||
boto3 = ">=1.9" | ||
typing-extensions = "*" | ||
|
||
[dev-packages] | ||
pytest = "~=5.0" | ||
mypy = ">=0.770" | ||
pylint = "*" | ||
|
||
[requires] | ||
python_version = "3.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[mypy] | ||
python_version = 3.7 | ||
show_error_context = True | ||
show_column_numbers = True | ||
|
||
[mypy-conftest] | ||
ignore_errors = True | ||
[mypy-boto3] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
"""A pipenv runner for mypy""" | ||
|
||
import typing as ty | ||
import subprocess | ||
import os | ||
import sys | ||
|
||
from precommit_utils import interpret_precommit_args | ||
from pipenv_utils import find_pipenv_dir | ||
|
||
|
||
def run_in_pipenv(cmd: str, fileorpath: str, cli_args: ty.Iterable = ()): | ||
"""Looks for the closest Pipfile/pipenv and runs the command within that venv""" | ||
print(f"checking {fileorpath} with {cmd}") | ||
fileorpath = os.path.abspath(fileorpath) | ||
pipenv_dir = find_pipenv_dir(fileorpath) | ||
|
||
if pipenv_dir: | ||
fileorpath = fileorpath[len(pipenv_dir) + 1 :] if pipenv_dir != fileorpath else pipenv_dir | ||
full_command = ["pipenv", "run", cmd, fileorpath, *cli_args] | ||
return subprocess.run( | ||
full_command, cwd=pipenv_dir, env={**os.environ, **dict(PYTHONPATH=pipenv_dir)} | ||
) | ||
|
||
return subprocess.run([cmd, fileorpath, *cli_args]) | ||
|
||
|
||
if __name__ == "__main__": | ||
path_args, cli_args = interpret_precommit_args() | ||
|
||
cmd = cli_args[0] | ||
cli_args = cli_args[1:] | ||
|
||
for path_arg in path_args: | ||
cp = run_in_pipenv(cmd, path_arg, cli_args) | ||
if cp.returncode != 0: | ||
print(f"Failed {cmd} over {path_arg} with {cp.returncode}") | ||
sys.exit(cp.returncode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
import os | ||
import subprocess | ||
import glob | ||
|
||
|
||
def find_pipenv_dir(fileorpath: str) -> str: | ||
fileorpath = os.path.abspath(fileorpath) | ||
pipenv_dir = os.path.dirname(fileorpath) if not os.path.isdir(fileorpath) else fileorpath | ||
while len(pipenv_dir) > 1: | ||
if os.path.exists(os.path.join(pipenv_dir, "Pipfile")): | ||
return pipenv_dir | ||
pipenv_dir = os.path.dirname(pipenv_dir) | ||
return "" | ||
|
||
|
||
def get_pipenv_venv_site_packages(pipenv_dir: str) -> str: | ||
venv_output = subprocess.check_output(["pipenv", "--venv"], text=True, cwd=pipenv_dir).rstrip( | ||
"\n" | ||
) | ||
glob_out = glob.glob(venv_output + "/lib/python*") | ||
return glob_out[0] + "/site-packages/" | ||
|
||
|
||
def get_pythonpath_for_pipfile_dir_and_venv(filepath: str) -> str: | ||
pipenv_dir = find_pipenv_dir(filepath) | ||
if pipenv_dir: | ||
return ":".join([pipenv_dir, get_pipenv_venv_site_packages(pipenv_dir)]) | ||
return "" | ||
|
||
|
||
def main(): | ||
"""Prints a PYTHONPATH including the Pipfile's own directory, if one is found""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("path") | ||
args = parser.parse_args() | ||
|
||
pythonpath = get_pythonpath_for_pipfile_dir_and_venv(args.path) | ||
if pythonpath: | ||
print(pythonpath) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
import subprocess | ||
import os | ||
|
||
from precommit_utils import interpret_precommit_args | ||
from pipenv_utils import get_pythonpath_for_pipfile_dir_and_venv | ||
|
||
|
||
if __name__ == "__main__": | ||
path_args, cli_args = interpret_precommit_args() | ||
|
||
for path in path_args: | ||
pythonpath = get_pythonpath_for_pipfile_dir_and_venv(path) | ||
print(f"Linting {path} with PYTHONPATH <{pythonpath}>") | ||
subprocess.check_call( | ||
["scripts/pylint_pipenv_score_limit.py", path, *cli_args, "--assume-pythonpath"], | ||
env={**os.environ, **dict(PYTHONPATH=pythonpath)}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
import os | ||
|
||
|
||
def interpret_precommit_args(): | ||
"""Precommit passes its arguments strangely and this lets us figure out which ones are which type""" | ||
path_args = list() | ||
cli_args = list() | ||
for arg in sys.argv[1:]: | ||
if os.path.exists(arg): | ||
path_args.append(arg) | ||
else: | ||
cli_args.append(arg) | ||
|
||
if not path_args: | ||
raise Exception( | ||
"Everything passed was considered to be a CLI argument, " | ||
"so there was nothing to check. " + str(cli_args) | ||
) | ||
|
||
return path_args, cli_args |
Oops, something went wrong.