Browse Source

rename dev-install plugin to install-script, the default filename is now bin/install and develop install flag must be passed explicitly with -e,--develop. Also removed the --type option from the rendered install script and added a --pip-args option

master
Niklas Rosenstein 6 months ago
parent
commit
cd0f1b6554
Signed by: NiklasRosenstein <rosensteinniklas@gmail.com> GPG Key ID: 06D269B33D25F6C6
4 changed files with 18 additions and 21 deletions
  1. +1
    -1
      package.yaml
  2. +1
    -1
      setup.py
  3. +7
    -5
      src/shore/plugins/install_script.py
  4. +9
    -14
      src/shore/templates/install_script/install

+ 1
- 1
package.yaml View File

@@ -31,7 +31,7 @@ entrypoints:
- shore = shore.__main__:_entry_point
shore.core.plugins:
- core = shore.plugins.core:CorePlugin
- dev-install = shore.plugins.dev_install:DevInstallRenderer
- install-script = shore.plugins.install_script:InstallScriptRenderer
- pypi = shore.plugins.pypi:PypiPublisher
- requirements-file = shore.plugins.requirements_file:RequirementsFileRenderer
- setuptools = shore.plugins.setuptools:SetuptoolsRenderer


+ 1
- 1
setup.py View File

@@ -38,7 +38,7 @@ setuptools.setup(
],
'shore.core.plugins': [
'core = shore.plugins.core:CorePlugin',
'dev-install = shore.plugins.dev_install:DevInstallRenderer',
'install-script = shore.plugins.install_script:InstallScriptRenderer',
'pypi = shore.plugins.pypi:PypiPublisher',
'requirements-file = shore.plugins.requirements_file:RequirementsFileRenderer',
'setuptools = shore.plugins.setuptools:SetuptoolsRenderer',


src/shore/plugins/dev_install.py → src/shore/plugins/install_script.py View File

@@ -36,12 +36,14 @@ def _dirname(package: Package):


@implements(IMonorepoPlugin)
class DevInstallRenderer:
""" Renders a "bin/dev-install" shell script for a monorepo that installs
Pip packages in the order, respecting their inter-dependencies. """
class InstallScriptRenderer:
"""
Renders a self-contained Python script for a monorepo that installs Pip packages
in order, respecting their inter-dependencies.
"""

class Config(Struct):
filename = Field(str, default='bin/dev-install')
filename = Field(str, default='bin/install')

@override
def get_monorepo_files(self, monorepo: Monorepo) -> Iterable[FileToRender]:
@@ -57,7 +59,7 @@ class DevInstallRenderer:
package_def += ']'

def write_script(_current, fp):
template = resource_string('shore', 'templates/dev_install/dev-install').decode('utf8')
template = resource_string('shore', 'templates/install_script/install').decode('utf8')
content = (template
.replace('{{package_def}}', package_def)
.replace('{{generated_file_remark}}', GENERATED_FILE_REMARK))

src/shore/templates/dev_install/dev-install → src/shore/templates/install_script/install View File

@@ -13,23 +13,16 @@ package_def = {{package_def}}

parser = argparse.ArgumentParser()
parser.add_argument('packages', nargs='*')
parser.add_argument('--no-develop', action='store_true', help='Perform a normal install of the packages.')
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('-e', '--develop', action='store_true', help='Perform a normal install of the packages.')
parser.add_argument('-v', '--verbose', action='store_true', help='Print the Pip command that is run.')
parser.add_argument('-q', '--quiet', action='store_true', help='Capture Pip output.')
parser.add_argument('--extras', default='', help='Comma-separated extras to install.')
parser.add_argument('--uninstall', action='store_true', help='Uninstall the packages instead.')
parser.add_argument('--pip-args', nargs='...', help='Additional arguments to pass to Pip.', default=[])
args = parser.parse_args()

if args.type and args.uninstall:
parser.error('conflicting options: --type and --uninstall')
if args.no_develop and args.uninstall:
parser.error('conflicting options: --no-develop and --uninstall')
if args.type == 'develop':
if args.no_develop:
parser.error('conflicting options: --type=develop and --no-develop')
elif args.type == 'install':
args.no_develop = True
if args.develop and args.uninstall:
parser.error('conflicting options: --develop and --uninstall')

def _resolve(result, pkg_names, extras=(), visited=None):
if visited is None:
@@ -55,18 +48,20 @@ _resolve(install_packages, (args.packages or (x['name'] for x in package_def)),
python = os.getenv('PYTHON', 'python')
pip = shlex.split(os.getenv('PYTHON_PIP', '"{0}" -m pip'.format(python)).replace('$PYTHON', python))
command = pip + ['uninstall' if args.uninstall else 'install']
if args.verbose:
command.append('-v')
for pkgname in install_packages:
if not args.no_develop and not args.uninstall:
if args.develop and not args.uninstall:
command.append('-e')
command.append(pkgname if args.uninstall else './' + pkgname)
if args.uninstall:
command.append('-y')
command += args.pip_args

project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

stdout, stderr = None, None
if args.verbose:
command.append('-v')
print('Running command in working directory', project_dir)
print('$', ' '.join(command))
elif args.quiet:

Loading…
Cancel
Save