Skip to content

Commit

Permalink
Add compatibility with Python 3.4 and 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Mar 29, 2018
1 parent ac73c53 commit 135ef5d
Show file tree
Hide file tree
Showing 47 changed files with 423 additions and 242 deletions.
Empty file added .coveragerc
Empty file.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

### Added

- Added compatibility with Python 3.4 and 3.5.


### Changed

- Improved dependency resolution to avoid unnecessary operations.
Expand Down
13 changes: 9 additions & 4 deletions poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def handle(self):
for name in packages:
for key in poetry_content[section]:
if key.lower() == name.lower():
raise ValueError(f'Package {name} is already present')
raise ValueError(
'Package {} is already present'.format(name)
)

requirements = self._determine_requirements(packages)
requirements = self._format_requirements(requirements)
Expand Down Expand Up @@ -118,7 +120,8 @@ def _determine_requirements(self, requires: List[str]) -> List[str]:
requirement['name'] = name

self.line(
f'Using version <info>{version}</> for <info>{name}</>'
'Using version <info>{}</> for <info>{}</>'
.format(version, name)
)
else:
# check that the specified version/constraint exists
Expand All @@ -129,7 +132,9 @@ def _determine_requirements(self, requires: List[str]) -> List[str]:

requirement['name'] = name

result.append(f'{requirement["name"]} {requirement["version"]}')
result.append(
'{} {}'.format(requirement['name'], requirement['version'])
)

return result

