Skip to content

Commit 4afe9e9

Browse files
Changes for v0.1.1 (#2)
* Small corrections to docs and podspec * Hide package implementation behind `src` * Set current dir before running Python program * Flet example added * Added `--pre` flag * Flet example * Version bump to 0.1.1, added docs, static methods
1 parent 9c3173b commit 4afe9e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2469
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.1.1
2+
3+
* Fixed issue with setting current directory on Python start.
4+
* Added `--pre` flag to `serious_python:main` CLI.
5+
* Added Flet example.
6+
* Hid internal implementation behind `src` dir.
7+
18
## 0.1.0
29

310
* Initial release of `serious_python` with iOS support.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,29 @@ platform :ios, '12.0'
4444
Create an instance of `SeriousPython` class and call its `run()` method:
4545

4646
```dart
47-
SeriousPython().run("app/app.zip");
47+
SeriousPython.run("app/app.zip");
4848
```
4949

5050
When the app starts the archive is unpacked to a temporary directory and Serious Python plugin will try to run `main.py` in the root of the archive. Current directory is changed to a temporary directory.
5151

5252
If your Python app has a different entry point it could be specified with `appFileName` parameter:
5353

5454
```dart
55-
SeriousPython().run("app/app.zip", appFileName: "my_app.py");
55+
SeriousPython.run("app/app.zip", appFileName: "my_app.py");
5656
```
5757

5858
You can pass a map with environment variables that should be available in your Python program:
5959

6060
```dart
61-
SeriousPython().run("app/app.zip",
61+
SeriousPython.run("app/app.zip",
6262
appFileName: "my_app.py",
6363
environmentVariables: {"a": "1", "b": "2"});
6464
```
6565

6666
By default, Serious Python expects Python dependencies installed into `__pypackages__` directory in the root of app directory. You can add additional paths to look for 3rd-party packages using `modulePaths` parameter:
6767

6868
```dart
69-
SeriousPython().run("app/app.zip",
69+
SeriousPython.run("app/app.zip",
7070
appFileName: "my_app.py",
7171
modulePaths: ["/absolute/path/to/my/site-packages"]);
7272
```
@@ -99,9 +99,9 @@ Make sure generated asset is added to `pubspec.yaml`.
9999

100100
By default, embedded Python program is run in a separate thread, to avoid UI blocking. Your Flutter app is not supposed to directly call Python functions or modules, but instead it should communicate via some API provided by a Python app, such as: REST API, sockets, SQLite database, files, etc.
101101

102-
To constantly run on background a Python program must be blocking, for example a [Flask app](examples/flask_example) listening on `8000` port, or you can start your long-running computations in `threading.Thread` and use `threading.Event` to prevent program from exiting.
102+
To constantly run on background a Python program must be blocking, for example a [Flask app](example/flask_example) listening on `8000` port, or you can start your long-running computations in `threading.Thread` and use `threading.Event` to prevent program from exiting.
103103

104-
Synchronous execution of Python program is also supported with `sync: true` parameter to `SeriousPython().run()` method. For example, it could be a utility program doing some preperations, etc. Just make sure it's either very short or run in a Dart isolate to avoid blocking UI.
104+
Synchronous execution of Python program is also supported with `sync: true` parameter to `SeriousPython.run()` method. For example, it could be a utility program doing some preperations, etc. Just make sure it's either very short or run in a Dart isolate to avoid blocking UI.
105105

106106
## Supported Python packages
107107

@@ -117,7 +117,9 @@ TBD
117117

118118
## Examples
119119

120-
[Python REPL with Flask backend](examples/flask_example).
120+
[Python REPL with Flask backend](example/flask_example).
121+
122+
[Flet app](example/flet_example).
121123

122124
## Future plans
123125

bin/package_command.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class PackageCommand extends Command {
1414
final description = "Packages Python app to Flutter assets.";
1515

1616
PackageCommand() {
17+
argParser.addFlag("pre",
18+
help: "Install pre-release dependencies.", negatable: false);
1719
argParser.addOption('asset',
1820
abbr: 'a',
1921
help:
@@ -105,6 +107,12 @@ class PackageCommand extends Command {
105107
.map((d) => d.replaceAllMapped(RegExp(r'flet(\W{1,}|$)'),
106108
(match) => 'flet-embed${match.group(1)}'))
107109
.toList();
110+
111+
List<String> extraArgs = [];
112+
if (argResults?["pre"]) {
113+
extraArgs.add("--pre");
114+
}
115+
108116
final pipProcess = await Process.start(
109117
'python3',
110118
[
@@ -113,6 +121,7 @@ class PackageCommand extends Command {
113121
'install',
114122
'--isolated',
115123
'--upgrade',
124+
...extraArgs,
116125
'--target',
117126
path.join(tempDir.path, '__pypackages__'),
118127
...dependencies

example/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Examples
2+
3+
### Python REPL with Flask backend
4+
5+
An exampe of using Flask to host app backend API written in Python.
6+
7+
[Source](flask_example)
8+
9+
### Flet app
10+
11+
An example of integrating [Flet widget](https://pub.dev/packages/flet) and [Flet framework](https://pypi.org/project/flet/) to easily create awesome Flutter apps in Python.
12+
13+
[Source](flet_example)

example/flask_example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ EXTERNAL SOURCES:
2222
SPEC CHECKSUMS:
2323
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
2424
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
25-
serious_python: 8b5a9a84f9095a4a6d41fe906ed34611681e44b6
25+
serious_python: 954ab1502631a446dd28e0bacdb519e8a803a1fe
2626

2727
PODFILE CHECKSUM: 7be2f5f74864d463a8ad433546ed1de7e0f29aef
2828

example/flask_example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ void main() {
1010
}
1111

1212
void startPython() async {
13-
SeriousPython()
14-
.run("app/app.zip", environmentVariables: {"a": "1", "b": "2"});
13+
SeriousPython.run("app/app.zip", environmentVariables: {"a": "1", "b": "2"});
1514
}
1615

1716
class MyApp extends StatefulWidget {

example/flask_example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ packages:
281281
path: "../.."
282282
relative: true
283283
source: path
284-
version: "0.1.0"
284+
version: "0.1.1"
285285
sky_engine:
286286
dependency: transitive
287287
description: flutter

example/flet_example/.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.packages
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
35+
# Symbolication related
36+
app.*.symbols
37+
38+
# Obfuscation related
39+
app.*.map.json
40+
41+
# Android Studio will place build artifacts here
42+
/android/app/debug
43+
/android/app/profile
44+
/android/app/release

example/flet_example/.metadata

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: f92f44110e87bad5ff168335c36da6f6053036e6
8+
channel: stable
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: f92f44110e87bad5ff168335c36da6f6053036e6
17+
base_revision: f92f44110e87bad5ff168335c36da6f6053036e6
18+
- platform: ios
19+
create_revision: f92f44110e87bad5ff168335c36da6f6053036e6
20+
base_revision: f92f44110e87bad5ff168335c36da6f6053036e6
21+
22+
# User provided section
23+
24+
# List of Local paths (relative to this file) that should be
25+
# ignored by the migrate tool.
26+
#
27+
# Files that are not part of the templates will be ignored by default.
28+
unmanaged_files:
29+
- 'lib/main.dart'
30+
- 'ios/Runner.xcodeproj/project.pbxproj'

example/flet_example/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# flet_example
2+
3+
A new Flutter project.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
12+
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
13+
14+
For help getting started with Flutter development, view the
15+
[online documentation](https://docs.flutter.dev/), which offers tutorials,
16+
samples, guidance on mobile development, and a full API reference.

0 commit comments

Comments
 (0)