Skip to content

Commit

Permalink
Merge pull request canonical#82 from canonical/unpin-requirements
Browse files Browse the repository at this point in the history
python: unpin dependencies (CRAFT-664)
  • Loading branch information
sergiusens committed Nov 25, 2021
2 parents c01f104 + 0e4ad45 commit 1be2eff
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 152 deletions.
39 changes: 8 additions & 31 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,34 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Add local bin to PATH
run: |
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- name: Install craft-providers
run: |
sudo apt update
sudo apt install -y python3-pip python3-venv
python3 -m venv ${HOME}/.venv
source ${HOME}/.venv/bin/activate
pip install -U pip wheel setuptools
pip install -U -r requirements.txt -r requirements-dev.txt
pip install -e .
pip install -U .[dev]
- name: Run black
run: |
source ${HOME}/.venv/bin/activate
make test-black
- name: Run codespell
run: |
source ${HOME}/.venv/bin/activate
make test-codespell
- name: Run flake8
run: |
source ${HOME}/.venv/bin/activate
make test-flake8
- name: Run isort
run: |
source ${HOME}/.venv/bin/activate
make test-isort
- name: Run mypy
run: |
source ${HOME}/.venv/bin/activate
make test-mypy
- name: Run pydocstyle
run: |
source ${HOME}/.venv/bin/activate
make test-pydocstyle
- name: Run pylint
run: |
source ${HOME}/.venv/bin/activate
make test-pylint
- name: Run pyright
run: |
sudo apt install -y npm
sudo npm install -g pyright
source ${HOME}/.venv/bin/activate
sudo snap install --classic node
sudo snap install --classic pyright
make test-pyright
- name: Install LXD
run: |
Expand All @@ -74,7 +57,6 @@ jobs:
sudo lxd init --auto
- name: Run integration tests on Linux
run: |
source ${HOME}/.venv/bin/activate
export CRAFT_PROVIDERS_TESTS_ENABLE_SNAP_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_LXD_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_LXD_UNINSTALL=1
Expand All @@ -93,19 +75,15 @@ jobs:
fetch-depth: 0
- name: Install craft-providers
run: |
python3 -m venv ${HOME}/.venv
source ${HOME}/.venv/bin/activate
pip3 install -U pip wheel setuptools
pip3 install -U -r requirements.txt -r requirements-dev.txt
pip3 install -e .
pip3 install -U .[dev]
pip3 install -U -e .
- name: Install Multipass
run: |
brew install multipass
multipass version
sleep 20
- name: Run integration tests on MacOS
run: |
source ${HOME}/.venv/bin/activate
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_UNINSTALL=1
make test-integrations
Expand All @@ -128,9 +106,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install craft-providers
run: |
pip install -U pip wheel setuptools
pip install -U -r requirements.txt -r requirements-dev.txt
pip install -e .
pip3 install -U .[dev]
pip3 install -e .
- name: Run unit tests
run: |
pytest tests/unit
make test-units
17 changes: 7 additions & 10 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Build documentation with MkDocs
#mkdocs:
# configuration: mkdocs.yml
build:
os: "ubuntu-20.04"
tools:
python: "3.8"

# Optionally build your docs in additional formats such as PDF
formats:
- pdf

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.8
install:
- requirements: requirements.txt
- requirements: requirements-dev.txt
- requirements: docs/requirements.txt
- method: pip
path: .
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ coverage: ## Run pytest with coverage report.
docs: ## Generate documentation.
rm -f docs/craft_providers.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ craft_providers --no-toc --ext-githubpages
pip install -r docs/requirements.txt
$(MAKE) -C docs clean
$(MAKE) -C docs html

Expand Down
6 changes: 3 additions & 3 deletions craft_providers/lxd/lxd_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def launch(
:raises LXDError: On unexpected error.
"""
config_keys = dict()
config_keys = {}

if map_user_uid:
uid = os.getuid()
Expand Down Expand Up @@ -383,8 +383,8 @@ def _host_supports_mknod(self) -> bool:
:raises LXDError: On unexpected error.
"""
cfg = self.lxc.info(project=self.project, remote=self.remote)
env = cfg.get("environment", dict())
kernel_features = env.get("kernel_features", dict())
env = cfg.get("environment", {})
kernel_features = env.get("kernel_features", {})
seccomp_listener = kernel_features.get("seccomp_listener", "false")

return seccomp_listener == "true"
Expand Down
2 changes: 1 addition & 1 deletion craft_providers/multipass/multipass.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def list(self) -> List[str]:
details=errors.details_from_called_process_error(error),
) from error

