Browse Source

update dev-install plugin

master
Niklas Rosenstein 1 year ago
parent
commit
9bdc42ba7f
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
2 changed files with 34 additions and 31 deletions
  1. + 13
    - 13
      src/shore/plugins/dev_install.py
  2. + 21
    - 18
      src/shore/templates/dev_install/dev-install

+ 13
- 13
src/shore/plugins/dev_install.py

@ -42,12 +42,12 @@ class DevInstallRenderer:
@override
def get_monorepo_files(self, monorepo: Monorepo) -> Iterable[FileToRender]:
nodes = self._get_interpackage_dependencies(monorepo)
pkg_order = list(toposort(sorted(nodes.keys()), lambda x: nodes[x]['dependencies']))
pkg_order = list(toposort(sorted(nodes.keys()), lambda x: nodes[x]['requires']))
package_def = '[\n'
for pkgname in pkg_order:
package = {
'name': pkgname,
'requires': nodes[pkgname]['dependencies'],
'requires': nodes[pkgname]['requires'],
'extra_requires': nodes[pkgname]['extra_requires']}
package_def += ' ' + json.dumps(package, sort_keys=True) + ',\n'
package_def += ']'
@ -66,19 +66,19 @@ class DevInstallRenderer:
for package in packages:
nodes[package.name] = {
'directory': os.path.basename(package.directory),
'dependencies': [],
'requires': [],
'extra_requires': {}
}
for package in packages:
for req in package.requirements.required:
if req.package in nodes:
nodes[package.name]['dependencies'].append(req.package)
for extra in package.requirements.extra:
for req in package.requirements.extra[extra]:
if req.package in nodes:
nodes[pacakge.name]['extra_requires'].setdefault(extra, []).append(req.package)
for req in (package.requirements.test.required if package.requirements.test else []):
def _flatten_reqs(dst, reqs):
for req in reqs.required if reqs else ():
if req.package in nodes:
nodes[package.name]['extra_requires'].setdefault('test', []).append(req.package)
dst.append(req.package)
for package in packages:
_flatten_reqs(nodes[package.name]['requires'], package.requirements)
_flatten_reqs(nodes[package.name].setdefault('test', []), package.requirements.test)
for extra, reqs in package.requirements.extra.items():
_flatten_reqs(nodes[package.name].setdefault(extra, []), reqs)
return nodes

+ 21
- 18
src/shore/templates/dev_install/dev-install

@ -15,7 +15,7 @@ parser.add_argument('--no-develop', action='store_true', help='Perform a normal
parser.add_argument('--uninstall', action='store_true', help='Uninstall the packages instead.')
parser.add_argument('--type', choices=('install', 'develop'), help='Alternative for using or not using --no-develop.')
parser.add_argument('-v', '--verbose', action='store_true', help='Print the Pip command that is run.')
parser.add_argument('--extras', help='Comma-separated extras to install.')
parser.add_argument('--extras', default='', help='Comma-separated extras to install.')
args = parser.parse_args()
if args.type and args.uninstall:
@ -28,24 +28,27 @@ if args.type == 'develop':
elif args.type == 'install':
args.no_develop = True
if not args.packages:
install_packages = [x['name'] for x in package_def]
else:
install_packages = []
def _resolve(pkgname, extras=()):
extras = list(filter(bool, extras))
if pkgname in install_packages:
return
package = next((x for x in package_def if x['name'] == pkgname), None)
def _resolve(result, pkg_names, extras=(), visited=None):
if visited is None:
visited = set()
for pkg_name in (x for x in pkg_names if x not in visited):
visited.add(pkg_name)
package = next((x for x in package_def if x['name'] == pkg_name), None)
if package is None:
parser.error('not a package of this monorepo: {}'.format(pkgname))
[_resolve(x) for x in package['requires']]
for extra in extras:
[_resolve(x) for x in package['extra_requires'].get(extra, [])]
if extras:
pkgname += '[' + ','.join(extras) + ']'
install_packages.append(pkgname)
[_resolve(x, (args.extras or '').split(',')) for x in args.packages]
parser.error('not a package of this monorepo: {}'.format(pkg_name))
_resolve(result, package['requires'], extras, visited)
pkg_extras = list(filter(lambda x: x and x in package['extra_requires'], extras))
for extra in pkg_extras:
_resolve(result, package['extra_requires'][extra])
if pkg_extras:
pkg_name += '[' + ','.join(pkg_extras) + ']'
result.append(pkg_name)
install_packages = []
_resolve(install_packages, (args.packages or (x['name'] for x in package_def)), args.extras)
python = os.getenv('PYTHON', 'python')
command = [python, '-m', 'pip', 'uninstall' if args.uninstall else 'install']

Loading…
Cancel
Save