Skip to content

Commit

Permalink
Merge pull request #40 from mogproject/develop
Browse files Browse the repository at this point in the history
Develop #37 #38
  • Loading branch information
mogproject committed Jan 14, 2015
2 parents 27fa1c8 + d9052ce commit fc0432b
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/

# Distribution / packaging
.Python
.eggs/
env/
build/
develop-eggs/
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytz
python-dateutil
GitPython>=0.3.5
boto

17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ def get_version():
return __import__('artifactcli').__version__


def get_requirements(path):
import os

with open(path) as f:
return f.read().splitlines()

setup(
name='artifact-cli',
version=get_version(),
description='Private Artifact Manager using Amazon S3',
author='mogproject',
author_email='mogproj@gmail.com',
url='https://github.com/mogproject/artifact-cli',
install_requires=[
'pytz',
'python-dateutil',
'GitPython',
'boto',
],
tests_require=[
'moto',
],
install_requires=get_requirements('requirements.txt'),
tests_require=get_requirements('test-requirements.txt'),
package_dir={'': SRC_DIR},
packages=find_packages(SRC_DIR),
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion src/artifactcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.7"
__version__ = "0.1.8"
2 changes: 1 addition & 1 deletion src/artifactcli/artifact/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, basic_info, file_info, scm_info=None):
self.scm_info = scm_info

def __str__(self):
buf = [self.basic_info, self.file_info] + [self.scm_info] if self.scm_info else []
buf = [self.basic_info, self.file_info] + ([self.scm_info] if self.scm_info else [])
return to_str('\n'.join(map(str, buf)))

def to_dict(self):
Expand Down
19 changes: 16 additions & 3 deletions src/artifactcli/artifact/gitinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from datetime import datetime
import logging
import os
import dateutil.parser
import git
from baseinfo import BaseInfo
Expand Down Expand Up @@ -57,11 +58,23 @@ def from_dict(d):
d['sha'],
)

@staticmethod
def _search_git_repo(path):
while True:
try:
return git.Repo(path)
except git.InvalidGitRepositoryError:
parent_dir = os.path.dirname(path)
if path == parent_dir:
return None
path = parent_dir
except git.NoSuchPathError:
return None

@staticmethod
def from_path(path):
try:
repo = git.Repo(path)
except (git.InvalidGitRepositoryError, git.NoSuchPathError):
repo = GitInfo._search_git_repo(path)
if not repo:
logging.warn('Failed to fetch Git information: %s' % path)
return None

Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
moto

17 changes: 17 additions & 0 deletions tests/artifactcli/artifact/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ def test_str(self):
])
self.assertEqual(str(self.test_data[1]), expected.encode('utf-8'))

def test_str_no_scm_info(self):
expected = '\n'.join([
'Basic Info:',
' Group ID : com.github.mogproject',
' Artifact ID: xxx-yyy-assembly',
' Version : 0.1-SNAPSHOT',
' Packaging : jar',
' Revision : None',
'File Info:',
' User : USER@HOST',
' Modified: 2014-12-31 12:34:56',
' Size : 0 (0.0B)',
' MD5 : 0',
])
self.assertEqual(str(self.test_data[2]), expected.encode('utf-8'))

def test_repr(self):
self.assertEqual(
repr(self.test_data[0]),
Expand All @@ -103,6 +119,7 @@ def test_from_path(self):
ret = Artifact.from_path('GROUP_ID', 'tests/resources/test-artifact-1.2.3.dat')
self.assertEqual(ret.basic_info, BasicInfo('GROUP_ID', 'test-artifact', '1.2.3', 'dat', None))
self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563'))
self.assertFalse(ret.scm_info is None)

def test_dict_conversions(self):
self.assertEqual(Artifact.from_dict(self.test_data[0].to_dict()), self.test_data[0])
Expand Down
1 change: 1 addition & 0 deletions tests/artifactcli/artifact/test_gitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_repr(self):

def test_from_path(self):
gi = GitInfo.from_path('tests/resources/test-artifact-1.2.3.dat')
self.assertFalse(gi is None)

def test_from_path_error(self):
self.assertEqual(GitInfo.from_path('tests/resources/test001_no_such_path.dat'), None)
Expand Down
1 change: 1 addition & 0 deletions tests/artifactcli/operation/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ def test_run(self):
ret = r.artifacts['test-artifact'][1]
self.assertEqual(ret.basic_info, BasicInfo('com.github.mogproject', 'test-artifact', '1.2.3', 'dat', 2))
self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563'))
self.assertFalse(ret.scm_info is None)
9 changes: 6 additions & 3 deletions tests/artifactcli/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def test_upload_file_real_file(self):
ret = r.artifacts['test-artifact'][0]
self.assertEqual(ret.basic_info, BasicInfo('com.github.mogproject', 'test-artifact', '1.2.3', 'dat', 1))
self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563'))
self.assertFalse(ret.scm_info is None)

def test_upload_file_force(self):
expected = [Artifact(BasicInfo('com.github.mogproject', 'art-test', '0.0.1', 'jar', 1),
Expand Down Expand Up @@ -609,23 +610,25 @@ def test_print_list_output_json_long(self):
fp = StringIO()
r.print_list(output='json', fp=fp)
arts = [Artifact.from_dict(d) for d in json.loads(fp.getvalue())]
self.assertEqual(arts, [
a = [
Artifact(BasicInfo('com.github.mogproject', 'art-test', '0.0.1', 'jar', i),
FileInfo('host1', 'user1', 4567890, datetime(2014, 12, 31, 9, 12, 34),
'ffffeeeeddddccccbbbbaaaa99998888'),
GitInfo('master', ['release 0.0.1'], 'mogproject', 'x@example.com',
datetime(2014, 12, 30, 8, 11, 29), 'first commit',
'111122223333444455556666777788889999aaaa'))
for i in range(1, 16)
] + [
]
b = [
Artifact(BasicInfo('com.github.mogproject', 'art-test', '0.0.2', 'jar', i),
FileInfo('host1', 'user1', 4567890, datetime(2014, 12, 31, 9, 12, 34),
'ffffeeeeddddccccbbbbaaaa99998888'),
GitInfo('master', ['release 0.0.2'], 'mogproject', 'x@example.com',
datetime(2014, 12, 30, 8, 11, 29), 'new version',
'111122223333444455556666777788889999aaaa'))
for i in range(1, 16)
])
]
self.assertEqual(arts, a + b)
fp.close()

def test_print_list_output_error(self):
Expand Down

0 comments on commit fc0432b

Please sign in to comment.