Skip to content

Commit 098db15

Browse files
chore(lint): update typing and linting (#425)
# change advances #305 - replace `flake8` with `ruff` and install `pre-commit` - run linters as part of a separate job (to separate linting from testing) - add a draft of `mypy` setup but not try to fix stuff because it's a complicated procedure to fix everything - this PR already reformatted a lot of code --------- Co-authored-by: Balint Bartha <[email protected]> Co-authored-by: David Ankin <[email protected]>
1 parent 386521f commit 098db15

File tree

73 files changed

+832
-3808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+832
-3808
lines changed

.github/workflows/ci-community.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,5 @@ jobs:
7070
cache: poetry
7171
- name: Install Python dependencies
7272
run: poetry install -E ${{ matrix.module }}
73-
- name: Run linter
74-
run: make modules/${{ matrix.module }}/lint
7573
- name: Run tests
76-
run: make modules/${{ matrix.module }}/tests
74+
run: make modules/${{ matrix.module }}/tests

.github/workflows/ci-core.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ jobs:
2525
python-version: ${{ matrix.python-version }}
2626
cache: poetry
2727
- name: Install Python dependencies
28-
run: poetry install
29-
- name: Run linter
30-
run: make core/lint
28+
run: poetry install --all-extras
3129
- name: Run twine check
3230
run: poetry build && poetry run twine check dist/*.tar.gz
3331
- name: Run tests

.github/workflows/ci-lint.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Contrinuous Integration for the core package
2+
3+
name: lint
4+
5+
on:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
11+
jobs:
12+
all:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Setup Poetry
17+
run: pipx install poetry
18+
- name: Setup python 3.9
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.9
22+
cache: poetry
23+
- name: Install Python dependencies
24+
run: poetry install
25+
- name: Install pre-commit
26+
run: pip install pre-commit
27+
- name: Run linter
28+
run: pre-commit run -a

.pre-commit-config.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
default_language_version:
2+
python: python3.9
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: 'v4.5.0'
7+
hooks:
8+
- id: check-toml
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
12+
- repo: https://github.com/psf/black-pre-commit-mirror
13+
rev: '24.1.1'
14+
hooks:
15+
- id: black
16+
args: [ '--config', 'pyproject.toml' ]
17+
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: 'v0.1.14'
20+
hooks:
21+
- id: ruff
22+
# Explicitly setting config to prevent Ruff from using `pyproject.toml` in sub packages.
23+
args: [ '--fix', '--exit-non-zero-on-fix', '--config', 'pyproject.toml' ]
24+
25+
# - repo: local
26+
# hooks:
27+
# - id: mypy
28+
# name: mypy
29+
# entry: poetry run mypy
30+
# args: ["--config-file", "pyproject.toml"]
31+
# files: "core" # start with the core being type checked
32+
# language: system
33+
# types: [ python ]
34+
# require_serial: true

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ RUN pip install --upgrade pip \
77
&& apt-get install -y \
88
freetds-dev \
99
&& rm -rf /var/lib/apt/lists/*
10-
ARG version=3.8
11-
COPY requirements/${version}.txt requirements.txt
10+
COPY build/requirements.txt requirements.txt
1211
COPY setup.py README.rst ./
1312
RUN pip install -r requirements.txt
1413
COPY . .

Dockerfile.diagnostics

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ FROM python:${version}
44
WORKDIR /workspace
55
COPY core core
66
RUN pip install --no-cache-dir -e core
7-
COPY diagnostics.py .
7+
COPY scripts/diagnostics.py .

INDEX.rst

+24-22
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ The snippet above will spin up a postgres database in a container. The :code:`ge
5858
Installation
5959
------------
6060

61-
The suite of testcontainers packages is available on `PyPI <https://pypi.org/project/testcontainers/>`_, and individual packages can be installed using :code:`pip`. We recommend installing the package you need by running :code:`pip install testcontainers-<feature>`, e.g., :code:`pip install testcontainers-postgres`.
61+
The suite of testcontainers packages is available on `PyPI <https://pypi.org/project/testcontainers/>`_,
62+
and individual packages can be installed using :code:`pip`.
6263

63-
.. note::
64+
Version `4.0.0` onwards we do not support the `testcontainers-*` packages as it is unsutainable to maintain ownership.
6465

65-
For backwards compatibility, packages can also be installed by specifying `extras <https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies>`__, e.g., :code:`pip install testcontainers[postgres]`.
66+
Instead packages can be installed by specifying `extras <https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies>`__, e.g., :code:`pip install testcontainers[postgres]`.
6667

6768

6869
Docker in Docker (DinD)
@@ -80,8 +81,8 @@ We recommend you use a `virtual environment <https://virtualenv.pypa.io/en/stabl
8081

8182
.. code-block:: bash
8283
83-
pip install -r requirements/[your python version].txt
84-
pytest -s
84+
poetry install --all-extras
85+
make <your-module>/tests
8586
8687
Package Structure
8788
^^^^^^^^^^^^^^^^^
@@ -90,23 +91,24 @@ Testcontainers is a collection of `implicit namespace packages <https://peps.pyt
9091

9192
.. code-block:: bash
9293
93-
# One folder per feature.
94-
[feature name]
95-
# Folder without __init__.py for implicit namespace packages.
96-
testcontainers
97-
# Implementation as namespace package with __init__.py.
98-
[feature name]
99-
__init__.py
100-
# Other files for this
101-
...
102-
# Tests for the feature.
103-
tests
104-
test_[feature_name].py
105-
...
106-
# README for this feature.
107-
README.rst
108-
# Setup script for this feature.
109-
setup.py
94+
modules
95+
# One folder per feature.
96+
[feature name]
97+
# Folder without __init__.py for implicit namespace packages.
98+
testcontainers
99+
# Implementation as namespace package with __init__.py.
100+
[feature name]
101+
__init__.py
102+
# Other files for this
103+
...
104+
# Tests for the feature.
105+
tests
106+
test_[some_aspect_for_the_feature].py
107+
...
108+
# README for this feature.
109+
README.rst
110+
# Setup script for this feature.
111+
setup.py
110112
111113
Contributing a New Feature
112114
^^^^^^^^^^^^^^^^^^^^^^^^^^

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ tests : ${TESTS}
2727
${TESTS} : %/tests :
2828
poetry run pytest -v --cov=testcontainers.$* $*/tests
2929

30-
# Targets to lint the code.
31-
lint : ${LINT}
32-
${LINT} : %/lint :
33-
poetry run flake8 $*
30+
# Target to lint the code.
31+
lint:
32+
pre-commit run -a
3433

3534
# Targets to publish packages.
3635
upload : ${UPLOAD}
@@ -42,7 +41,8 @@ ${UPLOAD} : %/upload :
4241
fi
4342

4443
# Targets to build docker images
45-
image: requirements/ubuntu-latest-${PYTHON_VERSION}.txt
44+
image:
45+
poetry export -f requirements.txt -o build/requirements.txt
4646
docker build --build-arg version=${PYTHON_VERSION} -t ${IMAGE} .
4747

4848
# Targets to run tests in docker containers

conf.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# testcontainers documentation build configuration file, created by
42
# sphinx-quickstart on Tue Mar 21 21:09:48 2017.
53
#
@@ -31,55 +29,55 @@
3129
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3230
# ones.
3331
extensions = [
34-
'sphinx.ext.autodoc',
35-
'sphinx.ext.doctest',
36-
'sphinx.ext.napoleon',
32+
"sphinx.ext.autodoc",
33+
"sphinx.ext.doctest",
34+
"sphinx.ext.napoleon",
3735
]
3836

3937
# Configure autodoc to avoid excessively long fully-qualified names.
4038
add_module_names = False
4139
autodoc_typehints_format = "short"
4240

4341
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
42+
templates_path = ["_templates"]
4543

4644
# The suffix(es) of source filenames.
4745
# You can specify multiple suffix as a list of string:
4846
#
4947
# source_suffix = ['.rst', '.md']
50-
source_suffix = '.rst'
48+
source_suffix = ".rst"
5149

5250
# The master toctree document.
53-
master_doc = 'INDEX'
51+
master_doc = "INDEX"
5452

5553
# General information about the project.
56-
project = u'testcontainers'
57-
copyright = u'2017, Sergey Pirogov'
58-
author = u'Sergey Pirogov'
54+
project = "testcontainers"
55+
copyright = "2017, Sergey Pirogov" # noqa: A001
56+
author = "Sergey Pirogov"
5957

6058
# The version info for the project you're documenting, acts as replacement for
6159
# |version| and |release|, also used in various other places throughout the
6260
# built documents.
6361
#
6462
# The short X.Y version.
65-
version = u'2.0.0'
63+
version = "2.0.0"
6664
# The full version, including alpha/beta/rc tags.
67-
release = u'2.0.0'
65+
release = "2.0.0"
6866

6967
# The language for content autogenerated by Sphinx. Refer to documentation
7068
# for a list of supported languages.
7169
#
7270
# This is also used if you do content translation via gettext catalogs.
7371
# Usually you set "language" from the command line for these cases.
74-
language = 'en'
72+
language = "en"
7573

7674
# List of patterns, relative to source directory, that match files and
7775
# directories to ignore when looking for source files.
7876
# This patterns also effect to html_static_path and html_extra_path
79-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', "meta/README.rst", '.venv']
77+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "meta/README.rst", ".venv"]
8078

