Skip to content

Commit

Permalink
s/app_name/module_name/g
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Nov 15, 2013
1 parent b5e02d6 commit ef055e0
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 61 deletions.
12 changes: 6 additions & 6 deletions changes/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
log = logging.getLogger(__name__)


def extract_attribute(app_name, attribute_name):
def extract_attribute(module_name, attribute_name):
"""Extract metatdata property from a module"""
with open('%s/__init__.py' % app_name) as input_file:
with open('%s/__init__.py' % module_name) as input_file:
for line in input_file:
if line.startswith(attribute_name):
return ast.literal_eval(line.split('=')[1].strip())


def replace_attribute(app_name, attribute_name, new_value, dry_run=True):
init_file = '%s/__init__.py' % app_name
def replace_attribute(module_name, attribute_name, new_value, dry_run=True):
init_file = '%s/__init__.py' % module_name
_, tmp_file = tempfile.mkstemp()

with open(init_file) as input_file:
Expand All @@ -35,8 +35,8 @@ def replace_attribute(app_name, attribute_name, new_value, dry_run=True):
log.debug(sh.diff(tmp_file, init_file, _ok_code=1))


def has_attribute(app_name, attribute_name):
init_file = '%s/__init__.py' % app_name
def has_attribute(module_name, attribute_name):
init_file = '%s/__init__.py' % module_name
return any(
[attribute_name in init_line for
init_line in open(init_file).readlines()]
Expand Down
14 changes: 7 additions & 7 deletions changes/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
log = logging.getLogger(__name__)


def write_new_changelog(app_name, filename, content_lines, dry_run=True):
def write_new_changelog(module_name, filename, content_lines, dry_run=True):
heading_and_newline = (
'# [Changelog](%s/releases)\n' %
attributes.extract_attribute(app_name, '__url__')
attributes.extract_attribute(module_name, '__url__')
)

with open(filename, 'r+') as f:
Expand Down Expand Up @@ -56,19 +56,19 @@ def replace_sha_with_commit_link(git_log_content):


def changelog():
app_name, dry_run, new_version = config.common_arguments()
module_name, dry_run, new_version = config.common_arguments()

changelog_content = [
'\n## [%s](%s/compare/%s...%s)\n\n' % (
new_version, attributes.extract_attribute(app_name, '__url__'),
version.current_version(app_name), new_version,
new_version, attributes.extract_attribute(module_name, '__url__'),
version.current_version(module_name), new_version,
)
]

git_log_content = sh.git.log(
'--oneline',
'--no-merges',
'%s..master' % version.current_version(app_name),
'%s..master' % version.current_version(module_name),
_tty_out=False
).split('\n')
log.debug('content: %s' % git_log_content)
Expand All @@ -94,7 +94,7 @@ def changelog():
]

write_new_changelog(
app_name,
module_name,
config.CHANGELOG,
changelog_content,
dry_run=dry_run
Expand Down
24 changes: 12 additions & 12 deletions changes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
changes.
Usage:
changes [options] <app_name> changelog
changes [options] <app_name> release
changes [options] <app_name> bump_version
changes [options] <app_name> run_tests
changes [options] <app_name> install
changes [options] <app_name> upload
changes [options] <app_name> pypi
changes [options] <app_name> tag
changes [options] <module_name> changelog
changes [options] <module_name> release
changes [options] <module_name> bump_version
changes [options] <module_name> run_tests
changes [options] <module_name> install
changes [options] <module_name> upload
changes [options] <module_name> pypi
changes [options] <module_name> tag
changes -h | --help
Expand Down Expand Up @@ -96,17 +96,17 @@ def main():
if arguments['--new-version']:
arguments['new_version'] = arguments['--new-version']

app_name = config.arguments['<app_name>']
module_name = config.arguments['<module_name>']

if not probe.probe_project(app_name):
if not probe.probe_project(module_name):
raise Exception('Project does not meet `changes` requirements')

for command in commands:
if arguments[command]:
if command not in suppress_version_prompt_for:
arguments['new_version'] = version.get_new_version(
app_name,
version.current_version(app_name),
module_name,
version.current_version(module_name),
arguments.get('--noinput', False),
**util.extract_arguments(arguments, version_arguments)
)
Expand Down
6 changes: 3 additions & 3 deletions changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ def common_arguments():
"""
Return common arguments
:return: tuple of <app_name>, --dry-run, new_version
:return: tuple of <module_name>, --dry-run, new_version
"""

app_name = arguments['<app_name>']
module_name = arguments['<module_name>']

version_prefix = arguments.get('--version-prefix')
new_version = arguments['new_version']

common_arguments = (
app_name,
module_name,
arguments['--dry-run'],
version_prefix + new_version if version_prefix else new_version,
)
Expand Down
31 changes: 17 additions & 14 deletions changes/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,29 @@ def make_virtualenv():


def install():
app_name, dry_run, new_version = config.common_arguments()

module_name, dry_run, new_version = config.common_arguments()
result = shell.handle_dry_run(sh.python, ('setup.py', 'clean', 'sdist'))
if result:
tmp_dir = make_virtualenv()
package_name = config.arguments.get('--package-name') or module_name
try:
virtualenv.install_sdist(
config.arguments['<app_name>'],
'dist/%s-%s.tar.gz' % (module_name, new_version),
config.arguments['<module_name>'],
'dist/%s-%s.tar.gz' % (package_name, new_version),
'%s/bin/python' % tmp_dir
)
log.info('Successfully installed %s sdist', app_name)
log.info('Successfully installed %s sdist', module_name)
if verification.run_test_command():
log.info('Successfully ran test command: %s',
config.arguments['--test-command'])
except:
raise Exception('Error installing %s sdist', app_name)
raise Exception('Error installing %s sdist', module_name)

path(tmp_dir).rmtree(path(tmp_dir))


def upload():
app_name, dry_run, new_version = config.common_arguments()
module_name, dry_run, new_version = config.common_arguments()
pypi = config.arguments['--pypi']

upload_args = 'setup.py clean sdist upload'.split(' ')
Expand All @@ -51,14 +50,14 @@ def upload():
if not upload_result:
raise Exception('Error uploading')
else:
log.info('Succesfully uploaded %s %s', app_name, new_version)
log.info('Succesfully uploaded %s %s', module_name, new_version)


def pypi():
app_name, dry_run, _ = config.common_arguments()
module_name, dry_run, _ = config.common_arguments()

tmp_dir = make_virtualenv()
install_cmd = '%s/bin/pip install %s' % (tmp_dir, app_name)
install_cmd = '%s/bin/pip install %s' % (tmp_dir, module_name)

package_index = 'pypi'
pypi = config.arguments['--pypi']
Expand All @@ -70,14 +69,18 @@ def pypi():
result = shell.execute(install_cmd, dry_run=dry_run)
if result:
log.info('Successfully installed %s from %s',
app_name, package_index)
module_name, package_index)
else:
log.error('Failed to install %s from %s',
app_name, package_index)
module_name, package_index)

