Skip to content

Commit

Permalink
Don't require an scm for local publishes. (#4773)
Browse files Browse the repository at this point in the history
The scm conceptually went unused anyway; so, guard a few corner cases
and add regression coverage.

Fixes #4772
  • Loading branch information
jsirois committed Jul 26, 2017
1 parent a4afe01 commit 5c60019
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/python/pants/backend/jvm/tasks/jar_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def __init__(self, *args, **kwargs):

self._jvm_options = self.get_options().jvm_options

self.scm = get_scm()
self.log = self.context.log

if self.get_options().local:
Expand Down Expand Up @@ -400,14 +399,16 @@ def __init__(self, *args, **kwargs):
self.push_postscript = self.get_options().push_postscript or ''
self.local_snapshot = False

self.scm = get_scm() if self.commit else None

self.named_snapshot = self.get_options().named_snapshot
if self.named_snapshot:
self.named_snapshot = Namedver.parse(self.named_snapshot)

self.dryrun = self.get_options().dryrun
self.transitive = self.get_options().transitive
self.force = self.get_options().force
self.publish_changelog = self.get_options().changelog
self.publish_changelog = self.get_options().changelog and self.scm

def parse_jarcoordinate(coordinate):
components = coordinate.split('#', 1)
Expand Down Expand Up @@ -674,7 +675,7 @@ def stage_artifacts(tgt, jar, version, tag, changelog):
for (org, name), rev in self.overrides.items():
print('{0}={1}'.format(coordinate(org, name), rev))

head_sha = self.scm.commit_id
head_sha = self.scm.commit_id if self.scm else None

safe_rmtree(self.workdir)
published = []
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/task/scm_publish_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def check_clean_master(self, commit=False):
if changed_files:
raise self.DirtyWorkspaceError('Can only push from a clean branch, found : {}'
.format(' '.join(changed_files)))
else:
elif self.scm:
self.log.info('Skipping check for a clean {} branch in test mode.'
.format(self.scm.branch_name))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_smoke_publish(self):
with temporary_dir() as publish_dir:
self.set_options(local=publish_dir)
task = self.create_task(self.context())
task.scm = Mock()
task.execute()

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def test_scala_publish(self):
'org.pantsbuild.testproject.publish/jvm-example-lib_2.11/publish.properties',
'org.pantsbuild.testproject.publish.hello/welcome_2.11/publish.properties'],
extra_options=['--doc-scaladoc-skip'],
expected_primary_artifact_count=3,
assert_publish_config_contents=True)

def test_java_publish(self):
Expand All @@ -109,8 +108,7 @@ def test_protobuf_publish(self):
['org.pantsbuild.testproject.publish.protobuf/protobuf-java/'
'publish.properties',
'org.pantsbuild.testproject.protobuf/distance/publish.properties'],
extra_options=['--doc-javadoc-skip'],
expected_primary_artifact_count=2)
extra_options=['--doc-javadoc-skip'])

def test_named_snapshot(self):
name = "abcdef0123456789"
Expand Down Expand Up @@ -220,16 +218,14 @@ def test_override_via_address(self):
assert_publish_config_contents=True)

def publish_test(self, target, artifacts, pushdb_files, extra_options=None, extra_config=None,
extra_env=None, expected_primary_artifact_count=1, success_expected=True,
assert_publish_config_contents=False):
extra_env=None, success_expected=True, assert_publish_config_contents=False):
"""Tests that publishing the given target results in the expected output.
:param target: Target to test.
:param artifacts: A map from directories to a list of expected filenames.
:param pushdb_files: list of pushdb files that would be created if this weren't a local publish
:param extra_options: Extra command-line options to the pants run.
:param extra_config: Extra pants.ini configuration for the pants run.
:param expected_primary_artifact_count: Number of artifacts we expect to be published.
:param extra_env: Extra environment variables for the pants run.
:param assert_publish_config_contents: Test the contents of the generated ivy and pom file.
If set to True, compares the generated ivy.xml and pom files in
Expand Down
10 changes: 7 additions & 3 deletions tests/python/pants_test/task/test_scm_publish_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

class ScmPublishMixinTest(unittest.TestCase):
class ScmPublish(ScmPublishMixin):
def __init__(self, restrict_push_branches=None, restrict_push_urls=None):
def __init__(self, restrict_push_branches=None, restrict_push_urls=None, scm_available=True):
self._restrict_push_branches = restrict_push_branches
self._restrict_push_urls = restrict_push_urls
self._scm = mock.Mock()
self._scm = mock.Mock() if scm_available else None
self._log = mock.MagicMock()

@property
Expand All @@ -40,6 +40,10 @@ def scm(self):
def log(self):
return self._log

def test_check_clean_master_no_scm(self):
scm_publish = self.ScmPublish(scm_available=False)
scm_publish.check_clean_master(commit=False)

def test_check_clean_master_dry_run_bad_branch(self):
scm_publish = self.ScmPublish(restrict_push_branches=['bob'])
scm_publish.scm.branch_name = 'jane'
Expand Down Expand Up @@ -77,7 +81,7 @@ def test_check_clean_master_bad_branch(self):

def test_check_clean_master_bad_remote(self):
scm_publish = self.ScmPublish(restrict_push_urls=['amy'])
scm_publish.scm.serveer_url = 'https://amy'
scm_publish.scm.server_url = 'https://amy'
with self.assertRaises(scm_publish.InvalidRemoteError):
scm_publish.check_clean_master(commit=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
<publications>
<artifact/>
<artifact m:classifier="sources"/>
<artifact m:classifier="CHANGELOG" ext="txt"/>
<artifact type="pom"/>
</publications>
</ivy-module>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
<artifact/>
<artifact m:classifier="sources"/>
<artifact m:classifier="javadoc"/>
<artifact m:classifier="CHANGELOG" ext="txt"/>
<artifact type="pom"/>
</publications>
</ivy-module>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
<artifact/>
<artifact m:classifier="sources"/>
<artifact m:classifier="javadoc"/>
<artifact m:classifier="CHANGELOG" ext="txt"/>
<artifact type="pom"/>
</publications>
</ivy-module>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
<artifact/>
<artifact m:classifier="sources"/>
<artifact m:classifier="javadoc"/>
<artifact m:classifier="CHANGELOG" ext="txt"/>
<artifact type="pom"/>
</publications>
</ivy-module>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
<publications>
<artifact/>
<artifact m:classifier="sources"/>
<artifact m:classifier="CHANGELOG" ext="txt"/>
<artifact type="pom"/>
</publications>
</ivy-module>

0 comments on commit 5c60019

Please sign in to comment.