PK ! poetry/__init__.pyimport os
import sys
_ROOT = os.path.dirname(os.path.realpath(__file__))
_VENDOR = os.path.join(_ROOT, '_vendor')
# Add vendored dependencies to path.
sys.path.insert(0, _VENDOR)
from .__version__ import __version__ # noqa
PK ! {Հ[ [ poetry/__main__.pyimport sys
if __name__ == '__main__':
from .console import main
sys.exit(main())
PK ! ' poetry/__version__.py__version__ = '0.8.3'
PK ! 뚩 poetry/_vendor/.gitignore*
!.gitignore
PK ! F$zL L poetry/config.pyfrom typing import Any
from .locations import CONFIG_DIR
from .utils._compat import Path
from .utils.toml_file import TomlFile
from .utils.toml_file import TOMLFile
class Config:
def __init__(self, file): # type: (TomlFile) -> None
self._file = file
if not self._file.exists():
self._raw_content = {}
self._content = TOMLFile([])
else:
self._raw_content = file.read(raw=True)
self._content = file.read()
@property
def name(self):
return str(self._file.path)
@property
def file(self):
return self._file
@property
def raw_content(self):
return self._raw_content
@property
def content(self):
return self._content
def setting(self, setting_name, default=None): # type: (str) -> Any
"""
Retrieve a setting value.
"""
keys = setting_name.split('.')
config = self._raw_content
for key in keys:
if key not in config:
return default
config = config[key]
return config
def add_property(self, key, value):
keys = key.split('.')
config = self._content
for i, key in enumerate(keys):
if key not in config and i < len(keys) - 1:
config[key] = {}
if i == len(keys) - 1:
config[key] = value
break
config = config[key]
self.dump()
def remove_property(self, key):
keys = key.split('.')
config = self._content
for i, key in enumerate(keys):
if key not in config:
return
if i == len(keys) - 1:
del config[key]
break
config = config[key]
self.dump()
def dump(self):
self._file.write(self._content)
@classmethod
def create(cls, file, base_dir=None): # type: (...) -> Config
if base_dir is None:
base_dir = CONFIG_DIR
file = TomlFile(Path(base_dir) / file)
return cls(file)
PK ! R R poetry/console/__init__.pyfrom .application import Application
def main():
return Application().run()
PK !
\C C poetry/console/application.pyimport os
from cleo import Application as BaseApplication
from cleo.inputs import ArgvInput
from cleo.outputs import ConsoleOutput
from poetry import __version__
from poetry.io.raw_argv_input import RawArgvInput
from .commands import AboutCommand
from .commands import AddCommand
from .commands import BuildCommand
from .commands import CheckCommand
from .commands import ConfigCommand
from .commands import InstallCommand
from .commands import LockCommand
from .commands import NewCommand
from .commands import PublishCommand
from .commands import RemoveCommand
from .commands import RunCommand
from .commands import ScriptCommand
from .commands import SearchCommand
from .commands import ShowCommand
from .commands import UpdateCommand
from .commands import VersionCommand
from .commands.debug import DebugInfoCommand
from .commands.debug import DebugResolveCommand
from .commands.self import SelfUpdateCommand
class Application(BaseApplication):
def __init__(self):
super(Application, self).__init__('Poetry', __version__)
self._poetry = None
self._skip_io_configuration = False
@property
def poetry(self):
from poetry.poetry import Poetry
if self._poetry is not None:
return self._poetry
self._poetry = Poetry.create(os.getcwd())
return self._poetry
def reset_poetry(self): # type: () -> None
self._poetry = None
def run(self, i=None, o=None): # type: (...) -> int
if i is None:
i = ArgvInput()
if o is None:
o = ConsoleOutput()
name = i.get_first_argument()
if name in ['run', 'script']:
self._skip_io_configuration = True
i = RawArgvInput()
return super(Application, self).run(i, o)
def do_run(self, i, o):
name = self.get_command_name(i)
if name not in ['run', 'script']:
return super(Application, self).do_run(i, o)
command = self.find(name)
self._running_command = command
status_code = command.run(i, o)
self._running_command = None
return status_code
def configure_io(self, i, o):
if self._skip_io_configuration:
return
super(Application, self).configure_io(i, o)
def get_default_commands(self): # type: () -> list
commands = super(Application, self).get_default_commands()
commands += [
AboutCommand(),
AddCommand(),
BuildCommand(),
CheckCommand(),
ConfigCommand(),
InstallCommand(),
LockCommand(),
NewCommand(),
PublishCommand(),
RemoveCommand(),
RunCommand(),
ScriptCommand(),
SearchCommand(),
ShowCommand(),
UpdateCommand(),
VersionCommand(),
]
# Debug commands
commands += [
DebugInfoCommand(),
DebugResolveCommand(),
]
# Self commands
commands += [
SelfUpdateCommand(),
]
return commands
PK ! % # poetry/console/commands/__init__.pyfrom .about import AboutCommand
from .add import AddCommand
from .build import BuildCommand
from .check import CheckCommand
from .config import ConfigCommand
from .install import InstallCommand
from .lock import LockCommand
from .new import NewCommand
from .publish import PublishCommand
from .remove import RemoveCommand
from .run import RunCommand
from .script import ScriptCommand
from .search import SearchCommand
from .show import ShowCommand
from .update import UpdateCommand
from .version import VersionCommand
PK ! 0 poetry/console/commands/about.pyfrom .command import Command
class AboutCommand(Command):
"""
Short information about Poetry.
about
"""
def handle(self):
self.line("""Poetry - Package Management for Python
Poetry is a dependency manager tracking local dependencies of your projects and libraries.
See https://github.com/sdispater/poetry> for more information.
""")
PK ! 23 poetry/console/commands/add.pyimport re
from typing import List
from typing import Tuple
from .venv_command import VenvCommand
class AddCommand(VenvCommand):
"""
Add a new dependency to pyproject.toml>.
add
{ name* : Packages to add. }
{--D|dev : Add package as development dependency. }
{--optional : Add as an optional dependency. }
{ --allow-prereleases : Accept prereleases. }
{--dry-run : Outputs the operations but will not execute anything
(implicitly enables --verbose). }
"""
help = """The add command adds required packages to your pyproject.toml> and installs them.
If you do not specify a version constraint, poetry will choose a suitable one based on the available package versions.
"""
def handle(self):
from poetry.installation import Installer
from poetry.semver.version_parser import VersionParser
packages = self.argument('name')
is_dev = self.option('dev')
section = 'dependencies'
if is_dev:
section = 'dev-dependencies'
original_content = self.poetry.file.read()
content = self.poetry.file.read()
poetry_content = content['tool']['poetry']
for name in packages:
for key in poetry_content[section]:
if key.lower() == name.lower():
raise ValueError(
'Package {} is already present'.format(name)
)
requirements = self._determine_requirements(
packages,
allow_prereleases=self.option('allow-prereleases')
)
requirements = self._format_requirements(requirements)
# validate requirements format
parser = VersionParser()
for constraint in requirements.values():
parser.parse_constraints(constraint)
for name, constraint in requirements.items():
if self.option('optional') or self.option('allow-prereleases'):
constraint = {
'version': constraint
}
if self.option('optional'):
constraint = {
'optional': True
}
if self.option('allow-prereleases'):
constraint['allows-prereleases'] = True
poetry_content[section][name] = constraint
# Write new content
self.poetry.file.write(content)
# Cosmetic new line
self.line('')
# Update packages
self.reset_poetry()
installer = Installer(
self.output,
self.venv,
self.poetry.package,
self.poetry.locker,
self.poetry.pool
)
installer.dry_run(self.option('dry-run'))
installer.update(True)
installer.whitelist(requirements)
try:
status = installer.run()
except Exception:
self.poetry.file.write(original_content)
raise
if status != 0 or self.option('dry-run'):
# Revert changes
if not self.option('dry-run'):
self.error(
'\n'
'Addition failed, reverting pyproject.toml '
'to its original content.'
)
self.poetry.file.write(original_content)
return status
def _determine_requirements(self,
requires, # type: List[str]
allow_prereleases=False, # type: bool
): # type: (...) -> List[str]
if not requires:
return []
requires = self._parse_name_version_pairs(requires)
result = []
for requirement in requires:
if 'version' not in requirement:
# determine the best version automatically
name, version = self._find_best_version_for_package(
requirement['name'],
allow_prereleases=allow_prereleases
)
requirement['version'] = version
requirement['name'] = name
self.line(
'Using version {}> for {}>'
.format(version, name)
)
else:
# check that the specified version/constraint exists
# before we proceed
name, _ = self._find_best_version_for_package(
requirement['name'], requirement['version'],
allow_prereleases=allow_prereleases
)
requirement['name'] = name
result.append(
'{} {}'.format(requirement['name'], requirement['version'])
)
return result
def _find_best_version_for_package(self,
name,
required_version=None,
allow_prereleases=False
): # type: (...) -> Tuple[str, str]
from poetry.version.version_selector import VersionSelector
selector = VersionSelector(self.poetry.pool)
package = selector.find_best_candidate(
name, required_version,
allow_prereleases=allow_prereleases
)
if not package:
# TODO: find similar
raise ValueError(
'Could not find a matching version of package {}'.format(name)
)
return (
package.pretty_name,
selector.find_recommended_require_version(package)
)
def _parse_name_version_pairs(self, pairs): # type: (list) -> list
result = []
for i in range(len(pairs)):
pair = re.sub('^([^=: ]+)[=: ](.*)$', '\\1 \\2', pairs[i].strip())
pair = pair.strip()
if ' ' in pair:
name, version = pair.split(' ', 2)
result.append({
'name': name,
'version': version
})
else:
result.append({
'name': pair
})
return result
def _format_requirements(self, requirements): # type: (List[str]) -> dict
requires = {}
requirements = self._parse_name_version_pairs(requirements)
for requirement in requirements:
requires[requirement['name']] = requirement['version']
return requires
PK ! Xغ poetry/console/commands/build.pyfrom .venv_command import VenvCommand
class BuildCommand(VenvCommand):
"""
Builds a package, as a tarball and a wheel by default.
build
{ --f|format= : Limit the format to either wheel or sdist. }
"""
def handle(self):
from poetry.masonry import Builder
fmt = 'all'
if self.option('format'):
fmt = self.option('format')
package = self.poetry.package
self.line(
'Building {}> ({}>)'
.format(package.pretty_name, package.version)
)
builder = Builder(self.poetry, self.venv, self.output)
builder.build(fmt)
PK ! _(F F poetry/console/commands/check.pyfrom .command import Command
class CheckCommand(Command):
"""
Checks the validity of the pyproject.toml file.
check
"""
def handle(self):
# Load poetry and display errors, if any
self.poetry.check(self.poetry.local_config, strict=True)
self.info('All set!')
PK ! cO " poetry/console/commands/command.pyfrom cleo import Command as BaseCommand
from ..styles.poetry import PoetryStyle
class Command(BaseCommand):
@property
def poetry(self):
return self.get_application().poetry
def reset_poetry(self): # type: () -> None
self.get_application().reset_poetry()
def run(self, i, o): # type: () -> int
"""
Initialize command.
"""
self.input = i
self.output = PoetryStyle(i, o)
return super(BaseCommand, self).run(i, o)
PK ! W} ! poetry/console/commands/config.pyimport json
import re
from .command import Command
TEMPLATE = """[settings]
[repositories]
"""
AUTH_TEMPLATE = """[http-basic]
"""
class ConfigCommand(Command):
"""
Sets/Gets config options.
config
{ key : Setting key. }
{ value?* : Setting value. }
{ --list : List configuration settings }
{ --unset : Unset configuration setting }
"""
help = """This command allows you to edit the poetry config settings and repositories..
To add a repository:
poetry repositories.foo https://bar.com/simple/
To remove a repository (repo is a short alias for repositories):
poetry --unset repo.foo
"""
def __init__(self):
from poetry.config import Config
super(ConfigCommand, self).__init__()
self._config = Config.create('config.toml')
self._auth_config = Config.create('auth.toml')
def initialize(self, i, o):
super(ConfigCommand, self).initialize(i, o)
# Create config file if it does not exist
if not self._config.file.exists():
self._config.file.parent.mkdir(parents=True, exist_ok=True)
with self._config.file.open() as f:
f.write(TEMPLATE)
if not self._auth_config.file.exists():
self._auth_config.file.parent.mkdir(parents=True, exist_ok=True)
with self._auth_config.file.open() as f:
f.write(AUTH_TEMPLATE)
def handle(self):
if self.option('list'):
self._list_configuration(self._config.raw_content)
return 0
setting_key = self.argument('key')
if not setting_key:
return 0
if self.argument('value') and self.option('unset'):
raise RuntimeError('You can not combine a setting value with --unset')
# show the value if no value is provided
if not self.argument('value') and not self.option('unset'):
m = re.match('^repos?(?:itories)?(?:\.(.+))?', self.argument('key'))
if m:
if not m.group(1):
value = {}
if self._config.setting('repositories') is not None:
value = self._config.setting('repositories')
else:
repo = self._config.setting(
'repositories.{}'.format(m.group(1))
)
if repo is None:
raise ValueError(
'There is no {} repository defined'
.format(m.group(1))
)
value = repo
self.line(str(value))
return 0
values = self.argument('value')
boolean_validator = lambda val: val in {'true', 'false', '1', '0'}
boolean_normalizer = lambda val: True if val in ['true', '1'] else False
unique_config_values = {
'settings.virtualenvs.create': (boolean_validator, boolean_normalizer),
'settings.pypi.fallback': (boolean_validator, boolean_normalizer),
}
if setting_key in unique_config_values:
if self.option('unset'):
return self._remove_single_value(setting_key)
return self._handle_single_value(
setting_key,
unique_config_values[setting_key],
values
)
# handle repositories
m = re.match('^repos?(?:itories)?(?:\.(.+))?', self.argument('key'))
if m:
if not m.group(1):
raise ValueError('You cannot remove the [repositories] section')
if self.option('unset'):
repo = self._config.setting(
'repositories.{}'.format(m.group(1))
)
if repo is None:
raise ValueError(
'There is no {} repository defined'.format(m.group(1))
)
self._config.remove_property(
'repositories.{}'.format(m.group(1))
)
return 0
if len(values) == 1:
url = values[0]
self._config.add_property(
'repositories.{}.url'.format(m.group(1)), url
)
return 0
raise ValueError(
'You must pass the url. '
'Example: poetry config repositories.foo https://bar.com'
)
# handle auth
m = re.match('^(http-basic)\.(.+)', self.argument('key'))
if m:
if self.option('unset'):
if not self._auth_config.setting('{}.{}'.format(m.group(1), m.group(2))):
raise ValueError(
'There is no {} {} defined'.format(
m.group(2), m.group(1)
)
)
self._auth_config.remove_property(
'{}.{}'.format(m.group(1), m.group(2))
)
return 0
if m.group(1) == 'http-basic':
if len(values) == 1:
username = values[0]
# Only username, so we prompt for password
password = self.secret('Password:')
elif len(values) != 2:
raise ValueError(
'Expected one or two arguments '
'(username, password), got {}'.format(len(values))
)
else:
username = values[0]
password = values[1]
self._auth_config.add_property(
'{}.{}'.format(m.group(1), m.group(2)),
{
'username': username,
'password': password
}
)
return 0
raise ValueError(
'Setting {} does not exist'.format(self.argument("key"))
)
def _handle_single_value(self, key, callbacks, values):
validator, normalizer = callbacks
if len(values) > 1:
raise RuntimeError('You can only pass one value.')
value = values[0]
if not validator(value):
raise RuntimeError(
'"{}" is an invalid value for {}'.format(value, key)
)
self._config.add_property(key, normalizer(value))
return 0
def _remove_single_value(self, key):
self._config.remove_property(key)
return 0
def _list_configuration(self, contents, k=None):
orig_k = k
for key, value in contents.items():
if k is None and key not in ['config', 'repositories', 'settings']:
continue
if isinstance(value, dict) or key == 'repositories' and k is None:
if k is None:
k = ''
k += re.sub('^config\.', '', key + '.')
self._list_configuration(value, k=k)
k = orig_k
continue
if isinstance(value, list):
value = [
json.dumps(val) if isinstance(val, list) else val
for val in value
]
value = '[{}]'.format(", ".join(value))
value = json.dumps(value)
self.line(
'[{}] {}'.format(
(k or "") + key, value
)
)
PK ! L L ) poetry/console/commands/debug/__init__.pyfrom .info import DebugInfoCommand
from .resolve import DebugResolveCommand
PK ! zV % poetry/console/commands/debug/info.pyimport os
import sys
from ..venv_command import VenvCommand
class DebugInfoCommand(VenvCommand):
"""
Shows debug information.
debug:info
"""
def handle(self):
poetry = self.poetry
package = poetry.package
venv = self.venv
poetry_python_version = '.'.join(str(s) for s in sys.version_info[:3])
self.output.title('Poetry')
self.output.listing([
'Version: {}>'.format(poetry.VERSION),
'Python: {}>'.format(poetry_python_version)
])
self.line('')
venv_python_version = '.'.join(str(s) for s in venv.version_info[:3])
self.output.title('Virtualenv')
self.output.listing([
'Python: {}>'.format(
venv_python_version
),
'Implementation: {}>'.format(
venv.python_implementation
),
'Path: {}>'.format(
venv.venv if venv.is_venv() else 'NA'
)
])
self.line('')
self.output.title('System')
self.output.listing([
'Platform: {}>'.format(sys.platform),
'OS: {}>'.format(os.name),
])
self.line('')
PK ! >8 ( poetry/console/commands/debug/resolve.pyimport re
from typing import List
from ..command import Command
class DebugResolveCommand(Command):
"""
Debugs dependency resolution.
debug:resolve
{ package?* : packages to resolve. }
"""
def handle(self):
from poetry.packages import Dependency
from poetry.puzzle import Solver
from poetry.repositories.repository import Repository
from poetry.semver.version_parser import VersionParser
packages = self.argument('package')
if not packages:
package = self.poetry.package
dependencies = package.requires + package.dev_requires
else:
requirements = self._determine_requirements(packages)
requirements = self._format_requirements(requirements)
# validate requirements format
parser = VersionParser()
for constraint in requirements.values():
parser.parse_constraints(constraint)
dependencies = []
for name, constraint in requirements.items():
dependencies.append(
Dependency(name, constraint)
)
solver = Solver(
self.poetry.package,
self.poetry.pool,
Repository(),
Repository(),
self.output
)
ops = solver.solve(dependencies)
self.line('')
self.line('Resolution results:')
self.line('')
for op in ops:
package = op.package
self.line(
' - {} ({})'
.format(
package.name, package.version
)
)
def _determine_requirements(self, requires): # type: (List[str]) -> List[str]
if not requires:
return []
requires = self._parse_name_version_pairs(requires)
result = []
for requirement in requires:
if 'version' not in requirement:
requirement['version'] = '*'
result.append(
'{} {}'.format(requirement['name'], requirement['version'])
)
return result
def _parse_name_version_pairs(self, pairs): # type: (list) -> list
result = []
for i in range(len(pairs)):
pair = re.sub('^([^=: ]+)[=: ](.*)$', '\\1 \\2', pairs[i].strip())
pair = pair.strip()
if ' ' in pair:
name, version = pair.split(' ', 2)
result.append({
'name': name,
'version': version
})
else:
result.append({
'name': pair
})
return result
def _format_requirements(self, requirements): # type: (List[str]) -> dict
requires = {}
requirements = self._parse_name_version_pairs(requirements)
for requirement in requirements:
requires[requirement['name']] = requirement['version']
return requires
PK ! " poetry/console/commands/install.pyfrom .venv_command import VenvCommand
class InstallCommand(VenvCommand):
"""
Installs the project dependencies.
install
{ --no-dev : Do not install dev dependencies. }
{ --dry-run : Outputs the operations but will not execute anything
(implicitly enables --verbose). }
{ --E|extras=* : Extra sets of dependencies to install
(multiple values allowed). }
"""
help = """The install command reads the pyproject.toml> file from
the current directory, processes it, and downloads and installs all the
libraries and dependencies outlined in that file. If the file does not
exist it will look for pyproject.toml> and do the same.
poetry install
"""
def handle(self):
from poetry.installation import Installer
installer = Installer(
self.output,
self.venv,
self.poetry.package,
self.poetry.locker,
self.poetry.pool
)
installer.extras(self.option('extras'))
installer.dev_mode(not self.option('no-dev'))
installer.dry_run(self.option('dry-run'))
installer.verbose(self.option('verbose'))
return installer.run()
PK ! @ poetry/console/commands/lock.pyfrom .venv_command import VenvCommand
class LockCommand(VenvCommand):
"""
Locks the project dependencies.
lock
"""
help = """The lock command reads the pyproject.toml> file from
the current directory, processes it, and locks the depdencies in the pyproject.lock> file.
poetry lock
"""
def handle(self):
from poetry.installation import Installer
installer = Installer(
self.output,
self.venv,
self.poetry.package,
self.poetry.locker,
self.poetry.pool
)
installer.update(True)
installer.execute_operations(False)
return installer.run()
PK ! е?h h poetry/console/commands/new.pyfrom poetry.utils._compat import Path
from .command import Command
class NewCommand(Command):
"""
Creates a new Python project at
new
{ path : The path to create the project at. }
{ --name : Set the resulting package name. }
"""
def handle(self):
from poetry.layouts import layout
layout_ = layout('standard')
path = Path.cwd() / Path(self.argument('path'))
name = self.option('name')
if not name:
name = path.name
if path.exists():
if list(path.glob('*')):
# Directory is not empty. Aborting.
raise RuntimeError(
'Destination {}> '
'exists and is not empty'.format(
path
)
)
readme_format = 'rst'
layout_ = layout_(name, '0.1.0', readme_format=readme_format)
layout_.create(path)
self.line(
'Created package {}> in {}>'
.format(name, path.relative_to(Path.cwd()))
)
PK ! " poetry/console/commands/publish.pyfrom .command import Command
class PublishCommand(Command):
"""
Publishes a package to a remote repository.
publish
{ --r|repository= : The repository to publish the package to. }
{ --no-build : Do not build the package before publishing. }
"""
help = """The publish command builds and uploads the package to a remote repository.
By default, it will upload to PyPI but if you pass the --repository option it will
upload to it instead.
The --repository option should match the name of a configured repository using
the config command.
"""
def handle(self):
from poetry.masonry.publishing.publisher import Publisher
# Building package first, unless told otherwise
if not self.option('no-build'):
self.call('build')
self.line('')
publisher = Publisher(self.poetry, self.output)
publisher.publish(self.option('repository'))
PK ! o ! poetry/console/commands/remove.pyfrom .venv_command import VenvCommand
class RemoveCommand(VenvCommand):
"""
Removes a package from the project dependencies.
remove
{ packages* : Packages that should be removed. }
{--D|dev : Removes a package from the development dependencies. }
{--dry-run : Outputs the operations but will not execute anything
(implicitly enables --verbose). }
"""
help = """The remove command removes a package from the current
list of installed packages
poetry remove"""
def handle(self):
from poetry.installation import Installer
packages = self.argument('packages')
is_dev = self.option('dev')
original_content = self.poetry.file.read()
content = self.poetry.file.read()
poetry_content = content['tool']['poetry']
section = 'dependencies'
if is_dev:
section = 'dev-dependencies'
# Deleting entries
requirements = {}
for name in packages:
found = False
for key in poetry_content[section]:
if key.lower() == name.lower():
found = True
requirements[name] = poetry_content[section][name]
break
if not found:
raise ValueError('Package {} not found'.format(name))
for key in requirements:
del poetry_content[section][key]
# Write the new content back
self.poetry.file.write(content)
# Update packages
self.reset_poetry()
installer = Installer(
self.output,
self.venv,
self.poetry.package,
self.poetry.locker,
self.poetry.pool
)
installer.dry_run(self.option('dry-run'))
installer.update(True)
installer.whitelist(requirements)
try:
status = installer.run()
except Exception:
self.poetry.file.write(original_content)
raise
if status != 0 or self.option('dry-run'):
# Revert changes
if not self.option('dry-run'):
self.error(
'\n'
'Removal failed, reverting pyproject.toml '
'to its original content.'
)
self.poetry.file.write(original_content)
return status
PK ! X@ poetry/console/commands/run.pyfrom .venv_command import VenvCommand
class RunCommand(VenvCommand):
"""
Runs a command in the appropriate environment.
run
{ args* : The command and arguments/options to run. }
"""
def handle(self):
args = self.argument('args')
venv = self.venv
return venv.execute(*args)
def merge_application_definition(self, merge_args=True):
if self._application is None \
or (self._application_definition_merged
and (self._application_definition_merged_with_args or not merge_args)):
return
if merge_args:
current_arguments = self._definition.get_arguments()
self._definition.set_arguments(self._application.get_definition().get_arguments())
self._definition.add_arguments(current_arguments)
self._application_definition_merged = True
if merge_args:
self._application_definition_merged_with_args = True
PK ! l. ! poetry/console/commands/script.pyimport sys
from .venv_command import VenvCommand
class ScriptCommand(VenvCommand):
"""
Executes a script defined in pyproject.toml
script
{ script-name : The name of the script to execute }
{ args?* : The command and arguments/options to pass to the script. }
"""
def handle(self):
script = self.argument('script-name')
argv = [script] + self.argument('args')
scripts = self.poetry.local_config.get('scripts')
if not scripts:
raise RuntimeError('No scripts defined in pyproject.toml')
if script not in scripts:
raise ValueError('Script {} is not defined'.format(script))
module, callable_ = scripts[script].split(':')
cmd = ['python', '-c']
cmd += [
'"import sys; '
'from importlib import import_module; '
'sys.argv = {!r}; '
'import_module(\'{}\').{}()"'.format(
argv, module, callable_
)
]
self.venv.run(*cmd, shell=True, call=True)
def merge_application_definition(self, merge_args=True):
if self._application is None \
or (self._application_definition_merged
and (self._application_definition_merged_with_args or not merge_args)):
return
if merge_args:
current_arguments = self._definition.get_arguments()
self._definition.set_arguments(self._application.get_definition().get_arguments())
self._definition.add_arguments(current_arguments)
self._application_definition_merged = True
if merge_args:
self._application_definition_merged_with_args = True
PK ! \J ! poetry/console/commands/search.pyfrom .command import Command
class SearchCommand(Command):
"""
Searches for packages on remote repositories.
search
{ tokens* : The tokens to search for. }
{ --N|only-name : Search only in name. }
"""
def handle(self):
from poetry.repositories.pypi_repository import PyPiRepository
flags = PyPiRepository.SEARCH_FULLTEXT
if self.option('only-name'):
flags = PyPiRepository.SEARCH_FULLTEXT
results = PyPiRepository().search(self.argument('tokens'), flags)
for result in results:
self.line('')
name = '{}>'.format(
result.name
)
name += ' ({}>)'.format(result.version)
self.line(name)
if result.description:
self.line(
' {}'.format(result.description)
)
PK ! Z&