Expand All @@ -143,7 +148,7 @@ def _find_best_version_for_package(self,
if not package:
# TODO: find similar
raise ValueError(
f'Could not find a matching version of package {name}'
'Could not find a matching version of package {}'.format(name)
)

return (
Expand Down
6 changes: 4 additions & 2 deletions poetry/console/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ def handle(self):
fmt = self.option('format')

package = self.poetry.package
self.line(f'Building <info>{package.pretty_name}</> '
f'(<comment>{package.version}</>)')
self.line(
'Building <info>{}</> (<comment>{}</>)'
.format(package.pretty_name, package.version)
)

builder = Builder(self.poetry, self.venv, self.output)
builder.build(fmt)
1 change: 0 additions & 1 deletion poetry/console/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from cleo import Command as BaseCommand
from cleo.inputs import ListInput

from poetry.poetry import Poetry

Expand Down
56 changes: 40 additions & 16 deletions poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ def handle(self):
if self._config.setting('repositories') is not None:
value = self._config.setting('repositories')
else:
repo = self._config.setting(f'repositories.{m.group(1)}')
repo = self._config.setting(
'repositories.{}'.format(m.group(1))
)
if repo is None:
raise ValueError(
f'There is no {m.group(1)} repository defined'
'There is no {} repository defined'
.format(m.group(1))
)

value = repo
Expand Down Expand Up @@ -115,18 +118,26 @@ def handle(self):
raise ValueError('You cannot remove the [repositories] section')

if self.option('unset'):
repo = self._config.setting(f'repositories.{m.group(1)}')
repo = self._config.setting(
'repositories.{}'.format(m.group(1))
)
if repo is None:
raise ValueError(f'There is no {m.group(1)} repository defined')
raise ValueError(
'There is no {} repository defined'.format(m.group(1))
)

self._config.remove_property(f'repositories.{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(f'repositories.{m.group(1)}.url', url)
self._config.add_property(
'repositories.{}.url'.format(m.group(1)), url
)

return 0

Expand All @@ -139,12 +150,16 @@ def handle(self):
m = re.match('^(http-basic)\.(.+)', self.argument('key'))
if m:
if self.option('unset'):
if not self._auth_config.setting(f'{m.group(1)}.{m.group(2)}'):
if not self._auth_config.setting('{}.{}'.format(m.group(1), m.group(2))):
raise ValueError(
f'There is no {m.group(2)} {m.group(1)} defined'
'There is no {} {} defined'.format(
m.group(2), m.group(1)
)
)

self._auth_config.remove_property(f'{m.group(1)}.{m.group(2)}')
self._auth_config.remove_property(
'{}.{}'.format(m.group(1), m.group(2))
)

return 0

Expand All @@ -154,22 +169,27 @@ def handle(self):
# Only username, so we prompt for password
password = self.secret('Password:')
elif len(values) != 2:
raise ValueError(f'Expected one or two arguments '
f'(username, password), got {len(values)}')
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(
f'{m.group(1)}.{m.group(2)}', {
'{}.{}'.format(m.group(1), m.group(2)),
{
'username': username,
'password': password
}
)

return 0

raise ValueError(f'Setting {self.argument("key")} does not exist')
raise ValueError(
'Setting {} does not exist'.format(self.argument("key"))
)

def _handle_single_value(self, key, callbacks, values):
validator, normalizer = callbacks
Expand All @@ -180,7 +200,7 @@ def _handle_single_value(self, key, callbacks, values):
value = values[0]
if not validator(value):
raise RuntimeError(
f'"{value}" is an invalid value for {key}'
'"{}" is an invalid value for {}'.format(value, key)
)

self._config.add_property(key, normalizer(value))
Expand Down Expand Up @@ -215,8 +235,12 @@ def _list_configuration(self, contents, k=None):
for val in value
]

value = f'[{", ".join(value)}]'
value = '[{}]'.format(", ".join(value))

value = json.dumps(value)

self.line(f'[<comment>{(k or "") + key}</comment>] <info>{value}</info>')
self.line(
'[<comment>{}</comment>] <info>{}</info>'.format(
(k or "") + key, value
)
)
12 changes: 9 additions & 3 deletions poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def handle(self):

for op in ops:
package = op.package
self.line(f' - <info>{package.name}</info> '
f'(<comment>{package.version}</comment>)')
self.line(
' - <info>{}</info> (<comment>{}</comment>)'
.format(
package.name, package.version
)
)

def _determine_requirements(self, requires: List[str]) -> List[str]:
if not requires:
Expand All @@ -68,7 +72,9 @@ def _determine_requirements(self, requires: List[str]) -> List[str]:
if 'version' not in requirement:
requirement['version'] = '*'

result.append(f'{requirement["name"]} {requirement["version"]}')
result.append(
'{} {}'.format(requirement['name'], requirement['version'])
)

return result

Expand Down
2 changes: 1 addition & 1 deletion poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle(self):
break

if not found:
raise ValueError(f'Package {name} not found')
raise ValueError('Package {} not found'.format(name))

for key in requirements:
del poetry_content[section][key]
Expand Down
51 changes: 35 additions & 16 deletions poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ def handle(self):
break

if not pkg:
raise ValueError(f'Package {package} not found')
raise ValueError('Package {} not found'.format(package))

if self.option('tree'):
self.display_package_tree(pkg, installed_repo)

return 0

rows = [
['<info>name</>', f' : <fg=cyan>{pkg.pretty_name}</>'],
['<info>version</>', f' : <comment>{pkg.pretty_version}</>'],
['<info>description</>', f' : {pkg.description}'],
['<info>name</>', ' : <fg=cyan>{}</>'.format(pkg.pretty_name)],
['<info>version</>', ' : <comment>{}</>'.format(pkg.pretty_version)],
['<info>description</>', ' : {}'.format(pkg.description)],
]

table.add_rows(rows)
Expand All @@ -82,8 +82,12 @@ def handle(self):
self.line('')
self.line('<info>dependencies</info>')
for dependency in pkg.requires:
self.line(f' - {dependency.pretty_name} '
f'<comment>{dependency.pretty_constraint}</>')
self.line(
' - {} <comment>{}</>'.format(
dependency.pretty_name,
dependency.pretty_constraint
)
)

return 0

Expand All @@ -109,9 +113,11 @@ def handle(self):
write_description = name_length + version_length + latest_length + 24 <= width

for locked in locked_packages:
line = f'<fg=cyan>{locked.pretty_name:{name_length}}</>'
line = '<fg=cyan>{:{}}</>'.format(locked.pretty_name, name_length)
if write_version:
line += f' {locked.full_pretty_version:{version_length}}'
line += ' {:{}}'.format(
locked.full_pretty_version, version_length
)
if show_latest and write_latest:
latest = latest_packages[locked.pretty_name]

Expand All @@ -122,7 +128,9 @@ def handle(self):
elif update_status == 'update-possible':
color = 'yellow'

line += f' <fg={color}>{latest.version:{latest_length}}</>'
line += ' <fg={}>{:{}}</>'.format(
color, latest.version, latest_length
)
if self.option('outdated') and update_status == 'up-to-date':
continue

Expand All @@ -140,8 +148,8 @@ def handle(self):
self.line(line)

def display_package_tree(self, package, installed_repo):
self.write(f'<info>{package.pretty_name}</info>')
self.line(f' {package.pretty_version} {package.description}')
self.write('<info>{}</info>'.format(package.prett_name))
self.line(' {} {}'.format(package.pretty_version, package.description))

dependencies = package.requires
dependencies = sorted(dependencies, key=lambda x: x.name)
Expand All @@ -155,8 +163,12 @@ def display_package_tree(self, package, installed_repo):

level = 1
color = self.colors[level]
info = f'{tree_bar}── <{color}>{dependency.name}</{color}> ' \
f'{dependency.pretty_constraint}'
info = '{tree_bar}── <{color}>{name}</{color}> {constraint}'.format(
tree_bar=tree_bar,
color=color,
name=dependency.name,
constraint=dependency.pretty_constraint
)
self._write_tree_line(info)

tree_bar = tree_bar.replace('└', ' ')
Expand Down Expand Up @@ -196,8 +208,13 @@ def _display_tree(self,
if dependency.name in current_tree:
circular_warn = '(circular dependency aborted here)'

info = f'{tree_bar}── <{color}>{dependency.name}</{color}> ' \
f'{dependency.pretty_constraint} {circular_warn}'
info = '{tree_bar}── <{color}>{name}</{color}> {constraint} {warn}'.format(
tree_bar=tree_bar,
color=color,
name=dependency.name,
constraint=dependency.pretty_constraint,
warn=circular_warn
)
self._write_tree_line(info)

tree_bar = tree_bar.replace('└', ' ')
Expand Down Expand Up @@ -231,7 +248,9 @@ def find_latest_package(self, package):
name = package.name
selector = VersionSelector(self.poetry.pool)

return selector.find_best_candidate(name, f'>={package.version}')
return selector.find_best_candidate(
name, '>={}'.format(package.version)
)

def get_update_status(self, latest, package):
if latest.full_pretty_version == package.full_pretty_version:
Expand Down
4 changes: 3 additions & 1 deletion poetry/console/commands/venv_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def initialize(self, i, o):
self._venv = Venv.create(o, self.poetry.package.name)

if self._venv.is_venv() and o.is_verbose():
o.writeln(f'Using virtualenv: <comment>{self._venv.venv}</>')
o.writeln(
'Using virtualenv: <comment>{}</>'.format(self._venv.venv)
)

@property
def venv(self):
Expand Down
Loading

0 comments on commit 135ef5d

Please sign in to comment.