Skip to content

Commit

Permalink
Move Common.java to com.chaquo.python.internal, and exclude it from j…
Browse files Browse the repository at this point in the history
…avadoc:

Previous method of using @deprecated caused warnings everywhere it was used.
  • Loading branch information
mhsmith committed Aug 5, 2023
1 parent 1b95380 commit 4910b84
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
run: |
(
echo "versions<<EOF"
target/list-versions.py --short
target/list-versions.py --minor
echo EOF
) >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Download Android Python builds
run: |
cd target
for version in $(./list-versions.py --long); do
for version in $(./list-versions.py --build); do
target_dir=../maven/com/chaquo/python/target/$version
./download-target.sh $target_dir
./unpackage-target.sh prefix $target_dir
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY product/buildSrc product/buildSrc

# The cmake version should match sdkCmakeDir in product/runtime/build.gradle.
RUN platform_ver=$(grep COMPILE_SDK_VERSION \
product/buildSrc/src/main/java/com/chaquo/python/Common.java \
product/buildSrc/src/main/java/com/chaquo/python/internal/Common.java \
| sed 's|.* = \(.*\);.*|\1|'); \
yes | android-sdk/cmdline-tools/tools/bin/sdkmanager \
"cmake;3.6.4111459" "platforms;android-$platform_ver"
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

target_dir=maven/com/chaquo/python/target
common_java="product/buildSrc/src/main/java/com/chaquo/python/Common.java"
common_java="product/buildSrc/src/main/java/com/chaquo/python/internal/Common.java"
extract_string='s/.*"(.*)".*/\1/'
python_version=$(grep "PYTHON_VERSION =" $common_java | sed -E "$extract_string")
build=$(grep "PYTHON_BUILD_NUM =" $common_java | sed -E "$extract_string")
Expand Down
4 changes: 2 additions & 2 deletions product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This file contains instructions for building and testing Chaquopy.
# Build prerequisites

* A local Python installation for each Python major.minor version suported by Chaquopy
(list them with `target/list-versions.py --short`). These must be on the PATH as
(list them with `target/list-versions.py --minor`). These must be on the PATH as
`pythonX.Y` on Unix, or `py -X.Y` on Windows.
* On Linux, install them from your distribution, or use Miniconda.
* On Mac and Windows, download them from https://python.org/.
Expand All @@ -22,7 +22,7 @@ This file contains instructions for building and testing Chaquopy.
* CMake: version from `sdkCmakeDir` in runtime/build.gradle.
* NDK (side by side): version from `ndkDir` in runtime/build.gradle.
* SDK Platform: version from `COMPILE_SDK_VERSION` in
buildSrc/src/main/java/com/chaquo/python/Common.java.
buildSrc/src/main/java/com/chaquo/python/internal/Common.java.

* JDK version 8. Create a `local.properties` file in `product` (i.e. the same directory
as this README), setting the JDK location as follows:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.chaquo.python;
package com.chaquo.python.internal;

import java.util.*;