8179
# The name of the Pygments (syntax highlighting) style to use.
82-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
8381

8482
# If true, `todo` and `todoList` produce output, else they produce nothing.
8583
todo_include_todos = False
@@ -90,7 +88,7 @@
9088
# The theme to use for HTML and HTML Help pages. See the documentation for
9189
# a list of builtin themes.
9290
#
93-
html_theme = 'alabaster'
91+
html_theme = "alabaster"
9492

9593
# Theme options are theme-specific and customize the look and feel of a theme
9694
# further. For a list of options available for each theme, see the
@@ -107,7 +105,7 @@
107105
# -- Options for HTMLHelp output ------------------------------------------
108106

109107
# Output file base name for HTML help builder.
110-
htmlhelp_basename = 'testcontainersdoc'
108+
htmlhelp_basename = "testcontainersdoc"
111109

112110

113111
# -- Options for LaTeX output ---------------------------------------------
@@ -116,15 +114,12 @@
116114
# The paper size ('letterpaper' or 'a4paper').
117115
#
118116
# 'papersize': 'letterpaper',
119-
120117
# The font size ('10pt', '11pt' or '12pt').
121118
#
122119
# 'pointsize': '10pt',
123-
124120
# Additional stuff for the LaTeX preamble.
125121
#
126122
# 'preamble': '',
127-
128123
# Latex figure (float) alignment
129124
#
130125
# 'figure_align': 'htbp',
@@ -134,19 +129,15 @@
134129
# (source start file, target name, title,
135130
# author, documentclass [howto, manual, or own class]).
136131
latex_documents = [
137-
(master_doc, 'testcontainers.tex', u'testcontainers Documentation',
138-
u'Sergey Pirogov', 'manual'),
132+
(master_doc, "testcontainers.tex", "testcontainers Documentation", "Sergey Pirogov", "manual"),
139133
]
140134

