Skip to content

Commit

Permalink
Merge pull request #546 from dciborow/dciborow/install-reqs
Browse files Browse the repository at this point in the history
Add "install-reqs" command to CLI
  • Loading branch information
takluyver committed Nov 5, 2022
2 parents 7b13fb2 + 6cdb29c commit 5b30163
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
9 changes: 9 additions & 0 deletions doc/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ Flit guess.
install all optional dependencies, or a comma-separated list of extras.
Default depends on ``--deps``.

.. option:: --only-deps

Install the dependencies of this package, but not the package itself.

This can be useful for e.g. building a container image, where your own code
is copied or mounted into the container at a later stage.

.. versionadded:: 3.8

.. option:: --user

Do a user-local installation. This is the default if flit is not in a
Expand Down
35 changes: 24 additions & 11 deletions flit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ def add_shared_install_options(parser: argparse.ArgumentParser):
parser.add_argument('--python',
help="Target Python executable, if different from the one running flit"
)

parser.add_argument('--deps', choices=['all', 'production', 'develop', 'none'], default='all',
help="Which set of dependencies to install. If --deps=develop, the extras dev, doc, and test are installed"
)
parser.add_argument('--only-deps', action='store_true',
help="Install only dependencies of this package, and not the package itself"
)
parser.add_argument('--extras', default=(), type=lambda l: l.split(',') if l else (),
help="Install the dependencies of these (comma separated) extras additionally to the ones implied by --deps. "
"--extras=all can be useful in combination with --deps=production, --deps=none precludes using --extras"
)


def main(argv=None):
ap = argparse.ArgumentParser()
Expand Down Expand Up @@ -134,13 +144,6 @@ def main(argv=None):
help="Add .pth file for the module/package to site packages instead of copying it"
)
add_shared_install_options(parser_install)
parser_install.add_argument('--deps', choices=['all', 'production', 'develop', 'none'], default='all',
help="Which set of dependencies to install. If --deps=develop, the extras dev, doc, and test are installed"
)
parser_install.add_argument('--extras', default=(), type=lambda l: l.split(',') if l else (),
help="Install the dependencies of these (comma separated) extras additionally to the ones implied by --deps. "
"--extras=all can be useful in combination with --deps=production, --deps=none precludes using --extras"
)

# flit init --------------------------------------------
parser_init = subparsers.add_parser('init',
Expand Down Expand Up @@ -189,9 +192,19 @@ def gen_setup_py():
from .install import Installer
try:
python = find_python_executable(args.python)
Installer.from_ini_path(args.ini_file, user=args.user, python=python,
symlink=args.symlink, deps=args.deps, extras=args.extras,
pth=args.pth_file).install()
installer = Installer.from_ini_path(
args.ini_file,
user=args.user,
python=python,
symlink=args.symlink,
deps=args.deps,
extras=args.extras,
pth=args.pth_file
)
if args.only_deps:
installer.install_requirements()
else:
installer.install()
except (ConfigError, PythonNotFoundError, common.NoDocstringError, common.NoVersionError) as e:
sys.exit(e.args[0])

Expand Down
15 changes: 9 additions & 6 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from unittest.mock import patch
import pytest

import tomli
try:
import tomllib
except ImportError:
import tomli as tomllib

from flit import init

Expand Down Expand Up @@ -107,7 +110,7 @@ def test_init():
generated = Path(td) / 'pyproject.toml'
assert_isfile(generated)
with generated.open('rb') as f:
data = tomli.load(f)
data = tomllib.load(f)
assert data['project']['authors'][0]['email'] == "test@example.com"
license = Path(td) / 'LICENSE'
assert data['project']['license']['file'] == 'LICENSE'
Expand All @@ -131,7 +134,7 @@ def test_init_homepage_and_license_are_optional():
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
data = tomllib.load(f)
assert not Path(td, 'LICENSE').exists()
assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
Expand All @@ -153,7 +156,7 @@ def test_init_homepage_validator():
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
data = tomllib.load(f)
assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
'name': 'test_module_name',
Expand All @@ -174,7 +177,7 @@ def test_author_email_field_is_optional():
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
data = tomllib.load(f)
assert not Path(td, 'LICENSE').exists()

assert data['project'] == {
Expand Down Expand Up @@ -215,7 +218,7 @@ def test_init_readme_found_yes_choosen():
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
data = tomllib.load(f)

assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
Expand Down

0 comments on commit 5b30163

Please sign in to comment.