Skip to content
Merged
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
212 changes: 157 additions & 55 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,164 @@ skip_commits:
- "*.md"

environment:
FLUTTER_MACOS_URL: https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.10.3-stable.zip
PYTHON_STACK: python 3.10
FLUTTER_MACOS_URL: https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.10.5-stable.zip
GITHUB_TOKEN:
secure: doX0dwjWhBmT56aJqR9NCbtMFJpDpdYxPCIB4vQoHfSR+nTa+pLCo6Yv5qWpD/90

matrix:
- job_name: Build Python for iOS
job_group: build_python
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey

- job_name: Build Python for Android
job_group: build_python
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004

- job_name: Publish serious_python package to pub.dev
job_group: publish_package
job_depends_on: build_python
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004

stack:
- python 3.10

install:
# update build version
- ps: |
if ($env:APPVEYOR_REPO_TAG_NAME) {
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
} else {
$cv = [version](git describe --abbrev=0).substring(1)
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
}
Update-AppveyorBuild -Version $v

# install Flutter
- HOMEBREW_NO_AUTO_UPDATE=1 brew install cocoapods
- curl $FLUTTER_MACOS_URL -o "$HOME/flutter_macos_stable.zip"
- unzip -qq "$HOME/flutter_macos_stable.zip" -d $HOME
- export PATH="$PATH:$HOME/flutter/bin"
- flutter config --enable-macos-desktop
- flutter doctor

# install Kivy toolchain
- pip3 install kivy-ios
- HOMEBREW_NO_AUTO_UPDATE=1 brew install autoconf automake libtool pkg-config
- brew link libtool

