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

Fix 180: Add environment variables to Click CLI options #187

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def print_version(ctx, param, value):
@click.option(
"--index-url",
"index_urls",
envvar="PYINSP_INDEX_URL",
type=str,
metavar="INDEX",
show_default=True,
Expand Down
58 changes: 58 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,64 @@ def test_cli_with_multiple_index_url_and_tilde_req():
regen=REGEN_TEST_FIXTURES,
)

@pytest.mark.online
def test_cli_with_single_env_var_index_url_flag_override():
# Click default is to override env vars via flag as shown here
expected_file = test_env.get_test_loc("single-url-env-var-expected.json", must_exist=True)
specifier = "zipp==3.8.0"
os.environ["PYINSP_INDEX_URL"] = "https://thirdparty.aboutcode.org/pypi/simple/"
extra_options = [
"--index-url",
"https://pypi.org/simple",
]
check_specs_resolution(
specifier=specifier,
expected_file=expected_file,
extra_options=extra_options,
regen=REGEN_TEST_FIXTURES
)
os.unsetenv("PYINSP_INDEX_URL")

@pytest.mark.online
def test_cli_with_single_env_var_index_url_except_pypi_simple():
expected_file = test_env.get_test_loc(
"single-url-env-var-except-simple-expected.json", must_exist=True)
# using flask since it's not present in thirdparty
specifier = "flask"
os.environ["PYINSP_INDEX_URL"] = "https://thirdparty.aboutcode.org/pypi/simple/"
check_specs_resolution(
specifier=specifier,
expected_file=expected_file,
extra_options=[],
regen=REGEN_TEST_FIXTURES,
)
os.unsetenv("PYINSP_INDEX_URL")

@pytest.mark.online
def test_cli_with_multiple_env_var_index_url_and_tilde_req():
expected_file = test_env.get_test_loc("tilde_req-expected.json", must_exist=True)
specifier = "zipp~=3.8.0"
os.environ["PYINSP_INDEX_URL"] = "https://pypi.org/simple https://thirdparty.aboutcode.org/pypi/simple/"
check_specs_resolution(
specifier=specifier,
expected_file=expected_file,
extra_options=[],
regen=REGEN_TEST_FIXTURES,
)
os.unsetenv("PYINSP_INDEX_URL")

@pytest.mark.online
def test_cli_with_single_env_var_index_url():
expected_file = test_env.get_test_loc("single-url-env-var-expected.json", must_exist=True)
specifier = "zipp==3.8.0"
os.environ["PYINSP_INDEX_URL"] = "https://pypi.org/simple"
check_specs_resolution(
specifier=specifier,
expected_file=expected_file,
extra_options=[],
regen=REGEN_TEST_FIXTURES
)
os.unsetenv("PYINSP_INDEX_URL")

@pytest.mark.online
def test_cli_with_environment_marker_and_complex_ranges():
Expand Down
Loading