diff --git a/README.md b/README.md index 1b7ced6..41b6553 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ cosmofy src/cosmofy \ ```text @@ -60,31 +61,24 @@ USAGE GENERAL - -h, --help - Show this help message and exit. - - --version - Show program version and exit. - - --debug - Show debug messages. - - -n, --dry-run - Do not make any file system changes. - - --self-update - Update `cosmofy` to the latest version. + -h, --help Show this help message and exit. + --version Show program version and exit. + --debug Show debug messages. + -n, --dry-run Do not make any file system changes. + --self-update Update `cosmofy` to the latest version. CACHE --python-url URL URL from which to download Cosmopolitan Python. - [env: COSMOFY_PYTHON_URL=https://cosmo.zip/pub/cosmos/bin/python] + [default: https://cosmo.zip/pub/cosmos/bin/python] + [env: COSMOFY_PYTHON_URL=None] --cache PATH Directory in which to cache Cosmopolitan Python downloads. Use `false` or `0` to disable caching. - [env: COSMOFY_CACHE_DIR=/home/lev/.cache/cosmofy] + [default: ~/.cache/cosmofy] + [env: COSMOFY_CACHE_DIR=None] --clone Obtain python by cloning `cosmofy` and removing itself instead of @@ -145,17 +139,17 @@ SELF-UPDATER --receipt-url URL URL to the published receipt. - [default: .json] + [default: --release-url + .json] [env: RECEIPT_URL=] --release-url URL URL to the file to download. - [default: ] + [default: --receipt-url without .json] [env: RELEASE_URL=] --release-version STRING Release version. - [default: we run `output --version` and save first version-looking string] + [default: first version-like string in `$(${output} --version)`] ``` diff --git a/src/cosmofy/args.py b/src/cosmofy/args.py index 8d37b8d..4c917f0 100644 --- a/src/cosmofy/args.py +++ b/src/cosmofy/args.py @@ -11,14 +11,16 @@ log = logging.getLogger(__name__) -COSMOFY_PYTHON_URL = ENV.get( - "COSMOFY_PYTHON_URL", "https://cosmo.zip/pub/cosmos/bin/python" -) +DEFAULT_PYTHON_URL = "https://cosmo.zip/pub/cosmos/bin/python" +"""Default URL to download python from.""" + +COSMOFY_PYTHON_URL = ENV.get("COSMOFY_PYTHON_URL") """URL to download python from.""" -COSMOFY_CACHE_DIR = Path( - ENV.get("COSMOFY_CACHE_DIR", Path.home() / ".cache" / "cosmofy") -) +DEFAULT_CACHE_DIR = Path.home() / ".cache" / "cosmofy" +"""Default cache directory.""" + +COSMOFY_CACHE_DIR = ENV.get("COSMOFY_CACHE_DIR") """Path to cache directory.""" RECEIPT_URL = ENV.get("RECEIPT_URL", "") @@ -41,30 +43,23 @@ GENERAL - -h, --help - Show this help message and exit. - - --version - Show program version and exit. - - --debug - Show debug messages. - - -n, --dry-run - Do not make any file system changes. - - --self-update - Update `cosmofy` to the latest version. + -h, --help Show this help message and exit. + --version Show program version and exit. + --debug Show debug messages. + -n, --dry-run Do not make any file system changes. + --self-update Update `cosmofy` to the latest version. CACHE --python-url URL URL from which to download Cosmopolitan Python. + [default: {DEFAULT_PYTHON_URL}] [env: COSMOFY_PYTHON_URL={COSMOFY_PYTHON_URL}] --cache PATH Directory in which to cache Cosmopolitan Python downloads. Use `false` or `0` to disable caching. + [default: {str(DEFAULT_CACHE_DIR).replace(str(Path.home()), '~')}] [env: COSMOFY_CACHE_DIR={COSMOFY_CACHE_DIR}] --clone @@ -126,17 +121,17 @@ --receipt-url URL URL to the published receipt. - [default: .json] + [default: --release-url + .json] [env: RECEIPT_URL={RECEIPT_URL}] --release-url URL URL to the file to download. - [default: ] + [default: --receipt-url without .json] [env: RELEASE_URL={RELEASE_URL}] --release-version STRING Release version. - [default: we run `output --version` and save first version-looking string] + [default: first version-like string in `$(${{output}} --version)`] """ @@ -169,10 +164,10 @@ def for_real(self, value: bool) -> None: # cache - python_url: str = COSMOFY_PYTHON_URL + python_url: str = COSMOFY_PYTHON_URL or DEFAULT_PYTHON_URL """URL from which to download Cosmopolitan Python.""" - cache: Optional[Path] = COSMOFY_CACHE_DIR + cache: Optional[Path] = Path(COSMOFY_CACHE_DIR or DEFAULT_CACHE_DIR) """Directory for caching downloads.""" clone: bool = False diff --git a/src/cosmofy/bundler.py b/src/cosmofy/bundler.py index e2895a7..16f979a 100644 --- a/src/cosmofy/bundler.py +++ b/src/cosmofy/bundler.py @@ -24,7 +24,6 @@ # pkg from .args import Args -from .args import COSMOFY_PYTHON_URL from .updater import download from .updater import download_if_newer from .updater import move_executable @@ -156,18 +155,18 @@ def from_cache( self, src: Path, dest: Path, archive: Optional[ZipFile2] = None ) -> ZipFile2: """Copy the archive from cache.""" - log.debug(f"{self.banner}download (if newer): {COSMOFY_PYTHON_URL}") + log.debug(f"{self.banner}download (if newer): {self.args.python_url}") if self.args.for_real: - download_if_newer(COSMOFY_PYTHON_URL, src) + download_if_newer(self.args.python_url, src) self.fs_copy(src, dest) return archive or _archive(dest) def from_download(self, dest: Path, archive: Optional[ZipFile2] = None) -> ZipFile2: """Download archive.""" - log.debug(f"{self.banner}download (fresh): {COSMOFY_PYTHON_URL} to {dest}") + log.debug(f"{self.banner}download (fresh): {self.args.python_url} to {dest}") if self.args.for_real: - download(COSMOFY_PYTHON_URL, dest) + download(self.args.python_url, dest) return archive or _archive(dest) def setup_temp(self) -> Tuple[Path, Optional[ZipFile2]]: diff --git a/test/test_bundler.py b/test/test_bundler.py index f370863..64996e4 100644 --- a/test/test_bundler.py +++ b/test/test_bundler.py @@ -18,7 +18,7 @@ # pkg from cosmofy import bundler from cosmofy.args import Args -from cosmofy.args import COSMOFY_PYTHON_URL +from cosmofy.args import DEFAULT_PYTHON_URL from cosmofy.bundler import _archive from cosmofy.bundler import _pack_uint32 from cosmofy.bundler import Bundler @@ -127,7 +127,7 @@ def test_from_download() -> None: with patch("cosmofy.bundler.download") as mock: real.from_download(dest) - mock.assert_called_once_with(COSMOFY_PYTHON_URL, dest) + mock.assert_called_once_with(DEFAULT_PYTHON_URL, dest) def test_setup_temp() -> None: