Skip to content

Commit

Permalink
make default python version a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed May 15, 2024
1 parent e8552bb commit 8bfd0de
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/packaged/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


MAKESELF_PATH = os.path.join(os.path.dirname(__file__), "makeself.sh")
DEFAULT_PYTHON_VERSION = "3.12"


class SourceDirectoryNotFound(Exception):
Expand Down
14 changes: 9 additions & 5 deletions src/packaged/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import platform
import sys

from packaged import PythonNotAvailable, SourceDirectoryNotFound, create_package
from packaged import (
DEFAULT_PYTHON_VERSION,
PythonNotAvailable,
SourceDirectoryNotFound,
create_package,
)
from packaged.config import (
Config,
ConfigValidationError,
config_file_exists,
parse_config,
Expand Down Expand Up @@ -72,11 +76,11 @@ def cli(argv: list[str] | None = None) -> int:
)
parser.add_argument(
"--python-version",
metavar="3.12",
metavar=DEFAULT_PYTHON_VERSION,
help="Version of Python to package your project with.",
default="3.12",
default=DEFAULT_PYTHON_VERSION,
)
args = parser.parse_args(argv, namespace=Config)
args = parser.parse_args(argv)

(
source_directory,
Expand Down
1 change: 1 addition & 0 deletions src/packaged/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def parse_config(source_directory: str) -> Config:
config_data["output_path"],
config_data["build_command"],
config_data["startup_command"],
config_data.get("python_version", "3.12"),
)
except KeyError as exc:
key = exc.args[0]
Expand Down
22 changes: 18 additions & 4 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@

from unittest import mock

from pytest import MonkeyPatch

import packaged
import packaged.cli


def test_cli(monkeypatch: MonkeyPatch) -> None:
def test_cli() -> None:
"""Ensures that CLI passes args to `create_package()` properly."""
with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(["./foo", "pip install foo", "python -m foo"])

# source_directory is None
mocked.assert_called_with(None, "./foo", "pip install foo", "python -m foo")
mocked.assert_called_with(
None,
"./foo",
"pip install foo",
"python -m foo",
packaged.DEFAULT_PYTHON_VERSION,
)

with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(
["./baz", "pip install baz", "python -m baz", "--python-version=3.10"]
)

# specified python version
mocked.assert_called_with(None, "./baz", "pip install baz", "python -m baz", "3.10")

with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(
Expand All @@ -31,6 +44,7 @@ def test_cli(monkeypatch: MonkeyPatch) -> None:
"./bar",
"pip install -rrequirements.txt",
"python src/mypackage/cli.py",
packaged.DEFAULT_PYTHON_VERSION,
)
args = mocked.call_args[0]
assert args[0].endswith("/mypackage")
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def pytest_sessionstart(session: pytest.Session) -> None:

return

_, python_bin_path = packaged.ensure_python("3.12")
_, python_bin_path = packaged.ensure_python(packaged.DEFAULT_PYTHON_VERSION)
assert os.path.isfile(python_bin_path)
2 changes: 1 addition & 1 deletion tests/end_to_end/packaged_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def build_package(
output_path,
build_command,
startup_command,
python_version="3.12",
python_version=packaged.DEFAULT_PYTHON_VERSION,
)
yield
finally:
Expand Down

0 comments on commit 8bfd0de

Please sign in to comment.