From 3c780884bb9426ac7eb8aff2bb5155582e6df4f9 Mon Sep 17 00:00:00 2001 From: Marius van Niekerk Date: Wed, 18 Dec 2019 23:07:14 -0500 Subject: [PATCH] black and isort --- .gitignore | 1 + .pre-commit-config.yaml | 11 +++++++--- condax/cli.py | 7 +++--- condax/conda.py | 47 +++++++++++++++++++++++------------------ condax/config.py | 2 +- condax/core.py | 8 +------ setup.py | 6 +----- tox.ini | 5 ++--- 8 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index e90f2ce..ee67d22 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .cache/ .coverage .idea/ +.mypy_cache/ .vscode/ condax.egg-info/ build/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3a5db1..e5b5417 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,16 @@ repos: - repo: https://github.com/pre-commit/mirrors-isort - rev: master + rev: v4.3.21 hooks: - id: isort - repo: https://github.com/psf/black - rev: stable + rev: 19.10b0 hooks: - id: black - language_version: python3.6 \ No newline at end of file + language_version: python3.6 + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.760 + hooks: + - id: mypy diff --git a/condax/cli.py b/condax/cli.py index 064cc2d..7bc58cc 100644 --- a/condax/cli.py +++ b/condax/cli.py @@ -7,11 +7,12 @@ def cli(): pass + @cli.command() -@click.argument('package') +@click.argument("package") def install(package): core.install_package(package) -if __name__ == '__main__': - cli() \ No newline at end of file +if __name__ == "__main__": + cli() diff --git a/condax/conda.py b/condax/conda.py index 906256e..bdfbc4f 100644 --- a/condax/conda.py +++ b/condax/conda.py @@ -1,11 +1,11 @@ +import glob +import json import logging import os import platform import shutil import stat import subprocess -import glob -import json import requests @@ -52,39 +52,44 @@ def ensure_dest_prefix(): def create_conda_environment(package): conda_exe = ensure_conda() - subprocess.check_call([ - conda_exe, 'create', - '--prefix', f'{CONDA_ENV_PREFIX_PATH}/{package}', - '--override-channels', - # TODO: allow configuring this - '--channel', 'conda-forge', - '--channel', 'defaults', - '--quiet', - package - ]) + subprocess.check_call( + [ + conda_exe, + "create", + "--prefix", + f"{CONDA_ENV_PREFIX_PATH}/{package}", + "--override-channels", + # TODO: allow configuring this + "--channel", + "conda-forge", + "--channel", + "defaults", + "--quiet", + package, + ] + ) def detemine_executables_from_env(package): env_prefix = f"{CONDA_ENV_PREFIX_PATH}/{package}" for file_name in glob.glob(f"{env_prefix}/conda-meta/{package}*.json"): - with open(file_name, 'r') as fo: + with open(file_name, "r") as fo: package_info = json.load(fo) if package_info["name"] == package: - potential_executables = [fn for fn in package_info["files"] if fn.startswith('bin/') or fn.startswith('sbin/')] + potential_executables = [ + fn + for fn in package_info["files"] + if fn.startswith("bin/") or fn.startswith("sbin/") + ] break else: raise ValueError("Could not determine package files") executables = [] for fn in potential_executables: - abs_executable_path = f'{env_prefix}/{fn}' + abs_executable_path = f"{env_prefix}/{fn}" if os.access(abs_executable_path, os.X_OK): executables.append(abs_executable_path) - - return executables - - - - + return executables diff --git a/condax/config.py b/condax/config.py index c5f49af..1b7cc4d 100644 --- a/condax/config.py +++ b/condax/config.py @@ -1,4 +1,4 @@ import os CONDA_ENV_PREFIX_PATH = os.path.expanduser("~/.condax") -CONDAX_LINK_DESTINATION = os.path.expanduser("~/.local/bin") \ No newline at end of file +CONDAX_LINK_DESTINATION = os.path.expanduser("~/.local/bin") diff --git a/condax/core.py b/condax/core.py index 6388068..96545be 100644 --- a/condax/core.py +++ b/condax/core.py @@ -1,10 +1,7 @@ import os +from .conda import create_conda_environment, detemine_executables_from_env from .config import CONDAX_LINK_DESTINATION -from .conda import ( - create_conda_environment, - detemine_executables_from_env, -) def install_package(package): @@ -13,6 +10,3 @@ def install_package(package): for exe in executables_to_link: executable_name = os.path.basename(exe) os.symlink(exe, f"{CONDAX_LINK_DESTINATION}/{executable_name}") - - - diff --git a/setup.py b/setup.py index 91c0da9..05a12ec 100644 --- a/setup.py +++ b/setup.py @@ -47,9 +47,5 @@ install_requires=REQUIRES, tests_require=["coverage", "pytest"], packages=find_packages(exclude=("tests", "tests.*")), - entry_points={ - 'console_scipts': [ - 'condax = condax.cli:cli' - ] - }, + entry_points={"console_scipts": ["condax = condax.cli:cli"]}, ) diff --git a/tox.ini b/tox.ini index e25dc9a..373e0df 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,8 @@ [tox] envlist = - py27, - py35, py36, - pypy, + py37, + py38, pypy3, [testenv]