Skip to content

Commit

Permalink
Add support for py36 and py37 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Apr 15, 2021
1 parent 6cb701d commit 704f087
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
include:
- tox_env: lint
- tox_env: integration
- tox_env: py36
- tox_env: py37
- tox_env: py38
- tox_env: py39

Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ error_summary = True
; warn_redundant_casts=True

# 3rd party ignores
[mypy-cached_property]
ignore_missing_imports = True

[mypy-click_completion]
ignore_missing_imports = True

Expand Down
17 changes: 15 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ blessings==1.7
# via mk (setup.cfg)
build==0.3.1.post1
# via mk (setup.cfg)
cached-property==1.5.2 ; python_version < "3.8"
# via mk (setup.cfg)
certifi==2020.12.5
# via requests
chardet==4.0.0
Expand All @@ -28,6 +30,10 @@ colorama==0.4.4
# twine
commonmark==0.9.1
# via rich
dataclasses==0.8 ; python_version < "3.7"
# via
# mk (setup.cfg)
# rich
diskcache==5.2.1
# via mk (setup.cfg)
docutils==0.17
Expand All @@ -40,8 +46,11 @@ idna==2.10
# via requests
importlib-metadata==3.10.0
# via
# build
# keyring
# mk (setup.cfg)
# pep517
# pluggy
# twine
keyring==23.0.1
# via twine
Expand Down Expand Up @@ -98,13 +107,17 @@ twine==3.4.1
typer==0.3.2
# via mk (setup.cfg)
typing-extensions==3.7.4.3
# via rich
# via
# importlib-metadata
# rich
urllib3==1.26.4
# via requests
webencodings==0.5.1
# via bleach
zipp==3.4.1
# via importlib-metadata
# via
# importlib-metadata
# pep517

# The following packages are considered to be unsafe in a requirements file:
# pip
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ classifiers =
Topic :: Software Development
Topic :: Utilities
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

[options]
use_scm_version = True
python_requires = >=3.8
python_requires = >=3.6
packages = find:
package_dir =
= src
include_package_data = True
zip_safe = False
install_requires =
cached-property>=1.5.2; python_version < '3.8' # BSD
GitPython
diskcache >= 5.2.1
blessings
build>=0.3.1.post1 # py_package
click >= 7.1.2
click-help-colors
colorama # for Windows
dataclasses; python_version < '3.7' # Apache
importlib-metadata
pip>=21.0.1 # py_package
pluggy
Expand Down
1 change: 0 additions & 1 deletion src/mk/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def run(args, *, check=False, cwd=None, tee=False) -> subprocess.CompletedProces
logging.info("Executing: %s", cmd)
result = subprocess_tee.run(
args,
capture_output=True,
check=check,
shell=shell,
universal_newlines=True,
Expand Down
11 changes: 9 additions & 2 deletions src/mk/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import hashlib
import logging
from functools import cached_property
import sys

try:
from functools import cached_property
except ImportError:
from cached_property import cached_property # type: ignore

from pathlib import Path
from typing import TYPE_CHECKING, List, Optional

Expand All @@ -24,7 +30,8 @@ def __init__(self) -> None:
return

self.root = Path(self.repo.working_dir)
self.hash = hashlib.sha1(str(self.root).encode("UTF-8")).hexdigest()[:5]
hash_key = f"{sys.version_info.major}{sys.version_info.minor}{self.root}"
self.hash = hashlib.sha1(hash_key.encode("UTF-8")).hexdigest()[:5]
self.cache = Cache(f"~/.cache/mk.{self.hash}/")

if self.repo.is_dirty():
Expand Down
18 changes: 16 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ blessings==1.7
# via mk (setup.cfg)
build==0.3.1.post1
# via mk (setup.cfg)
cached-property==1.5.2 ; python_version < "3.8"
# via mk (setup.cfg)
certifi==2020.12.5
# via requests
chardet==4.0.0
Expand All @@ -30,6 +32,10 @@ colorama==0.4.4
# twine
commonmark==0.9.1
# via rich
dataclasses==0.8 ; python_version < "3.7"
# via
# mk (setup.cfg)
# rich
diskcache==5.2.1
# via mk (setup.cfg)
docutils==0.17
Expand All @@ -42,8 +48,12 @@ idna==2.10
# via requests
importlib-metadata==3.10.0
# via
# build
# keyring
# mk (setup.cfg)
# pep517
# pluggy
# pytest
# twine
iniconfig==1.1.1
# via pytest
Expand Down Expand Up @@ -121,13 +131,17 @@ twine==3.4.1
typer==0.3.2
# via mk (setup.cfg)
typing-extensions==3.7.4.3
# via rich
# via
# importlib-metadata
# rich
urllib3==1.26.4
# via requests
webencodings==0.5.1
# via bleach
zipp==3.4.1
# via importlib-metadata
# via
# importlib-metadata
# pep517

# The following packages are considered to be unsafe in a requirements file:
# pip
30 changes: 6 additions & 24 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import re
import runpy
from subprocess import run
from typing import Optional

import pytest
from subprocess_tee import run


@pytest.mark.parametrize(
Expand All @@ -17,14 +17,8 @@
def test_show_completion_script(shell, expected) -> None:
"""Tests completion script generation."""
env = os.environ.copy()
env["SHELL"] = f"/bin/{shell}"
result = run(
["mk", "--show-completion"],
universal_newlines=True,
capture_output=True,
env=env,
check=False,
)
env["_TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION"] = "True"
result = run(f"mk --show-completion {shell}", env=env, check=False, tee=False)
assert result.returncode == 0, result
# very important as we could easily break it by sending data to stdout
assert expected in result.stdout
Expand All @@ -50,12 +44,6 @@ def do_complete() -> Optional[int]:
return runpy.run_module("mk", run_name="__main__")
except SystemExit as exc:
return exc.code
# return run(
# ["mk", "--show-completion"],
# universal_newlines=True,
# capture_output=True,
# check=True,
# )

result = benchmark(do_complete)

Expand All @@ -76,13 +64,7 @@ def test_show_completion_data(shell, expected) -> None:
env = os.environ.copy()
env["_MK_COMPLETE"] = f"complete_{shell}"
env["_TYPER_COMPLETE_ARGS"] = ""
result = run(
["mk", "--show-completion"],
universal_newlines=True,
capture_output=True,
env=env,
check=False,
)
result = run(["mk", "--show-completion"], env=env, check=False, tee=False)
# Apparently test return an unexpected 1 even if completion seems to be
# working, disabling return code testing until we know why.
# assert result.returncode == 0, result
Expand All @@ -92,14 +74,14 @@ def test_show_completion_data(shell, expected) -> None:

def test_help() -> None:
"""Tests display of help."""
result = run(["mk", "--help"], universal_newlines=True, capture_output=True, check=False)
result = run(["mk", "--help"], check=False, tee=False)
assert result.returncode == 0, result
# very important as we could easily break it by sending data to stdout
assert result.stdout.startswith("Usage: mk")


def test_no_git_repo() -> None:
"""Ensure error message is displayed outside git repos."""
result = run(["mk"], universal_newlines=True, capture_output=True, check=False, cwd="/")
result = run(["mk"], check=False, cwd="/", tee=False)
assert result.returncode == 0, result
assert "Current version of mk works only within git repos" in result.stderr
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ commands =

[testenv:deps]
description = Update dependency lock files
# Force it to use oldest supported version of python or we would lose ability
# to get pinning correctly.
basepython = python3.6
deps =
pip-tools >= 6.1.0
commands =
Expand Down

0 comments on commit 704f087

Please sign in to comment.