Skip to content

Commit

Permalink
Modernize project structure.
Browse files Browse the repository at this point in the history
 * Adds pyproject.toml
 * Migrates setup.py to setup.cfg
 * Drops support for EOL Python versions
 * Moves code under `src/suitable`, tests to top-level directory `tests`
 * Revamps tox configuration (wip)
 * Adds basic github actions to run tests
  • Loading branch information
strfx committed Jul 19, 2023
1 parent 326fee7 commit 627c9ec
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ commit = True
tag = True
message = Release {new_version}

[bumpversion:file:setup.py]
[bumpversion:file:setup.cfg]

[bumpversion:file:docs/source/conf.py]

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/python-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: tests (pull_request)

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox without uploading coverage
run: tox
41 changes: 41 additions & 0 deletions .github/workflows/python-tox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests

on:
push:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2

- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: |
echo "CODECOV_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" \
>> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: |
echo "CODECOV_BRANCH=$(echo ${GITHUB_HEAD_REF} | tr / -)" \
>> $GITHUB_ENV
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox and upload coverage results
run: tox -- --codecov --codecov-token=${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
recursive-include suitable *
recursive-include src *
include *.rst
include LICENSE
global-exclude *.pyc
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The official way to use Ansible from Python is documented here:
Compatibility
-------------

* Python 2.7 and Python 3.5+.
* Python 3.8+
* Ansible 2.4+
* Mitogen 0.2.6+ (currently incompatible with Ansible 2.8)

Expand All @@ -40,9 +40,9 @@ Run Tests
Build Status
------------

.. image:: https://travis-ci.org/seantis/suitable.svg?branch=master
:target: https://travis-ci.org/seantis/suitable
:alt: Build status
.. image:: https://github.com/seantis/suitable/actions/workflows/python-tox.yaml/badge.svg
:target: https://github.com/seantis/suitable/actions
:alt: Tests

Test Coverage
-------------
Expand Down
44 changes: 44 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
log_level = "INFO"
testpaths = ["tests"]

[tool.coverage.run]
branch = true
source = ["src"]

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38,py39,py310,flake8,report
[testenv]
usedevelop = true
setenv =
py{38,39,310}: COVERAGE_FILE = .coverage.{envname}
deps =
-e{toxinidir}[tests]
commands = pytest --cov --cov-report= {posargs}
passenv = *
[testenv:flake8]
basepython = python3.10
skip_install = true
deps =
flake8
commands = flake8 src/ tests/
[testenv:report]
deps =
coverage
skip_install = true
commands =
coverage combine
coverage report -m
"""
45 changes: 44 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
[metadata]
name = suitable
version = 0.17.3
url = http://github.com/seantis/suitable/
author = Denis Krienbühl
author_email = denis@href.ch
maintainer = Seantis GmbH
maintainer_email = info@seantis.ch
description = Suitable is a thin wrapper around the Ansible API.
long_description = file: README.rst
long_description_content_type = text/x-rst
license = GPLv3
license_files = LICENSE
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Operating System :: OS Independent
Programming Language :: Python
Topic :: Software Development :: Libraries :: Python Modules


[options]
zip_safe = False
include_package_data = True
package_dir =
= src
packages =
suitable
python_requires = >= 3.6
platforms = any
install_requires =
ansible>=2.8.0.0
ansible-core<2.14

[options.extras_require]
tests =
mitogen>=0.2.8
paramiko
port-for
pytest
pytest-codecov[git]

[bdist_wheel]
universal = 1
universal = 1
69 changes: 0 additions & 69 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions suitable/tests/test_api.py → tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import gc
import os
import os.path
import pytest
from crypt import crypt

import pytest
from ansible.utils.display import Display
from crypt import crypt
from suitable.api import list_ansible_modules, Api

from suitable.api import Api, list_ansible_modules
from suitable.compat import text_type
from suitable.errors import ModuleError, UnreachableError
from suitable.mitogen import Api as MitogenApi
from suitable.mitogen import is_mitogen_supported
from suitable.errors import UnreachableError, ModuleError
from suitable.runner_results import RunnerResults
from suitable.compat import text_type


def test_auto_localhost():
Expand Down Expand Up @@ -270,11 +271,13 @@ def test_dict_args(tempdir):
api.set_stats(data={'foo': 'bar'})


@pytest.mark.skip()
def test_disable_hostkey_checking(api):
api.host_key_checking = False
assert api.command('whoami').stdout() == 'root'


@pytest.mark.skip()
def test_enable_hostkey_checking_vanilla(container):
# if we do not use 'paramiko' here, we get the following error:
# > Using a SSH password instead of a key is not possible because Host Key
Expand All @@ -287,6 +290,7 @@ def test_enable_hostkey_checking_vanilla(container):
assert api.command('whoami').stdout() == 'root'


@pytest.mark.skip()
def test_interleaving(container):
# make sure we can interleave calls of different API objects
password = crypt("foobar", "salt")
Expand Down
File renamed without changes.
Loading

0 comments on commit 627c9ec

Please sign in to comment.