Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework v2 #13

Merged
merged 5 commits into from
Nov 23, 2022
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
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"formal_name": "App Name",
"app_name": "{{ cookiecutter.formal_name|lower|replace(' ', '-') }}",
"class_name": "{{ cookiecutter.formal_name.title().replace(' ','').replace('-','').replace('!','').replace('.','').replace(',','') }}",
"module_name": "{{ cookiecutter.app_name|replace('-', '_') }}",
"author": "Example Corporation",
"bundle": "com.example",
Expand Down
12 changes: 9 additions & 3 deletions {{ cookiecutter.formal_name }}/briefcase.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Generated using Python {{ cookiecutter.python_version }}
[paths]
app_path = "{{ cookiecutter.app_name }}/app"
app_packages_path = "{{ cookiecutter.app_name }}/app_packages"
app_path = "{{ cookiecutter.class_name }}/app"
app_packages_path = "{{ cookiecutter.class_name }}/app_packages"
info_plist_path = "{{ cookiecutter.class_name }}/{{ cookiecutter.class_name }}-Info.plist"
support_path = "Support"
{{ {"3.8": "support_revision = 12", "3.9": "support_revision = 10", "3.10": "support_revision = 6", "3.11": "support_revision = 1"}.get(cookiecutter.python_version|py_tag, "") }}
{{ {
"3.8": "support_revision = 12",
"3.9": "support_revision = 10",
"3.10": "support_revision = 6",
"3.11": "support_revision = 1"
}.get(cookiecutter.python_version|py_tag, "") }}

