Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for fabric3.0 #46

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: test
run-name: Run tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pre-commit:
name: Check pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]

pytest-fabric2:
name: Test for Fabric 2.0 compatibility
runs-on: ubuntu-latest
needs: [ pre-commit ]
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
fabric-version: [ "==2.2","<3.0" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Fabric ${{ matrix.fabric-version }} and patchwork
run: pip install "fabric${{ matrix.fabric-version }}" .[test]
- name: Test with pytest
run: pytest

pytest:
name: Run pytests
runs-on: ubuntu-latest
needs: [ pre-commit ]
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup patchwork
run: pip install -e .[test]
- name: Test with pytest
run: pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
docs/_build
.cache
.coverage
/venv
/build
/.idea
*.egg-info
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.21.0
hooks:
- id: check-github-workflows
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

15 changes: 0 additions & 15 deletions dev-requirements.txt

This file was deleted.

63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "patchwork"
version = "2.0.0"
description = "Deployment/sysadmin operations, powered by Fabric"
authors = [{ name = "Jeff Forcier", email = "[email protected]" }]
maintainers = [{ name = "Jeff Forcier", email = "[email protected]" }]
requires-python = ">=3.7"
readme = "README.rst"
license = { file = "LICENSE" }
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Topic :: Software Development",
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Software Distribution",
"Topic :: System :: Systems Administration",
]

dependencies = [
"fabric>=2.2",
]

[project.optional-dependencies]
docs = [
"releases",
"alabaster",
"sphinx",
]
test = [
"invocations",
"pytest",
"mock",
"pytest-relaxed",
]
test-cov = [
"pytest-cov",
]
dev = [
"patchwork[test]",
"pre-commit",
]

[project.urls]
homepage = "https://www.fabfile.org/"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "*"
14 changes: 0 additions & 14 deletions setup.cfg

This file was deleted.

48 changes: 0 additions & 48 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion patchwork/environment.py → src/patchwork/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def have_program(c, name):
"""
Returns whether connected user has program ``name`` in their ``$PATH``.
"""
return c.run("which {}".format(name), hide=True, warn=True)
return c.run(f"which {name}", hide=True, warn=True)
16 changes: 7 additions & 9 deletions patchwork/files.py → src/patchwork/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import re

from invoke.vendor import six

from .util import set_runner


Expand All @@ -25,12 +23,12 @@ def directory(c, runner, path, user=None, group=None, mode=None):
:param str mode:
``chmod`` compatible mode string to apply to the directory.
"""
runner("mkdir -p {}".format(path))
runner(f"mkdir -p {path}")
if user is not None:
group = group or user
runner("chown {}:{} {}".format(user, group, path))
runner(f"chown {user}:{group} {path}")
if mode is not None:
runner("chmod {} {}".format(mode, path))
runner(f"chmod {mode} {path}")


@set_runner
Expand Down Expand Up @@ -78,8 +76,8 @@ def contains(c, runner, filename, text, exact=False, escape=True):
if escape:
text = _escape_for_regex(text)
if exact:
text = "^{}$".format(text)
egrep_cmd = 'egrep "{}" "{}"'.format(text, filename)
text = f"^{text}$"
egrep_cmd = f'egrep "{text}" "{filename}"'
return runner(egrep_cmd, hide=True, warn=True).ok


Expand Down Expand Up @@ -116,7 +114,7 @@ def append(c, runner, filename, text, partial=False, escape=True):
Whether to perform regex-oriented escaping on ``text``.
"""
# Normalize non-list input to be a list
if isinstance(text, six.string_types):
if isinstance(text, str):
text = [text]
for line in text:
regex = "^" + _escape_for_regex(line) + ("" if partial else "$")
Expand All @@ -127,7 +125,7 @@ def append(c, runner, filename, text, partial=False, escape=True):
):
continue
line = line.replace("'", r"'\\''") if escape else line
runner("echo '{}' >> {}".format(line, filename))
runner(f"echo '{line}' >> {filename}")


def _escape_for_regex(text):
Expand Down
2 changes: 1 addition & 1 deletion patchwork/info.py → src/patchwork/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def distro_name(c):
}
for name, sentinels in sentinel_files.items():
for sentinel in sentinels:
if exists(c, "/etc/{}".format(sentinel)):
if exists(c, f"/etc/{sentinel}"):
return name
return "other"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# apt/deb, rpm/yum/dnf, arch/pacman, etc etc etc.


from patchwork.info import distro_family
from ..info import distro_family


def package(c, *packages):
Expand All @@ -29,4 +29,4 @@ def rubygem(c, gem):
"""
Install a Ruby gem.
"""
return c.sudo("gem install -b --no-rdoc --no-ri {}".format(gem))
return c.sudo(f"gem install -b --no-rdoc --no-ri {gem}")
14 changes: 6 additions & 8 deletions patchwork/transfers.py → src/patchwork/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
File transfer functionality above and beyond basic ``put``/``get``.
"""

from invoke.vendor import six
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invoke does not bundle six, moved to str



def rsync(
c,
Expand Down Expand Up @@ -79,7 +77,7 @@ def rsync(
(rsync's ``--rsh`` flag.)
"""
# Turn single-string exclude into a one-item list for consistency
if isinstance(exclude, six.string_types):
if isinstance(exclude, str):
exclude = [exclude]
# Create --exclude options from exclude list
exclude_opts = ' --exclude "{}"' * len(exclude)
Expand All @@ -97,30 +95,30 @@ def rsync(
# always-a-list, always-up-to-date-from-all-sources attribute to save us
# from having to do this sort of thing. (may want to wait for Paramiko auth
# overhaul tho!)
if isinstance(keys, six.string_types):
if isinstance(keys, str):
keys = [keys]
if keys:
key_string = "-i " + " -i ".join(keys)
# Get base cxn params
user, host, port = c.user, c.host, c.port
port_string = "-p {}".format(port)
port_string = f"-p {port}"
# Remote shell (SSH) options
rsh_string = ""
# Strict host key checking
disable_keys = "-o StrictHostKeyChecking=no"
if not strict_host_keys and disable_keys not in ssh_opts:
ssh_opts += " {}".format(disable_keys)
ssh_opts += f" {disable_keys}"
rsh_parts = [key_string, port_string, ssh_opts]
if any(rsh_parts):
rsh_string = "--rsh='ssh {}'".format(" ".join(rsh_parts))
rsh_string = f"--rsh='ssh {' '.join(rsh_parts)}'"
# Set up options part of string
options_map = {
"delete": "--delete" if delete else "",
"exclude": exclude_opts.format(*exclusions),
"rsh": rsh_string,
"extra": rsync_opts,
}
options = "{delete}{exclude} -pthrvz {extra} {rsh}".format(**options_map)
options = f"{options_map['delete']}{options_map['exclude']} -pthrvz {options_map['extra']} {options_map['rsh']}"
# Create and run final command string
# TODO: richer host object exposing stuff like .address_is_ipv6 or whatever
if host.count(":") > 1:
Expand Down
Loading