Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from dephell/improve-bump
Browse files Browse the repository at this point in the history
Improve bump
  • Loading branch information
orsinium committed Apr 29, 2019
2 parents cdbfec4 + 5d83cb9 commit f6fa74c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
26 changes: 19 additions & 7 deletions dephell/commands/project_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,25 @@ def __call__(self) -> bool:

# update version in project metadata
if root is not None and root.version != '0.0.0':
paths.append(Path(self.config['from']['path']))
root.version = new_version
loader.dump(
project=root,
path=self.config['from']['path'],
reqs=[Requirement(dep=dep, lock=loader.lock) for dep in root.dependencies],
)
# we can reproduce metadata only for poetry yet
if self.config['from']['format'] == 'poetry':
paths.append(Path(self.config['from']['path']))
root.version = new_version
loader.dump(
project=root,
path=self.config['from']['path'],
reqs=[Requirement(dep=dep, lock=loader.lock) for dep in root.dependencies],
)
else:
path = Path(self.config['from']['path'])
with path.open('r', encoding='utf8') as stream:
content = stream.read()
new_content = content.replace(str(root.version), str(new_version))
if new_content == content:
self.logger.warning('cannot bump version in metadata file')
else:
with path.open('w', encoding='utf8') as stream:
stream.write(new_content)

# set git tag
project = Path(self.config['project'])
Expand Down
10 changes: 8 additions & 2 deletions dephell/converters/setuppy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# built-in
from collections import defaultdict
from distutils.core import run_setup
from io import StringIO
from io import StringIO, BytesIO
from logging import getLogger
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -53,6 +53,12 @@
"""


def _patched_open(fname, mode='r', *args, **kwargs):
if 'b' in mode:
return BytesIO(fname.encode('utf8'))
return StringIO(fname)


class SetupPyConverter(BaseConverter):
lock = False

Expand Down Expand Up @@ -230,7 +236,7 @@ def _execute(path: Path):
globe = {
'__file__': str(path),
'__name__': '__main__',
'open': lambda fname, *args, **kwargs: StringIO(fname),
'open': _patched_open,
}
with chdir(path.parent):
try:
Expand Down

0 comments on commit f6fa74c

Please sign in to comment.