Skip to content

Commit

Permalink
Bundle makeself, and update license
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed May 14, 2024
1 parent e417182 commit c832bb5
Show file tree
Hide file tree
Showing 9 changed files with 1,855 additions and 63 deletions.
360 changes: 339 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ Then upload it to PyPI using [twine](https://twine.readthedocs.io/en/latest/#ins
```bash
twine upload dist/*
```

## License

The package is Licensed under GNU General Public License v2 (GPLv2). However,
note that **the packages created with `packaged` are NOT licensed under GPL**.
This is because the archives created are just data for the package, and
`packaged` is not a part of the archives created.

That means that you can freely use `packaged` for commercial use.

Read the [License section for Makeself](https://github.com/megastep/makeself?tab=readme-ov-file#license) for more information.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dev =
[options.package_data]
packaged =
py.typed
makeself.sh
makeself-header.sh

[tool:pytest]
addopts = --cov --cov-report=term-missing -nauto
41 changes: 10 additions & 31 deletions src/packaged/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@
import shutil
import subprocess
import tempfile
import urllib.request

import yen


MAKESELF_VERSION = "2.5.0"
MAKESELF_DOWNLOAD_URL = (
"https://github.com/megastep/makeself/releases/download/"
f"release-{MAKESELF_VERSION}/makeself-{MAKESELF_VERSION}.run"
)
MAKESELF_DOWNLOAD_PATH = os.path.join(os.path.dirname(__file__), ".build_deps")
MAKESELF_PATH = os.path.join(
MAKESELF_DOWNLOAD_PATH, f"makeself-{MAKESELF_VERSION}", "makeself.sh"
)
MAKESELF_PATH = os.path.join(os.path.dirname(__file__), "makeself.sh")


class SourceDirectoryNotFound(Exception):
Expand All @@ -30,26 +21,6 @@ def __init__(self, directory_path: str) -> None:
self.directory_path = directory_path


def ensure_makeself() -> None:
"""If `makeself.sh` doesn't exist, downloads it."""
if os.path.exists(MAKESELF_PATH):
return

if not os.path.exists(MAKESELF_DOWNLOAD_PATH):
os.mkdir(MAKESELF_DOWNLOAD_PATH)

makeself_run_path = os.path.join(MAKESELF_DOWNLOAD_PATH, "makeself.run")
urllib.request.urlretrieve(MAKESELF_DOWNLOAD_URL, makeself_run_path)

os.chmod(makeself_run_path, 0o777)
subprocess.check_call(
[makeself_run_path, "--nox11"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
cwd=MAKESELF_DOWNLOAD_PATH,
)


def create_package(
source_directory: str | None,
output_path: str,
Expand All @@ -72,7 +43,7 @@ def create_package(

try:
# Use `yen` to ensure a portable Python is present on the system
python_version, yen_python_bin_path = yen.ensure_python("3.11")
python_version, yen_python_bin_path = ensure_python()
yen_python_path = os.path.join(yen.PYTHON_INSTALLS_PATH, python_version)
yen_python_bin_relpath = os.path.relpath(yen_python_bin_path, yen_python_path)

Expand Down Expand Up @@ -125,3 +96,11 @@ def create_package(
os.remove(startup_script_path)
if os.path.exists(packaged_python_path):
shutil.rmtree(packaged_python_path)


def ensure_python() -> tuple[str, str]:
"""
Checks that the version of Python we want to use is available on the
system, and if not, downloads it.
"""
return yen.ensure_python("3.11")
3 changes: 1 addition & 2 deletions src/packaged/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import platform
import sys

from packaged import SourceDirectoryNotFound, ensure_makeself, create_package
from packaged import SourceDirectoryNotFound, create_package
from packaged.config import (
Config,
ConfigValidationError,
Expand Down Expand Up @@ -72,7 +72,6 @@ def cli(argv: list[str] | None = None) -> int:
args.startup_command,
)

ensure_makeself()
try:
create_package(source_directory, output_path, build_command, startup_command)
except SourceDirectoryNotFound as exc:
Expand Down
Loading

0 comments on commit c832bb5

Please sign in to comment.