verification.run_test_command()
except:
log.exception('error installing %s from %s', app_name, package_index)
raise Exception('Error installing %s from %s', app_name, package_index)
log.exception(
'error installing %s from %s', module_name, package_index
)
raise Exception(
'Error installing %s from %s', module_name, package_index
)

path(tmp_dir).rmtree(path(tmp_dir))
10 changes: 5 additions & 5 deletions changes/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def has_requirement(dependency, requirements_contents):
)


def probe_project(app_name):
def probe_project(module_name):
"""
Check if the project meets `changes` requirements
"""
Expand All @@ -37,12 +37,12 @@ def probe_project(app_name):
has_changelog = exists('CHANGELOG.md')
log.info('CHANGELOG.md? %s', has_changelog)

# `<app_name>/__init__.py` with `__version__` and `__url__`
init_path = '%s/__init__.py' % app_name
# `<module_name>/__init__.py` with `__version__` and `__url__`
init_path = '%s/__init__.py' % module_name
has_metadata = (
exists(init_path) and
attributes.has_attribute(app_name, '__version__') and
attributes.has_attribute(app_name, '__url__')
attributes.has_attribute(module_name, '__version__') and
attributes.has_attribute(module_name, '__url__')
)
log.info('Has module metadata? %s', has_metadata)

Expand Down
4 changes: 2 additions & 2 deletions changes/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


def commit_version_change():
app_name, dry_run, new_version = config.common_arguments()
module_name, dry_run, new_version = config.common_arguments()

commit_result = shell.handle_dry_run(
sh.git.commit,
('-m', new_version, '%s/__init__.py' % app_name, config.CHANGELOG)
('-m', new_version, '%s/__init__.py' % module_name, config.CHANGELOG)
)

if commit_result:
Expand Down
12 changes: 6 additions & 6 deletions changes/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@


def bump_version():
app_name, dry_run, new_version = config.common_arguments()
module_name, dry_run, new_version = config.common_arguments()

attributes.replace_attribute(
app_name,
module_name,
'__version__',
new_version,
dry_run=dry_run)


def current_version(app_name):
return attributes.extract_attribute(app_name, '__version__')
def current_version(module_name):
return attributes.extract_attribute(module_name, '__version__')


def get_new_version(app_name, current_version, no_input,
def get_new_version(module_name, current_version, no_input,
major=False, minor=False, patch=False):

proposed_new_version = increment(
Expand All @@ -37,7 +37,7 @@ def get_new_version(app_name, current_version, no_input,
new_version = raw_input(
'What is the release version for "%s" '
'[Default: %s]: ' % (
app_name, proposed_new_version
module_name, proposed_new_version
)
)

Expand Down
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from unittest2 import TestCase

from changes import config


class BaseTestCase(TestCase):
module_name = 'test_app'
Expand All @@ -23,6 +25,11 @@ def setUp(self):
with open(self.tmp_file, 'w') as init_file:
init_file.write('\n'.join(self.initial_init_content))

config.arguments.update({
'<module_name>': 'test_app',
'--dry-run': True,
})

def tearDown(self):
if os.path.exists(self.tmp_file):
shutil.rmtree(self.module_name)
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ConfigTestCase(BaseTestCase):
'--test-command': None,
'--tox': False,
'--version-prefix': None,
'<app_name>': 'changes',
'<module_name>': 'changes',
'bump_version': False,
'changelog': True,
'install': False,
Expand Down
6 changes: 1 addition & 5 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
class PackagingTestCase(BaseTestCase):

def test_install(self):
config.arguments['--dry-run'] = True
packaging.install()

def test_install_with_module_name(self):
config.arguments['--dry-run'] = True
config.arguments['--module-name'] = 'thing'
config.arguments['--package-name'] = 'thing'
packaging.install()

def test_make_virtualenv(self):
packaging.make_virtualenv()

def test_upload(self):
config.arguments['--dry-run'] = True
packaging.upload()

def test_pypi(self):
config.arguments['--dry-run'] = True
packaging.pypi()

0 comments on commit ef055e0

Please sign in to comment.