-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
airbyte-ci: Test pypi published properly (#34689)
- Loading branch information
Joe Reuter
committed
Jan 31, 2024
1 parent
7f4abcc
commit ad2a451
Showing
12 changed files
with
57 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
from typing import Optional | ||
from urllib.parse import urlparse | ||
|
||
import requests # type: ignore | ||
|
||
|
||
def is_package_published(package_name: Optional[str], version: Optional[str], registry_url: str) -> bool: | ||
""" | ||
Check if a package with a specific version is published on PyPI or Test PyPI. | ||
:param package_name: The name of the package to check. | ||
:param version: The version of the package. | ||
:param test_pypi: Set to True to check on Test PyPI, False for regular PyPI. | ||
:return: True if the package is found with the specified version, False otherwise. | ||
Check if a package with a specific version is published on a python registry. | ||
""" | ||
if not package_name or not version: | ||
return False | ||
|
||
parsed_registry_url = urlparse(registry_url) | ||
base_url = f"{parsed_registry_url.scheme}://{parsed_registry_url.netloc}" | ||
|
||
url = f"{base_url}/{package_name}/{version}/json" | ||
url = f"{registry_url}/{package_name}/{version}/json" | ||
|
||
response = requests.get(url) | ||
return response.status_code == 200 | ||
try: | ||
response = requests.get(url) | ||
return response.status_code == 200 | ||
except requests.exceptions.ConnectionError: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
airbyte-ci/connectors/pipelines/tests/test_helpers/test_pip.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
import pytest | ||
from pipelines.helpers.pip import is_package_published | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"package_name, version, registry_url, expected", | ||
[ | ||
pytest.param(None, None, "https://pypi.org/pypi", False, id="package_name and version are None"), | ||
pytest.param(None, "0.2.0", "https://pypi.org/pypi", False, id="package_name is None"), | ||
pytest.param("airbyte-source-pokeapi", None, "https://pypi.org/pypi", False, id="version is None"), | ||
pytest.param("airbyte-source-pokeapi", "0.2.0", "https://pypi.org/pypi", True, id="published on pypi"), | ||
pytest.param("airbyte-source-pokeapi", "0.1.0", "https://pypi.org/pypi", False, id="version not published on pypi"), | ||
pytest.param("airbyte-source-nonexisting", "0.1.0", "https://pypi.org/pypi", False, id="package not published on pypi"), | ||
pytest.param("airbyte-source-pokeapi", "0.2.1", "https://test.pypi.org/pypi", True, id="published on test.pypi"), | ||
pytest.param("airbyte-source-pokeapi", "0.1.0", "https://test.pypi.org/pypi", False, id="version not published on test.pypi"), | ||
pytest.param("airbyte-source-nonexisting", "0.1.0", "https://test.pypi.org/pypi", False, id="package not published on test.pypi"), | ||
pytest.param("airbyte-source-pokeapi", "0.2.0", "https://some-non-existing-host.com", False, id="host does not exist"), | ||
], | ||
) | ||
def test_is_package_published(package_name, version, registry_url, expected): | ||
assert is_package_published(package_name, version, registry_url) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters