-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a97e74
commit 85594a0
Showing
7 changed files
with
173 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.6 | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: master | ||
hooks: | ||
- id: isort | ||
|
||
- repo: https://github.com/psf/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.0.1' | ||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import click | ||
|
||
from . import core | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
@cli.command() | ||
@click.argument('package') | ||
def install(package): | ||
core.install_package(package) | ||
|
||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import logging | ||
import os | ||
import platform | ||
import shutil | ||
import stat | ||
import subprocess | ||
import glob | ||
import json | ||
|
||
import requests | ||
|
||
from .config import CONDA_ENV_PREFIX_PATH | ||
|
||
|
||
def ensure_conda(): | ||
conda_executable = shutil.which("conda") | ||
if conda_executable: | ||
return conda_executable | ||
|
||
conda_executable = shutil.which("conda.exe") | ||
if conda_executable: | ||
return conda_executable | ||
|
||
logging.info("No existing conda installation found. Installing the standalone") | ||
return install_conda_exe() | ||
|
||
|
||
def install_conda_exe(): | ||
conda_exe_prefix = "https://repo.anaconda.com/pkgs/misc/conda-execs" | ||
if platform.system() == "Linux": | ||
conda_exe_file = "conda-latest-linux-64.exe" | ||
elif platform.system() == "Darwin": | ||
conda_exe_file = "conda-latest-osx-64.exe" | ||
else: | ||
raise ValueError(f"Unsupported platform: {platform.system()}") | ||
|
||
resp = requests.get(f"{conda_exe_prefix}/{conda_exe_file}", allow_redirects=True) | ||
resp.raise_for_status() | ||
target_filename = os.path.expanduser("~/.local/conda.exe") | ||
with open(target_filename, "wb") as fo: | ||
fo.write(resp.content) | ||
st = os.stat(target_filename) | ||
os.chmod(target_filename, st.st_mode | stat.S_IXUSR) | ||
return target_filename | ||
|
||
|
||
def ensure_dest_prefix(): | ||
if not os.path.exists(CONDA_ENV_PREFIX_PATH): | ||
os.mkdir(CONDA_ENV_PREFIX_PATH) | ||
|
||
|
||
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 | ||
]) | ||
|
||
|
||
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: | ||
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/')] | ||
break | ||
else: | ||
raise ValueError("Could not determine package files") | ||
|
||
executables = [] | ||
for fn in potential_executables: | ||
abs_executable_path = f'{env_prefix}/{fn}' | ||
if os.access(abs_executable_path, os.X_OK): | ||
executables.append(abs_executable_path) | ||
|
||
return executables | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
|
||
CONDA_ENV_PREFIX_PATH = os.path.expanduser("~/.condax") | ||
CONDAX_LINK_DESTINATION = os.path.expanduser("~/.local/bin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
from .config import CONDAX_LINK_DESTINATION | ||
from .conda import ( | ||
create_conda_environment, | ||
detemine_executables_from_env, | ||
) | ||
|
||
|
||
def install_package(package): | ||
create_conda_environment(package) | ||
executables_to_link = detemine_executables_from_env(package) | ||
for exe in executables_to_link: | ||
executable_name = os.path.basename(exe) | ||
os.symlink(exe, f"{CONDAX_LINK_DESTINATION}/{executable_name}") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,47 +7,49 @@ | |
|
||
from setuptools import find_packages, setup | ||
|
||
with open('condax/__init__.py', 'r') as f: | ||
with open("condax/__init__.py", "r") as f: | ||
for line in f: | ||
if line.startswith('__version__'): | ||
version = line.strip().split('=')[1].strip(' \'"') | ||
if line.startswith("__version__"): | ||
version = line.strip().split("=")[1].strip(" '\"") | ||
break | ||
else: | ||
version = '0.0.1' | ||
version = "0.0.1" | ||
|
||
with open('README.md', 'r', encoding='utf-8') as f: | ||
with open("README.md", "r", encoding="utf-8") as f: | ||
readme = f.read() | ||
|
||
REQUIRES = [ | ||
'click' | ||
] | ||
REQUIRES = ["click"] | ||
|
||
setup( | ||
name='condax', | ||
name="condax", | ||
version=version, | ||
description='Install and run applications packaged with conda in isolated environments', | ||
long_description= readme, | ||
author= 'Marius van Niekerk', | ||
author_email= '[email protected]', | ||
maintainer= 'Marius van Niekerk', | ||
maintainer_email= '[email protected]', | ||
url= 'https://github.com/mariusvniekerk/condax', | ||
license= 'MIT', | ||
classifiers= [ | ||
'Development Status :: 4 - Beta', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Natural Language :: English', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
'Programming Language :: Python :: Implementation :: PyPy', | ||
description="Install and run applications packaged with conda in isolated environments", | ||
long_description=readme, | ||
author="Marius van Niekerk", | ||
author_email="[email protected]", | ||
maintainer="Marius van Niekerk", | ||
maintainer_email="[email protected]", | ||
url="https://github.com/mariusvniekerk/condax", | ||
license="MIT", | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Natural Language :: English", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 2.7", | ||
"Programming Language :: Python :: 3.5", | ||
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
], | ||
python_requires=">=3.6", | ||
install_requires=REQUIRES, | ||
tests_require=['coverage', 'pytest'], | ||
packages=find_packages(exclude=('tests', 'tests.*')), | ||
|
||
tests_require=["coverage", "pytest"], | ||
packages=find_packages(exclude=("tests", "tests.*")), | ||
entry_points={ | ||
'console_scipts': [ | ||
'condax = condax.cli:cli' | ||
] | ||
}, | ||
) |