Initial commit

This commit is contained in:
Philip Meier
2020-07-09 17:42:03 +02:00
commit 3ba8cc5ecb
33 changed files with 1094 additions and 0 deletions

5
.coveragerc Normal file
View File

@@ -0,0 +1,5 @@
[report]
exclude_lines =
@abstractmethod
raise NotImplementedError

24
.flake8 Normal file
View File

@@ -0,0 +1,24 @@
[flake8]
# See link below for available options
# https://flake8.pycqa.org/en/latest/user/options.html#options-and-their-descriptions
# Move this to pyproject.toml as soon as it is supported.
# See https://gitlab.com/pycqa/flake8/issues/428
exclude =
.git,
.github,
.venv,
.eggs,
.mypy_cache,
.pytest_cache,
.tox,
__pycache__,
*.pyc,
docs/build,
ignore = E203, E501, W503
max-line-length = 88
per-file-ignores =
__init__.py: F401, F403, F405
conftest.py: F401, F403, F405
show_source = True
statistics = True

55
.github/workflows/docs.yml vendored Normal file
View File

@@ -0,0 +1,55 @@
name: docs
on:
push:
branches:
- master
- releases/*
pull_request:
paths:
- "ltt/**"
- "docs/**"
- "setup.py"
- "tox.ini"
- "requirements-dev.txt"
- ".github/workflows/docs.yml"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: "3.6"
- name: Upgrade and install additional system packages
run: pip install --upgrade pip setuptools virtualenv wheel
- name: Install latex requirements
run: |
sudo apt update -y
sudo apt install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dev requirements
run: pip install -r requirements-dev.txt
- name: Build documentation
run: tox -e docs
- name: Upload html build
uses: actions/upload-artifact@v2
with:
name: html
path: docs/build/html
- name: Upload latex build
uses: actions/upload-artifact@v2
with:
name: latex
path: docs/build/latex/light-the-torch.pdf

39
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: lint
on:
push:
branches:
- master
- releases/*
pull_request:
paths:
- "**.py"
- "pyproject.toml"
- ".flake8"
- "mypy.ini"
- "tox.ini"
- "requirements-dev.txt"
- ".github/workflows/lint.yml"
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: "3.6"
- name: Upgrade and install additional system packages
run: pip install --upgrade pip setuptools virtualenv wheel
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dev requirements
run: pip install -r requirements-dev.txt
- name: Run lint
run: tox -e lint

38
.github/workflows/publish.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: publish
on:
push:
branches:
- releases/*
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: "3.6"
- name: Upgrade and install additional system packages
run: pip install --upgrade pip setuptools virtualenv wheel
- name: Checkout repository
uses: actions/checkout@v2
- name: Install pep517 and twine
run: pip install pep517 twine
- name: Build source and binary
run: python -m pep517.build --source --binary .
- name: Check README
run: twine check dist/*
- name: Upload to TestPyPI
env:
TWINE_REPOSITORY: testpypi
TWINE_USERNAME: ${{ secrets.TESTPYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TESTPYPI_PASSWORD }}
run: twine upload dist/*

34
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
name: release
on:
release:
types: [created]
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: "3.6"
- name: Upgrade and install additional system packages
run: pip install --upgrade pip setuptools virtualenv wheel
- name: Checkout repository
uses: actions/checkout@v2
- name: Install pep517 and twine
run: pip install pep517 twine
- name: Build source and binary
run: python -m pep517.build --source --binary .
- name: Upload to PyPI
env:
TWINE_REPOSITORY: pypi
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*

55
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,55 @@
name: tests
on:
push:
branches:
- master
- releases/*
pull_request:
paths:
- "ltt/**"
- "tests/**"
- "setup.py"
- "pytest.ini"
- "tox.ini"
- ".coveragerc"
- "codecov.yml"
- "requirements-dev.txt"
- ".github/workflows/tests.yml"
jobs:
run:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ['3.6', '3.7', '3.8']
fail-fast: true
runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python }}
steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Upgrade and install additional system packages
run: pip install --upgrade pip setuptools virtualenv wheel
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dev requirements
run: pip install -r requirements-dev.txt
- name: Run tests
run: tox -e py -- --skip-large-download
- name: Upload coverage
uses: codecov/codecov-action@v1.0.7
with:
env_vars: OS,PYTHON

134
.gitignore vendored Normal file
View File

@@ -0,0 +1,134 @@
ltt/_version.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# PyCharm project settings
.idea
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

21
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/timothycrosley/isort
rev: "4.3.21"
hooks:
- id: isort
args: [--settings-path=pyproject.toml, --filter-files]
additional_dependencies: [toml]
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
args: [--config=pyproject.toml]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: no-commit-to-branch

13
.readthedocs.yml Normal file
View File

@@ -0,0 +1,13 @@
version: 2
sphinx:
configuration: docs/source/conf.py
formats: all
python:
version: 3.6
install:
- requirements: docs/requirements-rtd.txt
- method: pip
path: .

100
CONTRIBUTING.rst Normal file
View File

@@ -0,0 +1,100 @@
Contributing guide lines
========================
We appreciate all contributions. If you are planning to contribute bug-fixes or
documentation improvements, please open a
`pull request (PR) <https://github.com/pmeier/light-the-torch/pulls>`_
without further discussion. If you planning to contribute new features, please open an
`issue <https://github.com/pmeier/light-the-torch/issues>`_
and discuss the feature with us first.
Every PR is subjected to multiple checks that it has to pass before it can be merged.
The checks are performed by `tox <https://tox.readthedocs.io/en/latest/>`_ . You can
install it alongside all other development requirements with
.. code-block:: sh
cd $LTT_ROOT
pip install -r requirements-dev.txt
Below you can find details and instructions how to run the checks locally.
Code format and linting
-----------------------
``light-the-torch`` uses `isort <https://timothycrosley.github.io/isort/>`_ to sort the
imports, `black <https://black.readthedocs.io/en/stable/>`_ to format the code, and
`flake8 <https://flake8.pycqa.org/en/latest/>`_ to enforce
`PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ compliance.
Furthermore, ``light-the-torch`` is `PEP561 <https://www.python.org/dev/peps/pep-0561/>`_
compliant and checks the type annotations with `mypy <http://mypy-lang.org/>`_ .
To format your code run
.. code-block:: sh
cd $LTT_ROOT
tox -e format
.. note::
The formatting with ``isort``, ``black``, as well as other minor utilities can be
performed by `pre-commit <https://pre-commit.com/>`_ before every commit.
``pre-commit`` is installed as development requirement. To enable this behavior run
.. code-block:: sh
cd $LTT_ROOT
pre-commit install
To run the full lint check locally run
.. code-block:: sh
cd $LTT_ROOT
tox -e lint
Tests
-----
``pystiche`` uses `pytest <https://docs.pytest.org/en/stable/>`_ to run the test suite.
You can run it locally with
.. code-block:: sh
cd $LTT_ROOT
tox
.. note::
``light-the-torch`` adds the following custom options with the
corresponding ``@pytest.mark.*`` decorators:
- ``--skip-large-download``: ``@pytest.mark.large_download``
- ``--skip-slow``: ``@pytest.mark.slow``
- ``--run-flaky``: ``@pytest.mark.flaky``
Options prefixed with ``--skip`` are run by default and skipped if the option is
given. Options prefixed with ``--run`` are skipped by default and run if the option
is given.
These options are passed through ``tox`` if given after a ``--`` flag. For example,
the CI invocation command is equivalent to:
.. code-block:: sh
cd $LTT_ROOT
tox -- --skip-large-download
Documentation
-------------
To build the html and latex documentation locally, run
.. code-block:: sh
cd $LTT_ROOT
tox -e docs

29
LICENSE Normal file
View File

@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2020, Philip Meier
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

13
MANIFEST.in Normal file
View File

@@ -0,0 +1,13 @@
recursive-exclude .github *
recursive-exclude tests *
exclude .coveragerc
exclude .flake8
exclude .gitignore
exclude .pre-commit-config.yaml
exclude codecov.yml
exclude MANIFEST.in
exclude mypy.ini
exclude pytest.ini
exclude requirements-dev.txt
exclude tox.ini

68
README.rst Normal file
View File

@@ -0,0 +1,68 @@
light-the-torch
===============
Install PyTorch distributions with autodetected computation backend
.. start-badges
.. list-table::
:stub-columns: 1
* - package
- |license| |status|
* - code
- |black| |mypy| |lint|
* - tests
- |tests| |coverage|
* - docs
- |docs| |rtd|
.. end-badges
For installation instructions and usage examples please consult the documentation
`hosted on readthedocs.com <https://light-the-torch.readthedocs.io/en/latest>`_ .
.. |license|
image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
:target: https://opensource.org/licenses/BSD-3-Clause
:alt: License
.. |status|
image:: https://www.repostatus.org/badges/latest/wip.svg
:alt: Project Status: WIP
:target: https://www.repostatus.org/#wip
.. |black|
image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: black
.. |mypy|
image:: http://www.mypy-lang.org/static/mypy_badge.svg
:target: http://mypy-lang.org/
:alt: mypy
.. |lint|
image:: https://github.com/pmeier/light-the-torch/workflows/lint/badge.svg
:target: https://github.com/pmeier/light-the-torch/actions?query=workflow%3Alint+branch%3Amaster
:alt: Lint status via GitHub Actions
.. |tests|
image:: https://github.com/pmeier/light-the-torch/workflows/tests/badge.svg
:target: https://github.com/pmeier/light-the-torch/actions?query=workflow%3Atests+branch%3Amaster
:alt: Test status via GitHub Actions
.. |coverage|
image:: https://codecov.io/gh/pmeier/ltt/branch/master/graph/badge.svg
:target: https://codecov.io/gh/pmeier/ltt
:alt: Test coverage via codecov.io
.. |docs|
image:: https://github.com/pmeier/light-the-torch/workflows/docs/badge.svg
:target: https://github.com/pmeier/light-the-torch/actions?query=workflow%3Adocs+branch%3Amaster
:alt: Docs status via GitHub Actions
.. |rtd|
image:: https://img.shields.io/readthedocs/light-the-torch?label=latest&logo=read%20the%20docs
:target: https://light-the-torch.readthedocs.io/en/latest/?badge=latest
:alt: Latest documentation hosted on Read the Docs

8
codecov.yml Normal file
View File

@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
threshold: 0.05%
precision: 1
round: down
range: "50...95"

View File

@@ -0,0 +1,23 @@
import configparser
from os import path
def extract_requirements(root, file="tox.ini"):
config = configparser.ConfigParser()
config.read(path.join(root, "..", file))
return config["testenv:docs"]["deps"].strip().split("\n")
def write_requirements_file(root, requirements, file="requirements-rtd.txt"):
with open(path.join(root, file), "w") as fh:
fh.write("\n".join(requirements) + "\n")
def main(root):
requirements = extract_requirements(root)
write_requirements_file(root, requirements)
if __name__ == "__main__":
root = path.dirname(__file__)
main(root)

View File

@@ -0,0 +1,2 @@
sphinx >= 2
sphinx_rtd_theme

102
docs/source/conf.py Normal file
View File

@@ -0,0 +1,102 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Imports ---------------------------------------------------------------------------
import os
from datetime import datetime
from distutils.util import strtobool
from os import path
from importlib_metadata import metadata
# -- Run config ------------------------------------------------------------------------
def get_bool_env_var(name, default=False):
try:
return bool(strtobool(os.environ[name]))
except KeyError:
return default
run_by_github_actions = get_bool_env_var("GITHUB_ACTIONS")
run_by_rtd = get_bool_env_var("READTHEDOCS")
run_by_ci = run_by_github_actions or run_by_rtd or get_bool_env_var("CI")
# -- Path setup ------------------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
PROJECT_ROOT = path.abspath(path.join(path.abspath(path.dirname(__file__)), "..", ".."))
# -- Project information ---------------------------------------------------------------
meta = metadata("ltt")
project = meta["name"]
author = meta["author"]
copyright = f"{datetime.now().year}, {author}"
release = meta["version"]
version = ".".join(release.split(".")[:2])
# -- General configuration -------------------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
]
# Add any paths that contain templates here, relative to this directory.
# templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
# exclude_patterns = []
# -- Config for intersphinx -----------------------------------------------------------
intersphinx_mapping = {
"python": ("https://docs.python.org/3.6", None),
}
# -- Options for Latex / MathJax ------------------------------------------------------
with open("custom_cmds.tex", "r") as fh:
custom_cmds = fh.read()
latex_elements = {"preamble": custom_cmds}
mathjax_inline = [r"\(" + custom_cmds, r"\)"]
mathjax_display = [r"\[" + custom_cmds, r"\]"]
# -- Options for HTML output -----------------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ["_static"]

View File

@@ -0,0 +1 @@
.. include:: ../../CONTRIBUTING.rst

View File

8
docs/source/index.rst Normal file
View File

@@ -0,0 +1,8 @@
Welcome to light-the-torch's documentation!
===========================================
.. toctree::
:maxdepth: 2
Installation <installation>
Contributing <contributing>

View File

@@ -0,0 +1,18 @@
Installation
============
``ltt`` is a proper Python package and can be installed with
`pip <>`.
..
The latest **stable** version can be installed with
.. code-block:: sh
pip install ltt
The **latest** potentially unstable version can be installed with
.. code-block::
pip install git+https://github.com/pmeier/light-the-torch

1
ltt/__init__.py Normal file
View File

@@ -0,0 +1 @@
from ._version import version as __version__ # type: ignore[import]

0
ltt/py.typed Normal file
View File

31
mypy.ini Normal file
View File

@@ -0,0 +1,31 @@
[mypy]
; https://mypy.readthedocs.io/en/stable/config_file.html
; import discovery
files = ltt
; untyped definitions and calls
disallow_untyped_defs = True
; None and Optional handling
no_implicit_optional = True
; warnings
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
warn_unreachable = True
; miscellaneous strictness flags
allow_redefinition = True
; configuring error messages
show_error_context = True
show_error_codes = True
pretty = True
; miscellaneous
warn_unused_configs = True
[mypy-ltt]
warn_unused_ignores = False

60
pyproject.toml Normal file
View File

@@ -0,0 +1,60 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"setuptools_scm[toml]>=3.4"
]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
# See link below for available options
# https://github.com/pypa/setuptools_scm/#configuration-parameters
write_to = "ltt/_version.py"
version_scheme = "release-branch-semver"
local_scheme = "node-and-timestamp"
[tool.isort]
# See link below for available options
# https://github.com/timothycrosley/isort/wiki/isort-Settings#full-reference-of-isort-settings
skip = [
".git",
".github",
".venv",
".eggs",
".mypy_cache",
".pytest_cache",
".tox",
"__pycache__",
"docs/build",
]
line_length = 88
use_parentheses = true
multi_line_output = 3
force_grid_wrap = 0
include_trailing_comma = true
known_standard_library = ["setuptools", "typing_extensions"]
known_third_party = ["pytest"]
known_first_party = ["ltt"]
[tool.black]
# See link below for available options
# https://github.com/psf/black#configuration-format
line-length = 88
target-version = ['py36', 'py37', 'py38']
exclude = '''
/(
\.git
| \.github
| \.venv
| \.eggs
| \.mypy_cache
| \.pytest_cache
| \.tox
| __pycache__
| docs/build
)/
'''

10
pytest.ini Normal file
View File

@@ -0,0 +1,10 @@
[pytest]
;See link below for available options
;https://docs.pytest.org/en/latest/reference.html#ini-options-ref
markers =
large_download
slow
flaky
testpaths = tests/
addopts = -ra

2
requirements-dev.txt Normal file
View File

@@ -0,0 +1,2 @@
tox >= 3.2
pre-commit

30
setup.cfg Normal file
View File

@@ -0,0 +1,30 @@
[metadata]
name = ltt
platforms = any
description = Install PyTorch distributions with autodetected computation backend
long_description = file: README.rst
long_description_content_type = text/x-rst
keywords = pytorch, cuda, pip, install
url = https://github.com/pmeier/light-the-torch
author = Philip Meier
author-email = github.pmeier@posteo.de
license = BSD-3-Clause
classifiers =
Development Status :: 3 - Alpha
License :: OSI Approved :: BSD License
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Typing :: Typed
project_urls =
Source = https://github.com/pmeier/light-the-torch
Tracker = https://github.com/pmeier/light-the-torch/issues
[options]
packages = find:
python_requires = >=3.6
[options.packages.find]
exclude =
tests
tests.*

0
tests/__init__.py Normal file
View File

77
tests/conftest.py Normal file
View File

@@ -0,0 +1,77 @@
import pytest
class MarkConfig:
def __init__(
self,
keyword,
run_by_default,
addoption=True,
option=None,
help=None,
condition_for_skip=None,
reason=None,
):
self.addoption = addoption
if option is None:
option = (
f"--{'skip' if run_by_default else 'run'}-{keyword.replace('_', '-')}"
)
self.option = option
if help is None:
help = (
f"{'Skip' if run_by_default else 'Run'} tests decorated with @{keyword}"
)
self.help = help
if condition_for_skip is None:
def condition_for_skip(config, item):
has_keyword = keyword in item.keywords
if run_by_default:
return has_keyword and config.getoption(option)
else:
return has_keyword and not config.getoption(option)
self.condition_for_skip = condition_for_skip
if reason is None:
reason = (
f"Test is {keyword} and {option} was "
f"{'' if run_by_default else 'not '}given."
)
self.marker = pytest.mark.skip(reason=reason)
MARK_CONFIGS = (
MarkConfig(
keyword="large_download",
run_by_default=True,
reason=(
"Test possibly includes a large download and --skip-large-download was "
"given."
),
),
MarkConfig(keyword="slow", run_by_default=True),
MarkConfig(keyword="flaky", run_by_default=False),
)
def pytest_addoption(parser):
for mark_config in MARK_CONFIGS:
if mark_config.addoption:
parser.addoption(
mark_config.option,
action="store_true",
default=False,
help=mark_config.help,
)
def pytest_collection_modifyitems(config, items):
for item in items:
for mark_config in MARK_CONFIGS:
if mark_config.condition_for_skip(config, item):
item.add_marker(mark_config.marker)

34
tests/test_smoke.py Normal file
View File

@@ -0,0 +1,34 @@
import importlib
import pkgutil
import ltt as package_under_test
def test_importability(subtests):
def is_private(name):
return name.rsplit(".", 1)[-1].startswith("_")
def onerror(name):
if is_private(name):
return
with subtests.test(name=name):
raise
for finder, name, is_package in pkgutil.walk_packages(
path=package_under_test.__path__,
prefix=f"{package_under_test.__name__}.",
onerror=onerror,
):
if is_private(name):
continue
if not is_package:
try:
importlib.import_module(name)
except Exception:
onerror(name)
def test_version_availability():
assert isinstance(package_under_test.__version__, str)

59
tox.ini Normal file
View File

@@ -0,0 +1,59 @@
[tox]
;See link below for available options
;https://tox.readthedocs.io/en/latest/config.html
isolated_build = True
envlist = py{36, 37, 38}
skip_missing_interpreters = true
[testenv]
deps =
pytest
pytest-subtests
pytest-cov
commands =
pytest \
-c pytest.ini \
--cov=ltt \
--cov-report=xml \
--cov-config=.coveragerc \
{posargs}
[testenv:format]
requires =
pre-commit
whitelist_externals =
pre-commit
skip_install = true
deps =
commands =
pre-commit run --all-files
[testenv:lint]
whitelist_externals =
pre-commit
requires =
pre-commit
deps =
flake8 >= 3.8
mypy
commands =
pre-commit run --all-files
flake8 \
--config=.flake8
mypy \
--config-file=mypy.ini
[testenv:docs]
passenv =
READTHEDOCS
GITHUB_ACTIONS
CI
deps =
importlib-metadata
sphinx >= 2
sphinx_rtd_theme
changedir = docs
commands =
sphinx-build -M html source build
sphinx-build -M latexpdf source build