/** @deprecated internal use */
public class Common {
// This should match api_level in target/build-common.sh.
public static final int MIN_SDK_VERSION = 21;
Expand Down
3 changes: 2 additions & 1 deletion product/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.chaquo.python.Common;
import com.chaquo.python.internal.Common;

apply plugin: 'java-gradle-plugin'
apply plugin: 'groovy'
Expand Down Expand Up @@ -66,6 +66,7 @@ Task testPythonTask(String name, String version, Closure closure) {
}
args "-m", "unittest"
if (project.hasProperty("testPythonArgs")) {
args "-v"
args project.testPythonArgs.split(" ")
} else {
args "discover", "-v"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.json.*
import java.nio.file.*
import java.security.MessageDigest

import static com.chaquo.python.Common.assetZip;
import com.chaquo.python.internal.*
import static com.chaquo.python.internal.Common.assetZip;
import static java.nio.file.StandardCopyOption.*


Expand Down
26 changes: 9 additions & 17 deletions product/gradle-plugin/src/test/integration/test_gradle_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,17 @@
with open(f"{product_dir}/local.properties") as props_file:
product_props = PropertiesFile.load(props_file)

DEFAULT_PYTHON_VERSION = None
PYTHON_VERSIONS = {}
for line in open(f"{product_dir}/buildSrc/src/main/java/com/chaquo/python/Common.java"):
match = re.search(r'DEFAULT_PYTHON_VERSION = "(.+)"', line)
if match:
DEFAULT_PYTHON_VERSION = match[1]

match = re.search(r'PYTHON_VERSIONS.put\("(.+)", ".+"\)', line)
if match:
full_version = match[1]
version = full_version.rpartition(".")[0]
PYTHON_VERSIONS[version] = full_version

if not DEFAULT_PYTHON_VERSION:
raise Exception("Failed to find DEFAULT_PYTHON_VERSION")
def list_versions(mode):
return run([f"{repo_root}/target/list-versions.py", f"--{mode}"],
check=True, capture_output=True, text=True).stdout.strip()

DEFAULT_PYTHON_VERSION = list_versions("default")
assert DEFAULT_PYTHON_VERSION == "3.8"

if not PYTHON_VERSIONS:
raise Exception("Failed to find PYTHON_VERSIONS")
PYTHON_VERSIONS = {}
for full_version in list_versions("micro").splitlines():
version = full_version.rpartition(".")[0]
PYTHON_VERSIONS[version] = full_version
assert list(PYTHON_VERSIONS) == ["3.8", "3.9", "3.10", "3.11"]
DEFAULT_PYTHON_VERSION_FULL = PYTHON_VERSIONS[DEFAULT_PYTHON_VERSION]

Expand Down
3 changes: 2 additions & 1 deletion product/runtime/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.chaquo.python.Common;
import com.chaquo.python.internal.Common;

group = "com.chaquo.python.runtime"

Expand Down Expand Up @@ -143,6 +143,7 @@ task("doc", group: "documentation")
javadoc {
destinationDir = file("$docsDir/java")
title "Chaquopy Java API"
exclude "com/chaquo/python/internal/**"
options {
addStringOption("source", "8")
addBooleanOption("Xdoclint:all,-missing", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.res.*;
import android.os.*;
import com.chaquo.python.*;
import com.chaquo.python.internal.*;
import java.io.*;
import java.util.*;
import org.jetbrains.annotations.*;
Expand Down
2 changes: 1 addition & 1 deletion product/runtime/src/main/python/java/android/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from java._vendor.elftools.elf.elffile import ELFFile

from android.os import Build
from com.chaquo.python import Common
from com.chaquo.python.android import AndroidPlatform
from com.chaquo.python.internal import Common


def initialize(context, build_json, app_path):
Expand Down
21 changes: 12 additions & 9 deletions target/list-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
parser = argparse.ArgumentParser()
mode_group = parser.add_mutually_exclusive_group(required=True)
mode_group.add_argument("--default", action="store_true")
mode_group.add_argument("--short", action="store_true")
mode_group.add_argument("--long", action="store_true")
mode_group.add_argument("--minor", action="store_true")
mode_group.add_argument("--micro", action="store_true")
mode_group.add_argument("--build", action="store_true")
args = parser.parse_args()

product_dir = abspath(f"{dirname(__file__)}/../product")
lines = []
for line in open(f"{product_dir}/buildSrc/src/main/java/com/chaquo/python/Common.java"):
for line in open(
f"{product_dir}/buildSrc/src/main/java/com/chaquo/python/internal/Common.java"
):
if args.default:
match = re.search(r'DEFAULT_PYTHON_VERSION = "(.+)"', line)
if match:
Expand All @@ -23,12 +26,12 @@
match = re.search(r'PYTHON_VERSIONS.put\("(\d+)\.(\d+)\.(\d+)", "(\d+)"\)', line)
if match:
major, minor, micro, build = match.groups()
if args.short:
lines.append(f"{major}.{minor}")
elif args.long:
lines.append(f"{major}.{minor}.{micro}-{build}")
else:
raise AssertionError()
version = f"{major}.{minor}"
if args.micro or args.build:
version += f".{micro}"
if args.build:
version += f"-{build}"
lines.append(version)

assert lines
print("\n".join(lines))
14 changes: 5 additions & 9 deletions target/python/build-and-package.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/bash
set -eu -o pipefail
shopt -s inherit_errexit

recipe_dir=$(dirname $(realpath $0))
recipe_dir=$(cd $(dirname $0) && pwd)
version_short=${1:?}

cd $recipe_dir/..

common_java="../product/buildSrc/src/main/java/com/chaquo/python/Common.java"
common_line=$(grep "PYTHON_VERSIONS.put(\"$version_short" $common_java)
read micro build < \
<(echo $common_line | sed -E "s/.*\"$version_short.([0-9]+)\", \"([0-9]+)\".*/\1 \2/")
version=$version_short.$micro
version_micro=$(./list-versions.py --micro | grep "^$version_short\.")
version_build=$(./list-versions.py --build | grep "^$version_short\.")

./for-each-abi.sh python/build.sh $version
./package-target.sh prefix ../maven/com/chaquo/python/target/$version-$build
./for-each-abi.sh python/build.sh $version_micro
./package-target.sh prefix ../maven/com/chaquo/python/target/$version_build

0 comments on commit 4910b84

Please sign in to comment.