mirror of
https://github.com/pmeier/light-the-torch.git
synced 2024-09-08 23:29:28 +03:00
Rename ltt to light_the_torch (#6)
* meta * rename source * fix tests * fix cli entry point * fix coverage * fix mocks
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[run]
|
||||
|
||||
omit =
|
||||
ltt/__main__.py
|
||||
light_the_torch/__main__.py
|
||||
|
||||
[report]
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
ltt/_version.py
|
||||
light_the_torch/_version.py
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
||||
@@ -14,7 +14,7 @@ install it alongside all other development requirements with
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd $LTT_ROOT
|
||||
cd $LIGHT_THE_TORCH_ROOT
|
||||
pip install -r requirements-dev.txt
|
||||
|
||||
Below you can find details and instructions how to run the checks locally.
|
||||
@@ -35,7 +35,7 @@ To format your code run
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd $LTT_ROOT
|
||||
cd $LIGHT_THE_TORCH_ROOT
|
||||
tox -e format
|
||||
|
||||
.. note::
|
||||
@@ -46,26 +46,26 @@ To format your code run
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd $LTT_ROOT
|
||||
cd $LIGHT_THE_TORCH_ROOT
|
||||
pre-commit install
|
||||
|
||||
To run the full lint check locally run
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd $LTT_ROOT
|
||||
cd $LIGHT_THE_TORCH_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
|
||||
``light-the-torch`` 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
|
||||
cd $LIGHT_THE_TORCH_ROOT
|
||||
tox
|
||||
|
||||
.. note::
|
||||
@@ -85,5 +85,5 @@ You can run it locally with
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd $LTT_ROOT
|
||||
cd $LIGHT_THE_TORCH_ROOT
|
||||
tox -- --skip-large-download
|
||||
|
||||
@@ -48,18 +48,18 @@ CPU.
|
||||
Installation
|
||||
============
|
||||
|
||||
The latest **stable** version can be installed with
|
||||
The latest **published** version can be installed with
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
pip install lighter
|
||||
pip install light-the-torch
|
||||
|
||||
|
||||
The **latest** potentially unstable version can be installed with
|
||||
The latest, potentially unstable **development** version can be installed with
|
||||
|
||||
.. code-block::
|
||||
|
||||
pip install git+https://github.com/pmeier/lighter
|
||||
pip install git+https://github.com/pmeier/light-the-torch
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
@@ -5,7 +5,7 @@ import sys
|
||||
from copy import copy
|
||||
from typing import Iterable, List, NoReturn, Optional, Sequence, Tuple
|
||||
|
||||
import ltt
|
||||
import light_the_torch as ltt
|
||||
|
||||
from ._core.common import PatchedInstallCommand
|
||||
from .computation_backend import ComputationBackend
|
||||
4
mypy.ini
4
mypy.ini
@@ -2,7 +2,7 @@
|
||||
; https://mypy.readthedocs.io/en/stable/config_file.html
|
||||
|
||||
; import discovery
|
||||
files = ltt
|
||||
files = light_the_torch
|
||||
|
||||
; untyped definitions and calls
|
||||
disallow_untyped_defs = True
|
||||
@@ -27,7 +27,7 @@ pretty = True
|
||||
; miscellaneous
|
||||
warn_unused_configs = True
|
||||
|
||||
[mypy-ltt]
|
||||
[mypy-light_the_torch]
|
||||
warn_unused_ignores = False
|
||||
|
||||
[mypy-pip.*]
|
||||
|
||||
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
||||
# See link below for available options
|
||||
# https://github.com/pypa/setuptools_scm/#configuration-parameters
|
||||
|
||||
write_to = "ltt/_version.py"
|
||||
write_to = "light_the_torch/_version.py"
|
||||
version_scheme = "release-branch-semver"
|
||||
local_scheme = "node-and-timestamp"
|
||||
|
||||
@@ -26,7 +26,7 @@ skip = [
|
||||
".pytest_cache",
|
||||
".tox",
|
||||
"__pycache__",
|
||||
"ltt/__init__.py",
|
||||
"light_the_torch/__init__.py",
|
||||
]
|
||||
line_length = 88
|
||||
use_parentheses = true
|
||||
@@ -35,7 +35,7 @@ force_grid_wrap = 0
|
||||
include_trailing_comma = true
|
||||
|
||||
known_third_party = ["pytest", "setuptools_scm", "toml"]
|
||||
known_first_party = ["ltt"]
|
||||
known_first_party = ["light_the_torch"]
|
||||
|
||||
[tool.black]
|
||||
# See link below for available options
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[metadata]
|
||||
name = ltt
|
||||
name = light_the_torch
|
||||
platforms = any
|
||||
description = Install PyTorch distributions computation backend auto-detection
|
||||
long_description = file: README.rst
|
||||
@@ -38,4 +38,4 @@ exclude =
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
ltt=ltt.cli:main
|
||||
ltt=light_the_torch.cli:main
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from ltt._core import common
|
||||
from light_the_torch._core import common
|
||||
|
||||
|
||||
def test_get_public_or_private_attr_public_and_private():
|
||||
|
||||
@@ -2,14 +2,14 @@ import sys
|
||||
|
||||
import pytest
|
||||
|
||||
import ltt
|
||||
from ltt import computation_backend as cb
|
||||
from ltt._core.common import InternalLTTError
|
||||
from ltt._core.find import PytorchCandidatePreferences
|
||||
import light_the_torch as ltt
|
||||
from light_the_torch import computation_backend as cb
|
||||
from light_the_torch._core.common import InternalLTTError
|
||||
from light_the_torch._core.find import PytorchCandidatePreferences
|
||||
|
||||
|
||||
def test_resolve_dists_internal_error(mocker):
|
||||
mocker.patch("ltt._core.find.run")
|
||||
mocker.patch("light_the_torch._core.find.run")
|
||||
|
||||
with pytest.raises(InternalLTTError):
|
||||
ltt.find_links(["foo"])
|
||||
@@ -23,7 +23,8 @@ def test_PytorchCandidatePreferences_detect_computation_backend(mocker):
|
||||
|
||||
computation_backend = GenericComputationBackend()
|
||||
mocker.patch(
|
||||
"ltt._core.find.detect_computation_backend", return_value=computation_backend,
|
||||
"light_the_torch._core.find.detect_computation_backend",
|
||||
return_value=computation_backend,
|
||||
)
|
||||
|
||||
candidate_prefs = PytorchCandidatePreferences()
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import pytest
|
||||
|
||||
import ltt
|
||||
from ltt._core import resolve
|
||||
from ltt._core.common import InternalLTTError
|
||||
import light_the_torch as ltt
|
||||
from light_the_torch._core import resolve
|
||||
from light_the_torch._core.common import InternalLTTError
|
||||
|
||||
|
||||
def test_resolve_dists_internal_error(mocker):
|
||||
mocker.patch("ltt._core.resolve.run")
|
||||
mocker.patch("light_the_torch._core.resolve.run")
|
||||
|
||||
with pytest.raises(InternalLTTError):
|
||||
ltt.resolve_dists(["foo"])
|
||||
|
||||
|
||||
def test_StopAfterPytorchDistsFoundResolver_no_torch(mocker):
|
||||
mocker.patch("ltt._core.resolve.PatchedResolverBase.__init__", return_value=None)
|
||||
mocker.patch(
|
||||
"light_the_torch._core.resolve.PatchedResolverBase.__init__", return_value=None
|
||||
)
|
||||
resolver = resolve.StopAfterPytorchDistsFoundResolver()
|
||||
resolver._required_pytorch_dists = ["torchaudio", "torchtext", "torchvision"]
|
||||
assert "torch" in resolver.required_pytorch_dists
|
||||
|
||||
@@ -6,9 +6,9 @@ from io import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
import ltt
|
||||
from ltt import cli
|
||||
from ltt import computation_backend as cb
|
||||
import light_the_torch as ltt
|
||||
from light_the_torch import cli
|
||||
from light_the_torch import computation_backend as cb
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@@ -62,20 +62,22 @@ def test_main_version(subtests, mocker, patch_argv):
|
||||
|
||||
def test_main_no_distributions(mocker, patch_argv):
|
||||
patch_argv()
|
||||
mocker.patch("ltt.cli.ltt.resolve_dists", return_value=[])
|
||||
mocker.patch("ltt.cli.ltt.find_links", side_effect=RuntimeError)
|
||||
mocker.patch("light_the_torch.cli.ltt.resolve_dists", return_value=[])
|
||||
mocker.patch("light_the_torch.cli.ltt.find_links", side_effect=RuntimeError)
|
||||
|
||||
with exits():
|
||||
cli.main()
|
||||
|
||||
|
||||
def test_main_no_install(mocker, patch_argv):
|
||||
mocker.patch("ltt.cli.ltt.resolve_dists", return_value=["generic_pytorch_dist"])
|
||||
mocker.patch(
|
||||
"light_the_torch.cli.ltt.resolve_dists", return_value=["generic_pytorch_dist"]
|
||||
)
|
||||
links = [
|
||||
"https://download.pytorch.org/foo.whl",
|
||||
"https://download.pytorch.org/bar.whl",
|
||||
]
|
||||
mocker.patch("ltt.cli.ltt.find_links", return_value=links)
|
||||
mocker.patch("light_the_torch.cli.ltt.find_links", return_value=links)
|
||||
patch_argv("--no-install", "baz")
|
||||
stdout = mocker.patch.object(sys, "stdout", StringIO())
|
||||
|
||||
@@ -87,17 +89,19 @@ def test_main_no_install(mocker, patch_argv):
|
||||
|
||||
|
||||
def test_main_install(subtests, mocker, patch_argv):
|
||||
mocker.patch("ltt.cli.ltt.resolve_dists", return_value=["generic_pytorch_idst"])
|
||||
mocker.patch(
|
||||
"light_the_torch.cli.ltt.resolve_dists", return_value=["generic_pytorch_idst"]
|
||||
)
|
||||
links = [
|
||||
"https://download.pytorch.org/foo.whl",
|
||||
"https://download.pytorch.org/bar.whl",
|
||||
]
|
||||
mocker.patch("ltt.cli.ltt.find_links", return_value=links)
|
||||
mocker.patch("light_the_torch.cli.ltt.find_links", return_value=links)
|
||||
install_cmd = "pip install {links}"
|
||||
arg = "baz"
|
||||
patch_argv("--install-cmd", install_cmd, arg)
|
||||
|
||||
check_call_mock = mocker.patch("ltt.cli.subprocess.check_call")
|
||||
check_call_mock = mocker.patch("light_the_torch.cli.subprocess.check_call")
|
||||
|
||||
with exits():
|
||||
cli.main()
|
||||
@@ -109,17 +113,19 @@ def test_main_install(subtests, mocker, patch_argv):
|
||||
|
||||
|
||||
def test_main_full_install(subtests, mocker, patch_argv):
|
||||
mocker.patch("ltt.cli.ltt.resolve_dists", return_value=["generic_pytorch_dist"])
|
||||
mocker.patch(
|
||||
"light_the_torch.cli.ltt.resolve_dists", return_value=["generic_pytorch_dist"]
|
||||
)
|
||||
links = [
|
||||
"https://download.pytorch.org/foo.whl",
|
||||
"https://download.pytorch.org/bar.whl",
|
||||
]
|
||||
mocker.patch("ltt.cli.ltt.find_links", return_value=links)
|
||||
mocker.patch("light_the_torch.cli.ltt.find_links", return_value=links)
|
||||
install_cmd = "pip install {links}"
|
||||
arg = "baz"
|
||||
patch_argv("--full-install", "--install-cmd", install_cmd, arg)
|
||||
|
||||
check_call_mock = mocker.patch("ltt.cli.subprocess.check_call")
|
||||
check_call_mock = mocker.patch("light_the_torch.cli.subprocess.check_call")
|
||||
|
||||
with exits():
|
||||
cli.main()
|
||||
|
||||
@@ -2,7 +2,7 @@ import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from ltt import computation_backend as cb
|
||||
from light_the_torch import computation_backend as cb
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -90,7 +90,7 @@ skip_if_cuda_unavailable = pytest.mark.skipif(
|
||||
|
||||
def test_detect_computation_backend_no_nvcc(mocker):
|
||||
mocker.patch(
|
||||
"ltt.computation_backend.subprocess.check_output",
|
||||
"light_the_torch.computation_backend.subprocess.check_output",
|
||||
side_effect=subprocess.CalledProcessError(1, ""),
|
||||
)
|
||||
|
||||
@@ -99,7 +99,7 @@ def test_detect_computation_backend_no_nvcc(mocker):
|
||||
|
||||
def test_detect_computation_backend_unknown_release(mocker):
|
||||
mocker.patch(
|
||||
"ltt.computation_backend.subprocess.check_output",
|
||||
"light_the_torch.computation_backend.subprocess.check_output",
|
||||
return_value="release unknown".encode("utf-8"),
|
||||
)
|
||||
|
||||
@@ -110,7 +110,7 @@ def test_detect_computation_backend_cuda(mocker):
|
||||
major = 42
|
||||
minor = 21
|
||||
mocker.patch(
|
||||
"ltt.computation_backend.subprocess.check_output",
|
||||
"light_the_torch.computation_backend.subprocess.check_output",
|
||||
return_value=f"foo\nbar, release {major}.{minor}, baz".encode("utf-8"),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import importlib
|
||||
import pkgutil
|
||||
|
||||
import ltt as package_under_test
|
||||
import light_the_torch as package_under_test
|
||||
|
||||
|
||||
def test_importability(subtests):
|
||||
|
||||
Reference in New Issue
Block a user