build_script:
# build Python 3
- toolchain build python3
- ls dist
- sh: |
DIST_FILE_NAME=dist/python-ios-dist-v$APPVEYOR_BUILD_VERSION.tar.gz
tar -czvf $DIST_FILE_NAME dist/*
appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist

# publish package
- sh: |
if [[ "$APPVEYOR_REPO_TAG_NAME" != "" ]]; then
mkdir -p $HOME/Library/Application\ Support/dart
echo $PUB_DEV_TOKEN | base64 --decode > $HOME/Library/Application\ Support/dart/pub-credentials.json
dart pub publish --force
elif [[ "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
dart pub publish --dry-run
fi

deploy:
provider: GitHub
auth_token: $(GITHUB_TOKEN)
release: $(APPVEYOR_REPO_TAG_NAME)
artifact: python-dist
on:
APPVEYOR_REPO_TAG: true

test: off
- $PYTHON_STACK

for:
# ======================================
# Build Python for iOS
# ======================================

- matrix:
only:
- job_name: Build Python for iOS

install:
# update build version
- ps: |
if ($env:APPVEYOR_REPO_TAG_NAME) {
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
} else {
$cv = [version](git describe --abbrev=0).substring(1)
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
}
Update-AppveyorBuild -Version $v

# install Kivy toolchain
- pip3 install kivy-ios
- HOMEBREW_NO_AUTO_UPDATE=1 brew install autoconf automake libtool pkg-config
- brew link libtool

build_script:
# build Python 3
- toolchain build python3
- ls dist

# remove hostpython
- rm -rf dist/hostpython3

# package the rest of dist
- DIST_FILE_NAME=dist/python-ios-dist-v$APPVEYOR_BUILD_VERSION.tar.gz
- tar -czvf $DIST_FILE_NAME dist/*
- appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist-macos

deploy:
provider: GitHub
auth_token: $(GITHUB_TOKEN)
release: $(APPVEYOR_REPO_TAG_NAME)
artifact: python-dist-macos
on:
APPVEYOR_REPO_TAG: true

test: off

# ======================================
# Build Python for Android
# ======================================

- matrix:
only:
- job_name: Build Python for Android

install:
# update build version
- ps: |
if ($env:APPVEYOR_REPO_TAG_NAME) {
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
} else {
$cv = [version](git describe --abbrev=0).substring(1)
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
}
Update-AppveyorBuild -Version $v

# install NDK
- export ANDROID_SDK_ROOT="/usr/lib/android-sdk"
- export NDK_VERSION=25.2.9519653
- export SDK_VERSION=android-33
- echo "y" | sdkmanager --install "ndk;$NDK_VERSION" --channel=3 > /dev/null
- echo "y" | sdkmanager --install "platforms;$SDK_VERSION" > /dev/null

# install Kivy for Android
- pip3 install python-for-android
- pip3 install --upgrade cython
- p4a --help
- p4a create --requirements python3 --arch arm64-v8a --arch armeabi-v7a --arch x86_64 --sdk-dir $ANDROID_SDK_ROOT --ndk-dir $ANDROID_SDK_ROOT/ndk/$NDK_VERSION --dist-name serious_python

# package
- BUNDLE_NAME=libpythonbundle.so

# arm64-v8a
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__arm64-v8a/_python_bundle
- zip -r $BUNDLE_NAME .
- mv $BUNDLE_NAME ../../libs/arm64-v8a
- popd

# armeabi-v7a
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__armeabi-v7a/_python_bundle
- zip -r $BUNDLE_NAME .
- mv $BUNDLE_NAME ../../libs/armeabi-v7a
- popd

# armeabi-v7a
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__x86_64/_python_bundle
- zip -r $BUNDLE_NAME .
- mv $BUNDLE_NAME ../../libs/x86_64
- popd

# package all .so files
- DIST_FILE_NAME=python-android-dist-v$APPVEYOR_BUILD_VERSION.zip
- pushd ~/.local/share/python-for-android/dists/serious_python/libs
- zip -r $DIST_FILE_NAME .
- appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist-android
- popd

deploy:
provider: GitHub
auth_token: $(GITHUB_TOKEN)
release: $(APPVEYOR_REPO_TAG_NAME)
artifact: python-dist-android
on:
APPVEYOR_REPO_TAG: true

# =========================================
# Publish serious_python package to pub.dev
# =========================================

- matrix:
only:
- job_name: Publish serious_python package to pub.dev

install:
- flutter upgrade --force

build_script:
# publish package
- sh: |
if [[ "$APPVEYOR_REPO_TAG_NAME" != "" ]]; then
mkdir -p $HOME/Library/Application\ Support/dart
echo $PUB_DEV_TOKEN | base64 --decode > $HOME/Library/Application\ Support/dart/pub-credentials.json
dart pub publish --force
elif [[ "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
dart pub publish --dry-run
fi

test: off
33 changes: 33 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: 796c8ef79279f9c774545b3771238c3098dbefab
channel: stable

project_type: plugin_ffi

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: android
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: ios
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0

Android support.

## 0.1.5

* SeriousPython.run() should be split into two methods to return temp dir with unpacked python app ([#6](https://github.com/flet-dev/serious-python/issues/6)).
Expand Down
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributing to `serious_python`

## Releasing a new version

Bump version in:

* `pubspec.yaml`
* `android/build.gradle`
* `ios/serious_python.podspec`

Bump `serious_python` dependency version with `flutter pub get` in example lock files:

* `example/flet_example/pubspec.lock`
* `example/flask_example/pubspec.lock`
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Build app backend service in Python and host it inside a Flutter app. Flutter ap

Serious Python is part of [Flet](https://flet.dev) project - the fastest way to build Flutter apps in Python. The motivation for building Serious Python was having a re-usable easy-to-use plugin, maintained and supported, to run real-world Python apps, not just "1+2" or "hello world" examples, on iOS or Android devices and hence the name "Serious Python".

Serious Python relies on [Kivy toolchain for iOS](https://github.com/kivy/kivy-ios) to build Python runtime and native packages.

## Platform Support

| iOS | Android |
| iOS | Android |
| :-----: | :----------: |
| ✅ | Coming soon |
| ✅ | |

### Python versions

iOS version of plugin is based on [Kivy toolchain](https://github.com/kivy/kivy-ios) and currently uses Python 3.10.10.

Android version of plugin is based on [Kivy python-for-android](https://github.com/kivy/python-for-android) and currently uses Python 3.10.10.

## Usage

Zip your Python app into `app.zip`, copy to `app` (or any other) directory in the root of your Flutter app and add it as an asset to `pubspec.yaml`:
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

analyzer:
exclude: [lib/src/android/gen.dart]
10 changes: 10 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
/src/main/jniLibs
73 changes: 73 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
group 'com.flet.serious_python'
version '0.2.0'

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
// The Android Gradle Plugin knows how to build native code with the NDK.
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'de.undercouch:gradle-download-task:4.1.2'
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'de.undercouch.download'

android {
// Bumping the plugin compileSdkVersion requires all clients of this plugin
// to bump the version in their app.
compileSdkVersion 31

// Bumping the plugin ndkVersion requires all clients of this plugin to bump
// the version in their app and to download a newer version of the NDK.
ndkVersion "23.1.7779620"

// Invoke the shared CMake build with the Android Gradle Plugin.
externalNativeBuild {
cmake {
path "../src/CMakeLists.txt"

// The default CMake version for the Android Gradle Plugin is 3.10.2.
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
//
// The Flutter tooling requires that developers have CMake 3.10 or later
// installed. You should not increase this version, as doing so will cause
// the plugin to fail to compile for some customers of the plugin.
// version "3.10.2"
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
}
}

import de.undercouch.gradle.tasks.download.Download

task downloadZipFile(type: Download) {
src "https://github.com/flet-dev/serious-python/releases/download/v${version}/python-android-dist-v${version}.zip"
dest new File(buildDir, "python-android-dist-v${version}.zip")
}

task unzipFile(dependsOn: downloadZipFile, type: Copy) {
from zipTree(downloadZipFile.dest)
into 'src/main/jniLibs'
}

preBuild.dependsOn unzipFile
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'serious_python'
Loading