Skip to content

Commit

Permalink
feat(project): Add local-lib-path config option.
Browse files Browse the repository at this point in the history
Points to a directory (relative to your projects root) where any local dependencies should be stored
.
  • Loading branch information
BradenM committed Dec 9, 2019
1 parent 2dec0ca commit d5b7390
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -fr pip-wheel-metadata/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +

Expand All @@ -23,9 +24,10 @@ clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
find . -name '.pytest_cache' -exec rm -fr {} +
rm -f .testmondata
rm -rf .tmontmp
rm cov.xml test_log.xml

lint: ## check style with flake8
flake8 micropy tests --config=setup.cfg
Expand Down
4 changes: 3 additions & 1 deletion micropy/project/modules/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def context(self):
"""
_paths = set(self.parent.context.get('paths', set()))
_local_lib = self.parent.config.get('local-lib-path', 'src/lib')
_paths.add(self.pkg_path)
return {
'paths': _paths
'paths': _paths,
'local_lib': Path(_local_lib)
}

def install_package(self, source: Union[LocalDependencySource, PackageDependencySource]) -> Any:
Expand Down
7 changes: 5 additions & 2 deletions micropy/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ def __init__(self, path: str, name: Optional[str] = None, **kwargs: Any):
self.info_path: Path = self.path / 'micropy.json'
self.cache_path: Path = self.data_path / '.cache'
self._context = Config(source_format=DictConfigSource)

self.name: str = name or self.path.name
default_config = {
'name': self.name,
'local-lib-path': 'src/lib'
}
self._config: Config = Config(self.info_path,
default={'name': self.name},
default=default_config,
should_sync=lambda *a: self.exists)
self.log: ServiceLog = Log.add_logger(self.name, show_title=False)

Expand Down
6 changes: 5 additions & 1 deletion micropy/project/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, template, **kwargs):
self.stubs = kwargs.get("stubs", None)
self.paths = kwargs.get("paths", None)
self.datadir = kwargs.get("datadir", None)
self.local_lib = kwargs.get("local_lib", None)

@property
def context(self):
Expand Down Expand Up @@ -160,6 +161,8 @@ def context(self):
if self.datadir:
paths = [str(p.relative_to(self.datadir.parent))
for p in self.paths]
if self.local_lib:
paths.append(str(self.local_lib))
stub_paths = json.dumps(paths)
ctx = {
"stubs": self.stubs or [],
Expand All @@ -185,7 +188,8 @@ def context(self):
paths = [p.relative_to(self.datadir.parent) for p in self.paths]
ctx = {
"stubs": self.stubs or [],
"paths": paths or []
"paths": paths or [],
"local_lib": self.local_lib
}
return ctx

Expand Down
2 changes: 1 addition & 1 deletion micropy/project/template/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[MASTER]
# Loaded Stubs: {% for stub in stubs %} {{ stub }} {% endfor %}
init-hook='import sys;{% for path in paths %}sys.path.insert(1, "{{ path }}");{% endfor %}sys.path.insert(1,"./lib")'
init-hook='import sys;{% for path in paths %}sys.path.insert(1, "{{ path }}");{% endfor %}{% if local_lib %}sys.path.insert(1,"{{ local_lib }}"){% endif %}'

[MESSAGES CONTROL]
# Only show warnings with the listed confidence levels. Leave empty to show
Expand Down
8 changes: 5 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def _get_config(request, name="NewProject", stubs=None, templates=None, packages
stubs = stubs or []
_mods = {
'base': {
'name': name
'name': name,
'local-lib-path': 'src/lib'
},
'stubs': {
'stubs': {s.name: s.stub_version for s in stubs}
Expand Down Expand Up @@ -76,7 +77,7 @@ def _get_context(request, stubs=None, pkg_path=None, data_dir=None):
'stubs': {
'stubs': set(stubs),
'paths': list(_paths),
'datadir': data_dir
'datadir': data_dir,
},
'reqs': {
'paths': [pkg_path]
Expand All @@ -88,6 +89,7 @@ def _get_context(request, stubs=None, pkg_path=None, data_dir=None):
if 'reqs' in mods and 'stubs' in mods:
_ctx = _context['stubs'].copy()
_ctx['paths'].extend(_context['reqs']['paths'])
_ctx['local_lib'] = Path('src/lib')
return _ctx
context = {}
for m in mods:
Expand Down Expand Up @@ -176,7 +178,7 @@ def test_create(self, test_project, mock_checks, mods):
def test_config(self, test_project, get_config, mods):
test_proj, mp = next(test_project(mods))
expect_config = get_config(mods, stubs=list(mp.stubs)[:2])
assert test_proj.config._config == {'name': 'NewProject'}
assert test_proj.config._config == {'name': 'NewProject', 'local-lib-path': 'src/lib'}
test_proj.create()
assert test_proj.config._config == expect_config

Expand Down

0 comments on commit d5b7390

Please sign in to comment.