icon.20 = "{{ cookiecutter.app_name }}/Images.xcassets/AppIcon.appiconset/icon-20.png"
icon.29 = "{{ cookiecutter.app_name }}/Images.xcassets/AppIcon.appiconset/icon-29.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ int main(int argc, char *argv[]) {
PyStatus status;
PyConfig config;
NSString *python_home;
NSString *app_module_name;
NSString *path;
NSString *traceback_str;
wchar_t *wapp_module_name;
wchar_t *wtmp_str;
const char* app_module_str;
const char* nslog_script;
PyObject *app_module;
PyObject *module;
Expand All @@ -40,9 +41,6 @@ int main(int argc, char *argv[]) {
PyConfig_InitIsolatedConfig(&config);

// Configure the Python interpreter:
// Run at optimization level 1
// (remove assertions, set __debug__ to False)
config.optimization_level = 1;
// Don't buffer stdio. We want output to appears in the log immediately
config.buffered_stdio = 0;
// Don't write bytecode; we can't modify the app bundle
Expand All @@ -63,9 +61,13 @@ int main(int argc, char *argv[]) {
}
PyMem_RawFree(wtmp_str);

// Set the app module name
wapp_module_name = Py_DecodeLocale("{{ cookiecutter.module_name }}", NULL);
status = PyConfig_SetString(&config, &config.run_module, wapp_module_name);
// Determine the app module name
app_module_name = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MainModule"];
if (app_module_name == NULL) {
NSLog(@"Unable to identify app module name.");
}
app_module_str = [app_module_name UTF8String];
status = PyConfig_SetBytesString(&config, &config.run_module, app_module_str);
if (PyStatus_Exception(status)) {
crash_dialog([NSString stringWithFormat:@"Unable to set app module name: %s", status.err_msg, nil]);
PyConfig_Clear(&config);
Expand Down Expand Up @@ -189,7 +191,7 @@ int main(int argc, char *argv[]) {
// pymain_run_module() method); we need to re-implement it
// because we need to be able to inspect the error state of
// the interpreter, not just the return code of the module.
NSLog(@"Running app module: {{ cookiecutter.module_name }}");
NSLog(@"Running app module: %@", app_module_name);
module = PyImport_ImportModule("runpy");
if (module == NULL) {
crash_dialog(@"Could not import runpy module");
Expand All @@ -202,7 +204,7 @@ int main(int argc, char *argv[]) {
exit(-3);
}

app_module = PyUnicode_FromWideChar(wapp_module_name, wcslen(wapp_module_name));
app_module = PyUnicode_FromString(app_module_str);
if (app_module == NULL) {
crash_dialog(@"Could not convert module name to unicode");
exit(-3);
Expand All @@ -214,6 +216,10 @@ int main(int argc, char *argv[]) {
exit(-4);
}

// Print a separator to differentiate Python startup logs from app logs
NSLog(@"---------------------------------------------------------------------------");

// Invoke the app module
result = PyObject_Call(module_attr, method_args, NULL);

if (result == NULL) {
Expand Down Expand Up @@ -277,8 +283,6 @@ int main(int argc, char *argv[]) {
@finally {
Py_Finalize();
}

PyMem_RawFree(wapp_module_name);
}

exit(ret);
Expand All @@ -292,7 +296,6 @@ int main(int argc, char *argv[]) {
void crash_dialog(NSString *details) {
NSLog(@"Application has crashed!");
NSLog(@"========================\n%@", details);

// TODO - acutally make this a dialog
// NSString *full_message = [NSString stringWithFormat:@"An unexpected error occurred.\n%@", details];
// // Create a stack trace dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MainModule</key>
<string>{{ cookiecutter.module_name }}</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
610000000000000000100200 /* app_packages */ = {isa = PBXFileReference; lastKnownFileType = folder; path = app_packages; sourceTree = "<group>"; };
610000000000000000100300 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
610000000000000000100400 /* {{ cookiecutter.formal_name }}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "{{ cookiecutter.formal_name }}.app"; sourceTree = BUILT_PRODUCTS_DIR; };
610000000000000000100500 /* {{ cookiecutter.app_name }}-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "{{ cookiecutter.app_name }}-Info.plist"; sourceTree = "<group>"; };
610000000000000000100500 /* {{ cookiecutter.class_name }}-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "{{ cookiecutter.class_name }}-Info.plist"; sourceTree = "<group>"; };
610000000000000000100600 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
610000000000000000100700 /* {{ cookiecutter.app_name }}-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "{{ cookiecutter.app_name }}-Prefix.pch"; sourceTree = "<group>"; };
610000000000000000100700 /* {{ cookiecutter.class_name }}-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "{{ cookiecutter.class_name }}-Prefix.pch"; sourceTree = "<group>"; };
610000000000000000100800 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
610000000000000000100900 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -60,7 +60,7 @@
children = (
60A04BC228B35E9F00DAA9E5 /* Support */,
60A04BC528B35ED400DAA9E5 /* Python.xcframework */,
60796EEB19190F4100A9926B /* {{ cookiecutter.app_name }} */,
60796EEB19190F4100A9926B /* {{ cookiecutter.class_name }} */,
60796EE419190F4100A9926B /* Frameworks */,
60796EE319190F4100A9926B /* Products */,
);
Expand All @@ -85,23 +85,23 @@
name = Frameworks;
sourceTree = "<group>";
};
60796EEB19190F4100A9926B /* {{ cookiecutter.app_name }} */ = {
60796EEB19190F4100A9926B /* {{ cookiecutter.class_name }} */ = {
isa = PBXGroup;
children = (
610000000000000000100100 /* app */,
610000000000000000100200 /* app_packages */,
610000000000000000100800 /* Images.xcassets */,
60796EEC19190F4100A9926B /* Supporting Files */,
);
path = {{ cookiecutter.app_name }};
path = "{{ cookiecutter.class_name }}";
sourceTree = "<group>";
};
60796EEC19190F4100A9926B /* Supporting Files */ = {
isa = PBXGroup;
children = (
610000000000000000100300 /* main.m */,
610000000000000000100500 /* {{ cookiecutter.app_name }}-Info.plist */,
610000000000000000100700 /* {{ cookiecutter.app_name }}-Prefix.pch */,
610000000000000000100500 /* {{ cookiecutter.class_name }}-Info.plist */,
610000000000000000100700 /* {{ cookiecutter.class_name }}-Prefix.pch */,
60796EEE19190F4100A9926B /* InfoPlist.strings */,
610000000000000000100900 /* Launch Screen.storyboard */,
);
Expand Down Expand Up @@ -357,9 +357,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ENABLE_BITCODE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "{{ cookiecutter.app_name }}/{{ cookiecutter.app_name }}-Prefix.pch";
INFOPLIST_FILE = "{{ cookiecutter.app_name }}/{{ cookiecutter.app_name }}-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
GCC_PREFIX_HEADER = "{{ cookiecutter.class_name }}/{{ cookiecutter.class_name }}-Prefix.pch";
INFOPLIST_FILE = "{{ cookiecutter.class_name }}/{{ cookiecutter.class_name }}-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -377,9 +377,9 @@
ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "{{ cookiecutter.app_name }}/{{ cookiecutter.app_name }}-Prefix.pch";
INFOPLIST_FILE = "{{ cookiecutter.app_name }}/{{ cookiecutter.app_name }}-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
GCC_PREFIX_HEADER = "{{ cookiecutter.class_name }}/{{ cookiecutter.class_name }}-Prefix.pch";
INFOPLIST_FILE = "{{ cookiecutter.class_name }}/{{ cookiecutter.class_name }}-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down