141135

142136
# -- Options for manual page output ---------------------------------------
143137

144138
# One entry per manual page. List of tuples
145139
# (source start file, name, description, authors, manual section).
146-
man_pages = [
147-
(master_doc, 'testcontainers', u'testcontainers Documentation',
148-
[author], 1)
149-
]
140+
man_pages = [(master_doc, "testcontainers", "testcontainers Documentation", [author], 1)]
150141

151142

152143
# -- Options for Texinfo output -------------------------------------------
@@ -155,7 +146,13 @@
155146
# (source start file, target name, title, author,
156147
# dir menu entry, description, category)
157148
texinfo_documents = [
158-
(master_doc, 'testcontainers', u'testcontainers Documentation',
159-
author, 'testcontainers', 'One line description of project.',
160-
'Miscellaneous'),
149+
(
150+
master_doc,
151+
"testcontainers",
152+
"testcontainers Documentation",
153+
author,
154+
"testcontainers",
155+
"One line description of project.",
156+
"Miscellaneous",
157+
),
161158
]

core/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ testcontainers-core
33

44
:code:`testcontainers-core` is the core functionality for spinning up Docker containers in test environments.
55

6-
.. autoclass:: testcontainers.core.container.DockerContainer
6+
.. autoclass:: testcontainers.core.container.DockerContainer

0 commit comments

Comments
 (0)