-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor config tests and correct setup classifier spelling
- Loading branch information
Struan Judd
committed
Mar 23, 2018
1 parent
a3594ca
commit e26de74
Showing
13 changed files
with
230 additions
and
148 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -4,4 +4,3 @@ | |
|
||
__author__ = """Struan Lyall Judd""" | ||
__email__ = '[email protected]' | ||
__version__ = '0.1.0' |
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
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
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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" Config file processing """ | ||
|
||
from click import echo | ||
from configparser import ConfigParser | ||
from pathlib import Path | ||
from typing import Iterable, Tuple, Dict, Any, IO # noqa: F401 | ||
|
||
from .config import ConfigDependencies | ||
from .venv import VEnv | ||
|
||
|
||
class ConfigDependenciesImpl(ConfigDependencies): | ||
def write(self, config: ConfigParser, path: Path): # pragma: no cover | ||
with path.open('w') as out_config: | ||
config.write(out_config) | ||
|
||
def scripts(self, venv: VEnv, packages: Iterable[str]) -> Iterable[Tuple[str, str]]: # pragma: no cover | ||
if venv.create(): | ||
venv.install(*venv.requirements) | ||
venv.install(*packages) | ||
|
||
try: | ||
import pkg_resources | ||
except ImportError: | ||
echo("Unable to import pkg_resources to register %s into %s" % (sorted(packages), venv)) | ||
return [] | ||
|
||
pkg_env = pkg_resources.Environment(search_path=[str(venv.abs_path / 'lib' / 'site-packages')]) | ||
|
||
def pkg_scripts(p: str) -> Iterable[str]: | ||
scripts = {} # type: Dict | ||
dist = pkg_env[p] | ||
if len(dist): | ||
scripts = dist[0].get_entry_map().get('console_scripts') or {} | ||
return scripts.keys() | ||
|
||
return ((s, p) for p in packages for s in pkg_scripts(p)) | ||
|
||
def read(self, path: Path) -> IO[Any]: | ||
return path.open() | ||
|
||
def exists(self, path: Path) -> bool: | ||
return path.exists() |
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
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
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
author="Struan Lyall Judd", | ||
author_email='[email protected]', | ||
classifiers=[ | ||
'Development Status :: 4 - Betaa', | ||
'Development Status :: 4 - Beta', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'License :: OSI Approved :: BSD License', | ||
|
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Tests package for Script Venv.""" | ||
|
||
__author__ = """Struan Lyall Judd""" | ||
__email__ = '[email protected]' |
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,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" Doubles for testing""" | ||
from configparser import ConfigParser | ||
from io import StringIO | ||
from pathlib import Path | ||
from typing import IO, Any, Iterable, Tuple | ||
|
||
from script_venv.config import ConfigDependencies | ||
from script_venv.venv import VEnv | ||
|
||
|
||
class TestConfigDependencies(ConfigDependencies): | ||
in_str = "" | ||
out_str = "" | ||
|
||
def exists(self, path: Path) -> bool: | ||
return bool(self.in_str) | ||
|
||
def read(self, path: Path) -> IO[Any]: | ||
# noinspection PyTypeChecker | ||
return StringIO(self.in_str) | ||
|
||
def scripts(self, venv: VEnv, packages: Iterable[str]) -> Iterable[Tuple[str, str]]: | ||
return [(p, p + ".script") for p in packages] | ||
|
||
def write(self, config: ConfigParser, path: Path): | ||
with StringIO() as out_file: | ||
config.write(out_file) | ||
self.out_str = out_file.getvalue() |
Oops, something went wrong.