Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop latest version support #15

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cucoslib/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

from cucoslib.conf import get_configuration
from cucoslib.enums import EcosystemBackend
from cucoslib.utils import (cwd, TimedCommand, compute_digest,
MavenCoordinates, mvn_find_latest_version)
from cucoslib.utils import cwd, TimedCommand, compute_digest, MavenCoordinates

logger = logging.getLogger(__name__)
configuration = get_configuration()
Expand Down Expand Up @@ -317,12 +316,12 @@ def release_key(rel):
Archive.extract(artifact_path, target_dir)
git.add_and_commit_everything()
elif ecosystem.is_backed_by(EcosystemBackend.maven):
git = Git.create_git(target_dir)
artifact_coords = MavenCoordinates.from_str(artifact)
if not version:
raise ValueError("No version provided for '%s'" % artifact_coords.to_str())
git = Git.create_git(target_dir)
# lxml can't handle HTTPS URLs
maven_url = "http://repo1.maven.org/maven2/"
if not version:
version = mvn_find_latest_version(maven_url, artifact_coords)
artifact_coords.version = version
logger.info("downloading maven package %s", artifact_coords.to_str())

Expand Down
20 changes: 0 additions & 20 deletions cucoslib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,26 +488,6 @@ def from_str(cls, coordinates_str):
return cls(**coordinates)


def mvn_find_latest_version(repo_url, coordinates):
"""
Find latest version of given artifact in Maven repository.

Returns None if the latest version couldn't be determined.
"""
metadata_url = os_path.join(repo_url,
coordinates.groupId.replace('.', '/'),
coordinates.artifactId,
"maven-metadata.xml")
try:
tree = etree.parse(metadata_url)
version = tree.findtext('versioning/release')
if version:
return version
except IOError:
pass
raise ValueError("Unable to determine artifact version: {a}".format(a=coordinates))


def get_latest_upstream_details(ecosystem, package):
"""Returns dict representation of Anitya project"""
url = configuration.anitya_url + '/api/by_ecosystem/{e}/{p}'.\
Expand Down
83 changes: 0 additions & 83 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,6 @@ def test_git_add_and_commit_everything_with_dotgit(tmpdir):
g.add_and_commit_everything()


@pytest.mark.flaky(reruns=5)
def test_fetch_npm_latest(tmpdir):
cache_path = subprocess.check_output(["npm", "config", "get", "cache"], universal_newlines=True).strip()
assert ".npm" in cache_path
module_cache_path = osp.join(cache_path, NPM_MODULE_NAME)

# this could go really really bad if npm returns "/"
shutil.rmtree(module_cache_path, ignore_errors=True) # we don't care if it doesn't exist

npm_url = "https://registry.npmjs.org/{}".format(NPM_MODULE_NAME)
response = requests.get(npm_url, json=True)
try:
assert response.status_code == 200, response.text
except AssertionError:
# Let's try again, but give the remote service some time to catch a breath
time.sleep(1)
raise
module_json = response.json()
latest_version = sorted(module_json["versions"].keys()).pop()
IndianaJones.fetch_artifact(npm,
artifact=NPM_MODULE_NAME, target_dir=str(tmpdir))
assert len(glob.glob(osp.join(cache_path, NPM_MODULE_NAME, "*"))) == 1,\
"there should be just one version of the artifact in the NPM cache"

assert osp.exists(osp.join(module_cache_path, latest_version))
assert osp.exists(osp.join(str(tmpdir), "package.tgz"))


