Skip to content

Commit

Permalink
Remove latest pypi package feature
Browse files Browse the repository at this point in the history
The pip functionality that it relied on has been removed.
Will remove this feature since it does not seem to be much in use.
  • Loading branch information
larsevj committed Jul 5, 2024
1 parent 570b562 commit 4a0e1a2
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 183 deletions.
4 changes: 1 addition & 3 deletions komodo/check_up_to_date_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from packaging import version as get_version
from packaging.specifiers import InvalidSpecifier, SpecifierSet

from komodo.package_version import LATEST_PACKAGE_ALIAS, strip_version
from komodo.package_version import strip_version
from komodo.prettier import write_to_file
from komodo.yaml_file_types import ReleaseFile, RepositoryFile

Expand Down Expand Up @@ -98,8 +98,6 @@ def compatible_versions(
def get_pypi_packages(release: dict, repository: dict) -> list:
pypi_packages = []
for package, version in release.items():
if LATEST_PACKAGE_ALIAS in strip_version(version):
continue
try:
if repository[package][version].get("source", None) == "pypi":
pypi_packages.append(package)
Expand Down
12 changes: 2 additions & 10 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
from komodo.build import make
from komodo.data import Data
from komodo.fetch import fetch
from komodo.package_version import (
LATEST_PACKAGE_ALIAS,
latest_pypi_version,
strip_version,
)
from komodo.package_version import strip_version
from komodo.shebang import fixup_python_shebangs
from komodo.shell import pushd, shell
from komodo.yaml_file_types import ReleaseFile, RepositoryFile
Expand Down Expand Up @@ -218,9 +214,7 @@ def generate_release_manifest(
for package, version in release_file_content.items():
entry: Dict[str, str] = repository_file_content[package][version]
maintainer = repository_file_content[package][version]["maintainer"]
if version == LATEST_PACKAGE_ALIAS:
version = latest_pypi_version(entry.get("pypi_package_name", package))
elif entry.get("fetch") == "git":
if entry.get("fetch") == "git":
version = git_hashes[package]
release[package] = {
"version": version,
Expand Down Expand Up @@ -282,8 +276,6 @@ def install_previously_downloaded_pip_packages(
continue

package_name = current.get("pypi_package_name", pkg)
if ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(package_name)
shell_input = [
pip_executable,
f"install {package_name}=={strip_version(ver)}",
Expand Down
5 changes: 0 additions & 5 deletions komodo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import jinja2

from komodo.package_version import (
LATEST_PACKAGE_ALIAS,
get_git_revision_hash,
latest_pypi_version,
strip_version,
)
from komodo.shell import pushd, shell
Expand Down Expand Up @@ -111,9 +109,6 @@ def fetch(pkgs, repo, outdir, pip="pip") -> dict:
protocol = current.get("fetch")
pkg_alias = current.get("pypi_package_name", pkg)

if url == "pypi" and ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(pkg_alias)

name = f"{pkg_alias} ({ver}): {url}"
pkgname = f"{pkg_alias}-{ver}"

Expand Down
28 changes: 0 additions & 28 deletions komodo/package_version.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import os
import re
import subprocess
import sys

LATEST_PACKAGE_ALIAS = "*"
_PYPI_LATEST_VERSION_RE = r".+from\ versions\:\ (.+)\)"
# This command is deprecated. Hopefully it is not removed until a replacement
# is made. For updates on this, see https://github.com/pypa/pip/issues/9139
_PYPI_LATEST_VERSION_CMD = "python -m pip install --use-deprecated=legacy-resolver {}=="


def strip_version(version):
"""In order to be able to support both py2 and py3 we need to be able
Expand All @@ -21,27 +14,6 @@ def strip_version(version):
return version.split("+")[0]


def latest_pypi_version(package):
cmd = _PYPI_LATEST_VERSION_CMD.format(package)
try:
subprocess.check_output(cmd.split(" "), stderr=subprocess.PIPE)
except subprocess.CalledProcessError as called_process_error:
stderr = called_process_error.stderr.decode(sys.getfilesystemencoding())
matches = re.match(_PYPI_LATEST_VERSION_RE, stderr)
if matches.lastindex == 0:
msg = f"got unexpected output from {cmd} using {_PYPI_LATEST_VERSION_RE}: {stderr}"
raise ValueError(
msg,
) from called_process_error
versions = matches.group(1).split(",")
version = versions[len(versions) - 1].strip()
if version == "none":
return None
return version
msg = f"{cmd} did not raise CalledProcessError"
raise ValueError(msg)


def get_git_revision_hash(path):
env = os.environ.copy()
env["GIT_DIR"] = f"{path}/.git"
Expand Down
38 changes: 12 additions & 26 deletions komodo/pypi_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from packaging.utils import canonicalize_name
from packaging.version import InvalidVersion

from .package_version import LATEST_PACKAGE_ALIAS


# From Pep 508
def format_full_version(info) -> str:
Expand Down Expand Up @@ -99,7 +97,7 @@ def add_user_specified(
Requirement(
d
if self._to_install.get(canonicalize_name(d))
in [None, LATEST_PACKAGE_ALIAS, "main", "master"]
in [None, "main", "master"]
else f"{d}=={self._to_install.get(canonicalize_name(d))}"
)
for d in depends
Expand Down Expand Up @@ -132,28 +130,16 @@ def _get_requirements(
if package_version not in self.requirements[canonical]:
with TemporaryDirectory() as tmpdir:
try:
if package_version == LATEST_PACKAGE_ALIAS:
subprocess.check_output(
[
"pip",
"download",
package_name,
f"--python-version={self.python_version}",
"--no-deps",
],
cwd=tmpdir,
)
else:
subprocess.check_output(
[
"pip",
"download",
f"{package_name}=={package_version}",
f"--python-version={self.python_version}",
"--no-deps",
],
cwd=tmpdir,
)
subprocess.check_output(
[
"pip",
"download",
f"{package_name}=={package_version}",
f"--python-version={self.python_version}",
"--no-deps",
],
cwd=tmpdir,
)
except Exception as err:
raise ValueError(
f"Could not install {package_name} {package_version} from pypi"
Expand Down Expand Up @@ -194,7 +180,7 @@ def _make_install_name(self, name: str) -> str:
return self._install_names.get(canonical, canonical)

def _version_satisfied(self, version: str, requirement: Requirement) -> bool:
if version in ["main", "master", LATEST_PACKAGE_ALIAS]:
if version in ["main", "master"]:
return True
try:
specifier = requirement.specifier
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cli/nominal_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ hackres: 0.0.5289
hackgit: test-hash
python: 2.7.5-builtin
qt5: 5.13.6-builtin
ert42: '*'
ert42: 10.0.1
some_github_binary_artifact: 0.0.1a1
2 changes: 1 addition & 1 deletion tests/data/cli/nominal_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ hackgit:
maintainer: charlie

ert42:
'*':
10.0.1:
source: pypi
pypi_package_name: ert
fetch: pip
Expand Down
6 changes: 0 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest

from komodo.cli import cli_main
from komodo.package_version import LATEST_PACKAGE_ALIAS
from tests import _get_test_root


Expand Down Expand Up @@ -73,11 +72,6 @@ def test_main(args, tmpdir):
with open(os.path.join(release_path, release_name), encoding="utf-8") as releasedoc:
releasedoc_content = releasedoc.read()

# test specifically for the regression introduced by
# https://github.com/equinor/komodo/issues/190 where if you provided ert
# with version '*', it would then show up in the releasedoc.
assert f"version: '{LATEST_PACKAGE_ALIAS}'" not in releasedoc_content

# ensure the alias is used when resolving the version
assert "version: null" not in releasedoc_content

Expand Down
23 changes: 0 additions & 23 deletions tests/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

from komodo.fetch import fetch
from komodo.package_version import LATEST_PACKAGE_ALIAS


def test_make_one_pip_package(captured_shell_commands, tmpdir):
Expand Down Expand Up @@ -116,28 +115,6 @@ def test_fetch_git_does_not_accept_pypi_package_name(tmpdir):
fetch(packages, repositories, str(tmpdir))


def test_fetch_pip_with_latest_version(captured_shell_commands, tmpdir):
packages = {"ert": LATEST_PACKAGE_ALIAS}
repositories = {
"ert": {
LATEST_PACKAGE_ALIAS: {
"source": "pypi",
"pypi_package_name": "ert3",
"fetch": "pip",
"make": "pip",
"maintainer": "someone",
"depends": [],
},
},
}

with patch("komodo.fetch.latest_pypi_version") as mock_latest_ver:
mock_latest_ver.return_value = "1.0.0"
fetch(packages, repositories, str(tmpdir))
mock_latest_ver.assert_called_once_with("ert3")
assert "ert3==1.0.0" in captured_shell_commands[0]


def test_fetch_git_hash(captured_shell_commands, tmpdir):
packages = {"ert": "main"}
repositories = {
Expand Down
40 changes: 0 additions & 40 deletions tests/test_package_version.py

This file was deleted.

40 changes: 0 additions & 40 deletions tests/test_up_to_date_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,46 +348,6 @@ def test_check_up_to_date_file_output(monkeypatch, tmpdir, capsys):
},
id="Base line test",
),
pytest.param(
{"dummy_package": "1.0.0", "komodo_version_package": "1.*"},
{
"dummy_package": {
"1.0.0": {"maintainer": "scout", "make": "pip", "source": "pypi"},
},
"komodo_version_package": {
"1.*": {"maintainer": "scout", "make": "pip", "source": "pypi"},
},
},
{
"releases": {
"2.0.0": [{"filename": f"valid_upgrade_for_macos_{sys.platform}"}]
},
},
{
"release": {
"dummy_package": "2.0.0",
"komodo_version_package": "1.*",
},
"repo": {
"dummy_package": {
"2.0.0": {
"maintainer": "scout",
"make": "pip",
"source": "pypi",
},
"1.0.0": {
"maintainer": "scout",
"make": "pip",
"source": "pypi",
},
},
"komodo_version_package": {
"1.*": {"maintainer": "scout", "make": "pip", "source": "pypi"},
},
},
},
id="With komodo package alias not updated",
),
pytest.param(
{"dummy_package": "1.0.0+py27"},
{
Expand Down

0 comments on commit 4a0e1a2

Please sign in to comment.