data_list = json.loads(proc.stdout).get("list", list())
data_list = json.loads(proc.stdout).get("list", [])
return [instance["name"] for instance in data_list]

def mount(
Expand Down
2 changes: 1 addition & 1 deletion craft_providers/multipass/multipass_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def is_mounted(self, *, host_source: pathlib.Path, target: pathlib.Path) -> bool
:raises MultipassError: On unexpected failure.
"""
info = self._get_info()
mounts = info.get("mounts", dict())
mounts = info.get("mounts", {})

for mount_point, mount_config in mounts.items():
# Even on Windows, Multipass writes source_path as posix, e.g.:
Expand Down
2 changes: 1 addition & 1 deletion craft_providers/util/os_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def parse_os_release(content: str) -> Dict[str, str]:
stripped of encapsulating quotes.
"""
mappings: Dict[str, str] = dict()
mappings: Dict[str, str] = {}

for line in content.splitlines():
line = line.strip()
Expand Down
15 changes: 15 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@

# Enable support for google-style instance attributes.
napoleon_use_ivar = True


def run_apidoc(_):
from sphinx.ext.apidoc import main
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
cur_dir = os.path.abspath(os.path.dirname(__file__))
module = os.path.join(cur_dir, "..", "craft_providers")
main(["-e", "-o", cur_dir, module, "--no-toc", "--force"])


def setup(app):
app.connect("builder-inited", run_apidoc)
10 changes: 10 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Sphinx==4.2.0
sphinx-autodoc-typehints==1.12.0
sphinx-jsonschema==1.16.11
sphinx-pydantic==0.1.1
sphinx-rtd-theme==1.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
87 changes: 0 additions & 87 deletions requirements-dev.txt

This file was deleted.

9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"isort",
"mypy",
"pydocstyle",
"pylint",
# Incompatible with current pylint-fixme-info==1.0.2
# https://github.com/PyCQA/pylint/issues/5390
"pylint<2.12.0",
"pylint-fixme-info",
"pylint-pytest",
"pytest",
Expand All @@ -63,7 +65,7 @@
]

extras_requires = {
"dev": dev_requires + doc_requires + test_requires,
"dev": dev_requires + test_requires,
"doc": doc_requires,
"test": test_requires,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lxd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def tmp_instance(
lxc: LXC = LXC(),
):
if config_keys is None:
config_keys = dict()
config_keys = {}

lxc.launch(
instance_name=instance_name,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class FakeExecutor(Executor):
"""

def __init__(self) -> None:
self.records_of_push_file_io: List[Dict[str, Any]] = list()
self.records_of_pull_file: List[Dict[str, Any]] = list()
self.records_of_push_file: List[Dict[str, Any]] = list()
self.records_of_push_file_io: List[Dict[str, Any]] = []
self.records_of_pull_file: List[Dict[str, Any]] = []
self.records_of_push_file: List[Dict[str, Any]] = []

def push_file_io(
self,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/util/test_env_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@pytest.mark.parametrize(
"env,expected",
[
(dict(), ["env"]),
({}, ["env"]),
(dict(foo="bar"), ["env", "foo=bar"]),
(dict(foo="bar", foo2="bar2"), ["env", "foo=bar", "foo2=bar2"]),
(
Expand All @@ -42,7 +42,7 @@ def test_formulate_command(env, expected):
@pytest.mark.parametrize(
"env,expected",
[
(dict(), ["env", "-i"]),
({}, ["env", "-i"]),
(dict(foo="bar"), ["env", "-i", "foo=bar"]),
(dict(foo="bar", foo2="bar2"), ["env", "-i", "foo=bar", "foo2=bar2"]),
(
Expand Down

0 comments on commit 1be2eff

Please sign in to comment.