@pytest.mark.parametrize("package,version,digest", [
("abbrev", "1.0.7", "30f6880e415743312a0021a458dd6d26a7211f803a42f1e4a30ebff44d26b7de"),
("abbrev", "1.0.4", "8dc0f480571a4a19e74f1abd4f31f6a70f94953d1ccafa16ed1a544a19a6f3a8")
Expand All @@ -112,22 +84,6 @@ def test_fetch_npm_specific(tmpdir, package, version, digest):
assert osp.exists(osp.join(tmpdir, "package.tgz"))


def test_fetch_pypi_latest(tmpdir):
# stolen from internets
# http://code.activestate.com/recipes/577708-check-for-package-updates-on-pypi-works-best-in-pi/

pypi_rpc = ServerProxy('https://pypi.python.org/pypi')
latest_version = pypi_rpc.package_releases(PYPI_MODULE_NAME)[0]

IndianaJones.fetch_artifact(pypi,
artifact=PYPI_MODULE_NAME, target_dir=str(tmpdir))

assert len(os.listdir(str(tmpdir))) > 1
glob_whl_path = glob.glob(osp.join(str(tmpdir),
"{}-{}*".format(PYPI_MODULE_NAME, latest_version))).pop()
assert osp.exists(glob_whl_path)


def test_fetch_pypi_specific(tmpdir):
digest, path = IndianaJones.fetch_artifact(
pypi, artifact=PYPI_MODULE_NAME,
Expand All @@ -140,24 +96,6 @@ def test_fetch_pypi_specific(tmpdir):
assert osp.exists(glob_whl_path)


@pytest.mark.flaky(reruns=5)
def test_fetch_rubygems_latest(tmpdir):
rubygems_url = "https://rubygems.org/api/v1/versions/{}/latest.json".format(RUBYGEMS_MODULE_NAME)
response = requests.get(rubygems_url, json=True)
try:
assert response.status_code == 200, response.text
except AssertionError:
# Let's try again, but give the remote service some time to catch a breath
time.sleep(1)
raise
latest_version = response.json()["version"]
IndianaJones.fetch_artifact(rubygems,
artifact=RUBYGEMS_MODULE_NAME, target_dir=str(tmpdir))

assert osp.exists(osp.join(str(tmpdir), "{}-{}.gem".format(RUBYGEMS_MODULE_NAME,
latest_version)))


def test_fetch_rubygems_specific(tmpdir):
digest, path = IndianaJones.fetch_artifact(
rubygems,
Expand All @@ -179,24 +117,3 @@ def test_fetch_maven_specific(tmpdir):
assert digest == MAVEN_MODULE_DIGEST
assert osp.exists(osp.join(str(tmpdir), '{}-{}.jar'.format(artifactId, MAVEN_MODULE_VERSION)))


def test_fetch_maven_latest(tmpdir):
maven_central_url = 'http://repo1.maven.org/maven2'

groupId, artifactId = MAVEN_MODULE_NAME.split(':', 1)
groupId = groupId.replace('.', '/')

# get maven-metadata.xml from the repository
url_template = '{base}/{group}/{artifact}/maven-metadata.xml'.format(base=maven_central_url,
group=groupId,
artifact=artifactId)
meta = etree.parse(url_template)

# get latest version
version = meta.xpath('/metadata/versioning/latest')[0].text

IndianaJones.fetch_artifact(maven,
artifact=MAVEN_MODULE_NAME,
version=None, target_dir=str(tmpdir))

assert osp.exists(osp.join(str(tmpdir), '{}-{}.jar'.format(artifactId, version)))
7 changes: 0 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
skip_git_files,
ThreadPool,
MavenCoordinates,
mvn_find_latest_version,
compute_digest,
get_latest_upstream_details,
safe_get_latest_version,
Expand Down Expand Up @@ -82,12 +81,6 @@ def touch_file(path):
assert set(get_all_files_from(test_dir, path_filter=hidden_path_filter)) == \
set(itertools.chain(py_files, test_files))

def test_mvn_find_latest_version(self):
repo_url = os.path.join(os.path.dirname(__file__), 'data/maven/')
a = MavenCoordinates('org.junit', 'junit')
latest = mvn_find_latest_version(repo_url, a)
assert latest == '4.12'

def test_compute_digest(self):
assert compute_digest("/etc/os-release")
with pytest.raises(TaskError):
Expand Down