Skip to content

Commit

Permalink
Merge pull request #28 from valohai/renovate-2024
Browse files Browse the repository at this point in the history
Renovations, 2024
  • Loading branch information
ruksi committed Jun 10, 2024
2 parents 678c911 + 7a19296 commit 2f2d1c8
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 165 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ jobs:
strategy:
matrix:
python-version:
- '3.7'
- '3.10'
- '3.8'
- '3.12'
steps:
- name: 'Set up Python ${{ matrix.python-version }}'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python-version }}'
- uses: actions/checkout@v3
- run: 'pip install -e . -r requirements-dev.txt'
- uses: actions/checkout@v4
- run: 'pip install -e .[dev]'
- run: pytest -vvv --cov .
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v4

Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: actions/checkout@v3
- uses: pre-commit/action@v3.0.0
python-version: '3.12'
- uses: actions/checkout@v4
- uses: pre-commit/action@v3.0.1
40 changes: 0 additions & 40 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-20.04
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pip install -U pip setuptools build twine
- run: python -m build .
- run: twine upload --verbose dist/*
Expand Down
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.256
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.10.0
hooks:
- id: mypy
exclude: laituri_tests/test_.*
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![codecov](https://codecov.io/gh/valohai/laituri/branch/master/graph/badge.svg)](https://codecov.io/gh/valohai/laituri)

`laituri` is a set of Docker-related Python snippets used at [Valohai](https://valohai.com/).
You can use it with Python >= 3.7.
You can use it with Python >= 3.8.

## Usage

Expand Down Expand Up @@ -47,7 +47,7 @@ Installing editable library version in the current virtual environment.

```bash
# install this package and all development dependencies
pip install -e . -r requirements-dev.txt pip-tools pre-commit && pre-commit install
pip install -e .[dev] pre-commit && pre-commit install

# manually run lint and type checks
pre-commit run --all-files
Expand Down
20 changes: 13 additions & 7 deletions laituri/docker/credential_manager/docker_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ def docker_login(domain: str, username: str, password: str) -> bool:
args = [
get_docker_command(),
'login',
'--username', username,
'--username',
username,
'--password-stdin',
domain,
]
log.debug(f"Running `{' '.join(args)}`")
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try:
cmd_input = (password + '\n').encode('utf-8')
cmd_input = f"{password}\n".encode()
stdout, _ = proc.communicate(input=cmd_input, timeout=settings.DOCKER_TIMEOUT)
except subprocess.TimeoutExpired as te:
raise DockerLoginFailed('timed out') from te
Expand All @@ -76,11 +77,16 @@ def docker_logout(domain: str) -> None:

try:
log.debug(f'Running `docker logout {domain}`')
subprocess.check_call([
get_docker_command(),
'logout',
domain,
], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, timeout=settings.DOCKER_TIMEOUT)
subprocess.check_call(
[
get_docker_command(),
'logout',
domain,
],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
timeout=settings.DOCKER_TIMEOUT,
)
except subprocess.CalledProcessError as cpe:
message = cpe.stdout.decode('utf-8', errors='ignore')
log.warning(f'Failed `docker logout {domain}`: {message}')
2 changes: 2 additions & 0 deletions laituri/docker/credential_manager/ecr_with_role_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def ecr_with_role_v1_credential_manager(
auth_tries: int,
) -> Iterator[None]:
from boto3 import Session

role_name = registry_credentials['role_name']
creds = get_role_credentials_from_instance_metadata(role_name)
try:
Expand Down Expand Up @@ -47,6 +48,7 @@ def ecr_with_role_v1_credential_manager(

def get_role_credentials_from_instance_metadata(role_name: str) -> Dict[str, str]:
from botocore.utils import InstanceMetadataFetcher

fetcher = InstanceMetadataFetcher()
creds: Dict[str, str] = fetcher.retrieve_iam_role_credentials()
if creds.get('role_name') != role_name:
Expand Down
2 changes: 1 addition & 1 deletion laituri/utils/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def wrapped_func(*args, **kwargs): # type: ignore
try:
return func(*args, **kwargs)
except Exception:
delay = (2 ** (attempt - 1)) # 1, 2, 4, 8, 16, 32...
delay = 2 ** (attempt - 1) # 1, 2, 4, 8, 16, 32...
delay += random.random() # a tiny bit of random for desynchronizing multiple potential users
delay = min(delay, max_delay)
time.sleep(delay)
Expand Down
4 changes: 2 additions & 2 deletions laituri_tests/test_docker_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'type': 'docker',
'version': '1',
'username': 'edward',
'password': 'scissors123'
'password': 'scissors123',
}


Expand Down Expand Up @@ -83,7 +83,7 @@ def test_fallback_with_invalid_credential_configuration(mocker, missing_value):
with get_credential_manager(
image=image,
registry_credentials=VALID_DOCKER_CREDENTIALS,
log_status=my_logging_callback
log_status=my_logging_callback,
):
my_action()

Expand Down
4 changes: 2 additions & 2 deletions laituri_tests/test_registry_credentials_callback_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_callback_retry(mocker, requests_mock, with_header: bool, image: str):
{'status_code': 500},
{'exc': requests.exceptions.ConnectTimeout},
{'status_code': 200}, # no JSON
{'status_code': 200, 'json': VALID_CALLBACK_RESPONSE}
]
{'status_code': 200, 'json': VALID_CALLBACK_RESPONSE},
],
)
mock_popen = mocker.patch('subprocess.Popen', new_callable=create_mock_popen)
mocker.patch('time.sleep') # removes retry delays for testing
Expand Down
1 change: 0 additions & 1 deletion laituri_tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TestRetry:

@pytest.fixture(autouse=True)
def disable_sleep(self, mocker):
return mocker.patch('time.sleep') # removes retry delays for testing
Expand Down
51 changes: 46 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "laituri"
dynamic = ["version"]
description = "Docker Toolkit for Python"
readme = "README.md"
license = "MIT"
requires-python = ">=3.8"
authors = [
{ name = "Valohai", email = "hait@valohai.com" },
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]
dependencies = [
"requests>=2.23,<3",
]

[project.optional-dependencies]
dev = [
"pytest",
"pytest-cov",
"pytest-mock",
"requests-mock",
]

[project.urls]
Homepage = "https://github.com/valohai/laituri"

[tool.hatch.version]
path = "laituri/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
"/laituri",
]
build-backend = "setuptools.build_meta"

[tool.mypy]
strict = true
exclude = "laituri_tests/test_.*"

[tool.ruff]
target-version = "py37"
target-version = "py38"
line-length = 120

[tool.ruff.lint]
mccabe.max-complexity = 10
flake8-tidy-imports.ban-relative-imports = "all"
select = [
Expand All @@ -22,6 +59,10 @@ select = [
"I", # isort
"T", # debugger and print
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = []

[tool.ruff.format]
quote-style = "preserve"
5 changes: 0 additions & 5 deletions requirements-dev.in

This file was deleted.

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

This file was deleted.

28 changes: 0 additions & 28 deletions setup.cfg

This file was deleted.

0 comments on commit 2f2d1c8

Please sign in to comment.