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

chore(lint): update typing and linting #425

Merged
Merged
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
4 changes: 1 addition & 3 deletions .github/workflows/ci-community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,5 @@ jobs:
cache: poetry
- name: Install Python dependencies
run: poetry install -E ${{ matrix.module }}
- name: Run linter
run: make modules/${{ matrix.module }}/lint
- name: Run tests
run: make modules/${{ matrix.module }}/tests
run: make modules/${{ matrix.module }}/tests
4 changes: 1 addition & 3 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Install Python dependencies
run: poetry install
- name: Run linter
run: make core/lint
run: poetry install --all-extras
- name: Run twine check
run: poetry build && poetry run twine check dist/*.tar.gz
- name: Run tests
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Contrinuous Integration for the core package

name: lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Poetry
run: pipx install poetry
- name: Setup python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: poetry
- name: Install Python dependencies
run: poetry install
- name: Install pre-commit
run: pip install pre-commit
- name: Run linter
run: pre-commit run -a
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
default_language_version:
python: python3.9

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
hooks:
- id: check-toml
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/psf/black-pre-commit-mirror
rev: '24.1.1'
hooks:
- id: black
args: [ '--config', 'pyproject.toml' ]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.14'
hooks:
- id: ruff
# Explicitly setting config to prevent Ruff from using `pyproject.toml` in sub packages.
args: [ '--fix', '--exit-non-zero-on-fix', '--config', 'pyproject.toml' ]

# - repo: local
# hooks:
# - id: mypy
# name: mypy
# entry: poetry run mypy
# args: ["--config-file", "pyproject.toml"]
# files: "core" # start with the core being type checked
# language: system
# types: [ python ]
# require_serial: true
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ RUN pip install --upgrade pip \
&& apt-get install -y \
freetds-dev \
&& rm -rf /var/lib/apt/lists/*
ARG version=3.8
COPY requirements/${version}.txt requirements.txt
COPY build/requirements.txt requirements.txt
COPY setup.py README.rst ./
RUN pip install -r requirements.txt
COPY . .
2 changes: 1 addition & 1 deletion Dockerfile.diagnostics
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM python:${version}
WORKDIR /workspace
COPY core core
RUN pip install --no-cache-dir -e core
COPY diagnostics.py .
COPY scripts/diagnostics.py .
46 changes: 24 additions & 22 deletions INDEX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ The snippet above will spin up a postgres database in a container. The :code:`ge
Installation
------------

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`.
The suite of testcontainers packages is available on `PyPI <https://pypi.org/project/testcontainers/>`_,
and individual packages can be installed using :code:`pip`.

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

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]`.
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]`.


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

.. code-block:: bash

pip install -r requirements/[your python version].txt
pytest -s
poetry install --all-extras
make <your-module>/tests

Package Structure
^^^^^^^^^^^^^^^^^
Expand All @@ -90,23 +91,24 @@ Testcontainers is a collection of `implicit namespace packages <https://peps.pyt

.. code-block:: bash

# One folder per feature.
[feature name]
# Folder without __init__.py for implicit namespace packages.
testcontainers
# Implementation as namespace package with __init__.py.
[feature name]
__init__.py
# Other files for this
...
# Tests for the feature.
tests
test_[feature_name].py
...
# README for this feature.
README.rst
# Setup script for this feature.
setup.py
modules
# One folder per feature.
[feature name]
# Folder without __init__.py for implicit namespace packages.
testcontainers
# Implementation as namespace package with __init__.py.
[feature name]
__init__.py
# Other files for this
...
# Tests for the feature.
tests
test_[some_aspect_for_the_feature].py
...
# README for this feature.
README.rst
# Setup script for this feature.
setup.py

Contributing a New Feature
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ tests : ${TESTS}
${TESTS} : %/tests :
poetry run pytest -v --cov=testcontainers.$* $*/tests

# Targets to lint the code.
lint : ${LINT}
${LINT} : %/lint :
poetry run flake8 $*
# Target to lint the code.
lint:
pre-commit run -a

# Targets to publish packages.
upload : ${UPLOAD}
Expand All @@ -42,7 +41,8 @@ ${UPLOAD} : %/upload :
fi

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

# Targets to run tests in docker containers
Expand Down
57 changes: 27 additions & 30 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# testcontainers documentation build configuration file, created by
# sphinx-quickstart on Tue Mar 21 21:09:48 2017.
#
Expand Down Expand Up @@ -31,55 +29,55 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.napoleon',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.napoleon",
]

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

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'INDEX'
master_doc = "INDEX"

# General information about the project.
project = u'testcontainers'
copyright = u'2017, Sergey Pirogov'
author = u'Sergey Pirogov'
project = "testcontainers"
copyright = "2017, Sergey Pirogov" # noqa: A001
author = "Sergey Pirogov"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'2.0.0'
version = "2.0.0"
# The full version, including alpha/beta/rc tags.
release = u'2.0.0'
release = "2.0.0"

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

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

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

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

# Output file base name for HTML help builder.
htmlhelp_basename = 'testcontainersdoc'
htmlhelp_basename = "testcontainersdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -116,15 +114,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -134,19 +129,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'testcontainers.tex', u'testcontainers Documentation',
u'Sergey Pirogov', 'manual'),
(master_doc, "testcontainers.tex", "testcontainers Documentation", "Sergey Pirogov", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'testcontainers', u'testcontainers Documentation',
[author], 1)
]
man_pages = [(master_doc, "testcontainers", "testcontainers Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -155,7 +146,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'testcontainers', u'testcontainers Documentation',
author, 'testcontainers', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"testcontainers",
"testcontainers Documentation",
author,
"testcontainers",
"One line description of project.",
"Miscellaneous",
),
]
2 changes: 1 addition & 1 deletion core/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ testcontainers-core

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

.. autoclass:: testcontainers.core.container.DockerContainer
.. autoclass:: testcontainers.core.container.DockerContainer
Loading
Loading