Skip to content

Commit

Permalink
Implement code style enforcement (#12)
Browse files Browse the repository at this point in the history
* Put the flake8 config into a separate file

* Make flake8 better explained

* Configure isort

* Make the source compat w/ wemake-python-styleguide

* Add wemake-python-styleguide badge to README

* Fix linter offences

* Integrate pre-commit tool

* Integrate tox

* Drop-in a yamllint config

* Integrate Travis CI
  • Loading branch information
webknjaz authored and ganeshrn committed Jan 21, 2020
1 parent 5d64d92 commit 8326fe1
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 49 deletions.
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
filename =
# Normal Python files (default):
*.py,
# Cython files:
*.pyx
per-file-ignores =
# Exclude errors that don't make sense for Cython
lib/pylibssh/*.pyx: E225,E227,E999
max-line-length = 160
17 changes: 17 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://github.com/timothycrosley/isort/wiki/isort-Settings
[settings]
# Should be: 80 - 1
line_length = 79
# force_to_top=file1.py,file2.py
# skip=file3.py,file4.py
# known_future_library=future,pies
# known_standard_library=std,std2
# known_third_party=randomthirdparty
# known_first_party=mylib1,mylib2
indent = ' '
# https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output = 5
# length_sort = 1
# forced_separate = django.contrib,django.utils
default_section = FIRSTPARTY
no_lines_before = LOCALFOLDER
70 changes: 70 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
repos:
- repo: git://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort

- repo: git://github.com/asottile/add-trailing-comma
rev: v0.7.1
hooks:
- id: add-trailing-comma

- repo: git://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.6
hooks:
- id: remove-tabs

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
# Side-effects:
- id: trailing-whitespace
- id: check-merge-conflict
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: requirements-txt-fixer

# Non-modifying checks:
- id: name-tests-test
- id: check-added-large-files
- id: check-byte-order-marker
- id: check-case-conflict
# disabled due to pre-commit/pre-commit-hooks#159
#- id: check-docstring-first
- id: check-json
- id: check-symlinks
- id: check-yaml
# args:
# - --unsafe
- id: detect-private-key

# Heavy checks:
- id: check-ast
- id: debug-statements
- id: flake8
additional_dependencies:
- flake8-2020
- flake8-pytest-style
- wemake-python-styleguide

- repo: git://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.0
hooks:
- id: rst-linter
files: >-
^.*\.rst$
- repo: git://github.com/pycqa/pydocstyle.git
rev: 4.0.1
hooks:
- id: pydocstyle

# - repo: local
# hooks:
# - id: pylint
# language: system
# name: PyLint
# files: \.py$
# entry: python -m pylint
# args: []
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: python

jobs:
fast_finish: true
include:
- name: pre-commit.com tool linters
python: 3.8
env:
TOXENV: lint

cache:
pip: true
directories:
- $HOME/.cache/pre-commit
- $HOME/.pre-commit
- $HOME/virtualenv/python$(python -c 'import platform; print(platform.python_version())')
- $HOME/Library/Caches/Homebrew

install:
- python -m pip install tox
- python -m tox --notest # Pre-populate a virtualenv with dependencies

script:
- python -m tox
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indentation:
indent-sequences: false
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Changelog
*********

0.0.1 Unreleased
==============
================

0.0.1.dev0
==========
Expand Down
46 changes: 23 additions & 23 deletions LICENSE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ above, provided that you also meet all of these conditions:
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
its purpose remains meaningful.

(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
Expand Down Expand Up @@ -284,23 +284,23 @@ directing the user to the copy of this License. Also, you must do one
of these things:

* **a)** Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
* **b)** Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.

* **c)** Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
Expand Down Expand Up @@ -335,12 +335,12 @@ the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

* **a)** Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
* **b)** Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.

**8.** You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
Expand Down Expand Up @@ -492,7 +492,7 @@ school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:

Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
library 'Frob' (a library for tweaking knobs) written by James Random Hacker.

<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
.. image:: https://img.shields.io/pypi/pyversions/pylibssh.svg?logo=Python&logoColor=white
:target: https://pypi.org/project/pylibssh

.. image:: https://img.shields.io/badge/style-wemake-000000.svg
:target: https://github.com/wemake-services/wemake-python-styleguide

pylibssh: Python bindings to client functionality of libssh
===========================================================

Expand Down
3 changes: 3 additions & 0 deletions lib/pylibssh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

"""Python bindings for libssh."""
3 changes: 3 additions & 0 deletions lib/pylibssh/includes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

"""Cython interface definitions for libssh."""
1 change: 0 additions & 1 deletion lib/pylibssh/includes/callbacks.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,3 @@ cdef extern from "libssh/callbacks.h" nogil:
ctypedef ssh_channel_callbacks_struct * ssh_channel_callbacks

int ssh_set_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb)

43 changes: 26 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import sys
# -*- coding: utf-8 -*-

"""Dist metadata setup."""

import os
import logging
import sys

from setuptools import setup, find_packages
from setuptools import find_packages, setup
from setuptools.extension import Extension

from Cython.Build import cythonize

LIB_NAME = 'ssh'


sys.path.insert(0, os.path.abspath('lib'))

setup(
name="pylibssh",
version="0.0.1.dev0",
ext_modules=cythonize([Extension("pylibssh.session", ["lib/pylibssh/session.pyx"], libraries=["ssh"]),
Extension("pylibssh.channel", ["lib/pylibssh/channel.pyx"], libraries=["ssh"]),
Extension("pylibssh.sftp", ["lib/pylibssh/sftp.pyx"], libraries=["ssh"]),
Extension("pylibssh.errors", ["lib/pylibssh/errors.pyx"], libraries=["ssh"])]),
name='pylibssh',
version='0.0.1.dev0',
ext_modules=cythonize([
Extension('pylibssh.session', ['lib/pylibssh/session.pyx'], libraries=[LIB_NAME]),
Extension('pylibssh.channel', ['lib/pylibssh/channel.pyx'], libraries=[LIB_NAME]),
Extension('pylibssh.sftp', ['lib/pylibssh/sftp.pyx'], libraries=[LIB_NAME]),
Extension('pylibssh.errors', ['lib/pylibssh/errors.pyx'], libraries=[LIB_NAME]),
]),
package_dir={'': 'lib'},
packages=find_packages('lib'),
description="Python bindings for libssh client",
description='Python bindings for libssh client',
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Cython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Security",
'Development Status :: 2 - Pre-Alpha',
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
'Operating System :: MacOS',
'Operating System :: POSIX :: Linux',
'Programming Language :: Cython',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Security',
],
)
6 changes: 5 additions & 1 deletion test/units/test_channel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

"""Tests suite for channel."""

import unittest


class TestChannel(unittest.TestCase):
pass
"""Tests collection for channel."""
6 changes: 5 additions & 1 deletion test/units/test_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

"""Tests suite for session."""

import unittest


class TestSession(unittest.TestCase):
pass
"""Tests collection for session."""
6 changes: 5 additions & 1 deletion test/units/test_sftp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

"""Tests suite for sftp."""

import unittest


class TestSftp(unittest.TestCase):
pass
"""Tests collection for sftp."""
58 changes: 54 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
[flake8]
filename = *.py, *.pyx
per-file-ignores = lib/pylibssh/*:E225,E227,E999
max-line-length = 160
[tox]
envlist = python
minversion = 3.13.0
requires =
setuptools >= 40.9.0
pip >= 19.0.3
# tox-venv >= 0.4.0
isolated_build = true


[testenv]
isolated_build = true
usedevelop = false
deps =
pytest
commands =
{envpython} -m pytest {posargs:}


[testenv:build-dists]
isolated_build = true
# `usedevelop = true` overrides `skip_install` instruction, it's unwanted
usedevelop = false
# don't install octomachinery itself in this env
skip_install = true
deps =
pep517 >= 0.5.0
setenv =
PYPI_UPLOAD = true
commands =
rm -rfv {toxinidir}/dist/
{envpython} -m pep517.build \
--source \
--binary \
--out-dir {toxinidir}/dist/ \
{toxinidir}
whitelist_externals =
rm


[testenv:lint]
basepython = python3
commands =
{envpython} -m pre_commit run --show-diff-on-failure {posargs:--all-files}

# Print out the advise of how to install pre-commit from this env into Git:
-{envpython} -c \
'cmd = "{envpython} -m pre_commit install"; scr_width = len(cmd) + 10; sep = "=" * scr_width; cmd_str = " $ " + cmd; '\
'print("\n" + sep + "\nTo install pre-commit hooks into the Git repo, run:\n\n" + cmd_str + "\n\n" + sep + "\n")'
deps =
pre-commit
# pylint
isolated_build = true
skip_install = true

0 comments on commit 8326fe1

Please sign in to comment.