Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit b1070ff

Browse files
James CrosbyJames Crosby
James Crosby
authored and
James Crosby
committed
unify get-dependencies and install-dependencies code (build should never fail to find a component if install installed it)
1 parent 97dcfa8 commit b1070ff

File tree

3 files changed

+280
-193
lines changed

3 files changed

+280
-193
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def read(fname):
77

88
setup(
99
name = "yotta",
10-
version = "0.0.17",
10+
version = "0.0.18",
1111
author = "James Crosby",
1212
author_email = "James.Crosby@arm.com",
1313
description = ("Re-usable components for embedded software."),

yotta/lib/access.py

Lines changed: 74 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,9 @@ def searchPathsForComponent(name, version_required, search_paths):
143143
return local_component
144144
return None
145145

146-
def satisfyVersion(
147-
name,
148-
version_required,
149-
available,
150-
search_paths,
151-
working_directory,
152-
update_installed=None
153-
):
154-
''' returns a Component for the specified version (either to an already
155-
installed copy (from the available list, or from disk), or to a newly
156-
downloaded one), or None if the version could not be satisfied.
157146

158-
update_installed = {None, 'Check', 'Update'}
159-
None: prevent any attempt to look for new versions if the
160-
component already exists
161-
Check: check for new versions, and pass new version information to
162-
the component object
163-
Update: replace any existing version with the newest available, if
164-
the newest available has a higher version
165-
'''
166-
147+
def satisfyVersionFromAvailble(name, version_required, available):
167148
spec = None
168-
v = None
169-
170149
if name in available:
171150
logger.debug('satisfy %s from already installed components' % name)
172151
try:
@@ -181,31 +160,28 @@ def satisfyVersion(
181160
r.getName(), name, r.path
182161
))
183162
return r
163+
return None
184164

165+
def satisfyVersionFromSearchPaths(name, version_required, search_paths, update=False):
166+
''' returns a Component for the specified version, if found in the list of
167+
search paths. If `update' is True, then also check for newer versions
168+
of the found component, and update it in-place (unless it was installed
169+
via a symlink).
170+
'''
171+
spec = None
172+
v = None
185173

186174
local_component = searchPathsForComponent(name, version_required, search_paths)
187175
logger.debug("%s %s locally" % (('found', 'not found')[not local_component], name))
188-
if local_component and (local_component.installedLinked() or update_installed != 'Update'):
189-
logger.debug("satisfy component from directory: %s" % local_component.path)
190-
# if a component exists (has a valid description file), and either is
191-
# not outdated, or we are not updating
192-
if name != local_component.getName():
193-
raise Exception('Component %s found in incorrectly named directory %s (%s)' % (
194-
local_component.getName(), name, local_component.path
195-
))
196-
return local_component
197-
198-
# if we need to check for latest versions, get the latest available version
199-
# before checking for a local component so that we can create the local
200-
# component with a handle to its latest available version
201-
if update_installed is not None:
202-
#logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
203-
v = latestSuitableVersion(name, version_required)
204-
if local_component:
205-
local_component.setLatestAvailable(v)
206-
207176
if local_component:
208-
if not local_component.outdated():
177+
if update and not local_component.installedLinked():
178+
#logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
179+
v = latestSuitableVersion(name, version_required)
180+
if local_component:
181+
local_component.setLatestAvailable(v)
182+
183+
# if we don't need to update, then we're done
184+
if local_component.installedLinked() or not local_component.outdated():
209185
logger.debug("satisfy component from directory: %s" % local_component.path)
210186
# if a component exists (has a valid description file), and either is
211187
# not outdated, or we are not updating
@@ -214,27 +190,36 @@ def satisfyVersion(
214190
local_component.getName(), name, local_component.path
215191
))
216192
return local_component
217-
elif local_component.outdated():
218-
logger.info('%soutdated: %s@%s -> %s' % (
219-
('update ' if update_installed == 'Update' else ''),
220-
name,
221-
local_component.getVersion(),
222-
v
223-
))
224-
# must rm the old component before continuing
225-
fsutils.rmRf(local_component.path)
193+
194+
# otherwise, we need to update the installed component
195+
logger.info('update outdated: %s@%s -> %s' % (
196+
name,
197+
local_component.getVersion(),
198+
v
199+
))
200+
# must rm the old component before continuing
201+
fsutils.rmRf(local_component.path)
202+
return _satisfyVersionByInstallingVersion(name, version_required, local_component.path, v)
203+
return None
226204

227-
if not v and update_installed is None:
228-
v = latestSuitableVersion(name, version_required)
205+
def satisfyVersionByInstalling(name, version_required, working_directory):
206+
''' installs and returns a Component for the specified name+version
207+
requirement, into a subdirectory of `working_directory'
208+
'''
209+
v = latestSuitableVersion(name, version_required)
210+
install_into = os.path.join(working_directory, name)
211+
return _satisfyVersionByInstallingVersion(name, version_required, install_into, v)
229212

230-
if not v:
231-
raise access_common.ComponentUnavailable(
232-
'Dependency "%s":"%s" is not a supported form.' % (name, version_required)
233-
)
234-
directory = os.path.join(working_directory, name)
213+
def _satisfyVersionByInstallingVersion(name, version_required, working_directory, version):
214+
''' installs and returns a Component for the specified version requirement into
215+
'working_directory' using the provided remote version object.
216+
This function is not normally called via `satisfyVersionByInstalling',
217+
which looks up a suitable remote version object.
218+
'''
219+
assert(version)
235220
logger.info('download ' + name)
236-
v.unpackInto(directory)
237-
r = component.Component(directory)
221+
version.unpackInto(working_directory)
222+
r = component.Component(working_directory)
238223
if not r:
239224
raise Exception(
240225
'Dependency "%s":"%s" is not a valid component.' % (name, version_required)
@@ -245,6 +230,35 @@ def satisfyVersion(
245230
))
246231
return r
247232

233+
def satisfyVersion(
234+
name,
235+
version_required,
236+
available,
237+
search_paths,
238+
working_directory,
239+
update_installed=None
240+
):
241+
''' returns a Component for the specified version (either to an already
242+
installed copy (from the available list, or from disk), or to a newly
243+
downloaded one), or None if the version could not be satisfied.
244+
245+
update_installed = None / 'Update'
246+
None: prevent any attempt to look for new versions if the
247+
component already exists
248+
Update: replace any existing version with the newest available, if
249+
the newest available has a higher version
250+
'''
251+
252+
r = satisfyVersionFromAvailble(name, version_required, available)
253+
if r is not None:
254+
return r
255+
256+
r = satisfyVersionFromSearchPaths(name, version_required, search_paths, update_installed == 'Update')
257+
if r is not None:
258+
return r
259+
260+
return satisfyVersionByInstalling(name, version_required, working_directory)
261+
248262

249263
def satisfyTarget(name, version_required, working_directory, update_installed=None):
250264
''' returns a Target for the specified version (either to an already

0 commit comments

Comments
 (0)