beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.48k stars 352 forks source link

Write a PyCharm plugin #1450

Open mzdk100 opened 9 months ago

mzdk100 commented 9 months ago

What is the problem or limitation you are having?

There are two main issues:

  1. I hope to add build plugins that PyCharm can use instead of using CMD to build, as PyCharm is more efficient in writing code.
  2. I hope to remove the code templates related to the platform from the build directory, as it is usually necessary to add the build directory to the .gitignore file. If the code templates are also excluded, it will result in modifications to the code templates that cannot be managed by VCS. For example, I need to modify the Android template and add some third-party dependency libraries to the build.gradle file. As there are relatively few existing Python libraries available for mobile devices, I need to use some third-party jars to expand the functionality and use rubicon-java to call in the Python layer.

Describe the solution you'd like

  1. I hope to add a build plugin for PyCharm.
  2. I hope to modify the storage directory of the code template.

Describe alternatives you've considered

There is currently no solution for the first problem; The second issue can be implemented using the sub module of Git, but it is not elegant enough, and the build directory often needs to be cleaned, so I will not choose this solution either.

Additional context

See #1451 for an equivalent request for VSCode.

freakboy3742 commented 9 months ago

While I don't use PyCharm myself, I'm fully in favor of someone writing a plugin to make writing and debugging BeeWare apps in PyCharm easier.

However, it's not entirely clear what you're asking for regarding the build directory.

The code that is in the build directory isn't a template - it's the output of a template. And it's called the build directory specifically because it should be considered ephemeral, and therefore be in your .gitignore folder. The name was chosen specifically because of the Python ecosystem convention for using build as a folder that isn't committed to version control.

Admittedly, that's a "pure" perspective of the app development perspective. I understand that in practice, it is sometimes necessary to modify the code in the build folder that has been generated. However, we're not going to make radical changes to project layout to accomodate a use case that shouldn't (in theory, at least) exist.

We will, however, entertain ideas that allow configuration changes to be defined in pyproject.toml and applied to projects - even if those configuration items are platform specific. For example, we added the build-gradle-extra-content configuration setting so that you can inject arbirtrary gradle content into the end of your projects' gradle file. If you've got a specific use case for adding extra third-party libraries that isn't supported by build-gradle-extra-content, or could be expressed more elegantly with a specific feature, that's definitely something we'd consider adding.

And - strictly - you don't even need to wait for us to add it. Any variable defined in your pyproject.toml file will be passed as context to the template at time of rendering; and you can fork the default Briefcase template and use that fork in your own project. If you define a template = "https://github.com/... setting, Briefcase will use that template rather than the default Android template, so you can modify the template to include whatever you want; if your template uses a extra_libs property, you could define extra_libs in your pyproject.toml, and that content would be available when you build your app.

mzdk100 commented 9 months ago

Due to some Python binary dependency libraries not being available on Android, many times I need to compile so libraries or add Java code files myself, using Rubicon Java for bridging; But as you said, we usually should not directly modify the build directory, but Android's native code files and resource files are all in the build directory. If modified, they may be deleted inadvertently, leading to significant losses; What I want to achieve is the ability to reliably save my modifications to Android native code, which can be managed using VCS; The solution you provided may be to derive the default template for Briefcase and write the code in your own template; But the problem with this is that I need to use two git repositories to manage the entire project (application template and main project), and this is only for the Android platform. If it also includes Windows and Mac OS X, it is very expensive and not elegant enough. So I really hope we can redesign this construction method, because there are really few py libraries available for mobile devices now, and many times we need to build our own wheels. For example, media playback, cameras, sensors, and so on. Finally, regarding PyCharm, I also gave feedback to JetBrains, 'I hope you can support BeeWare'. However, this will take time, and I also hope that we can implement such a plugin ourselves. At least I really need it now, but unfortunately, I don't know how to develop such a plugin yet. I hope that Briefcase can also put it on the agenda as soon as possible. Thanks!

------------------ 原始邮件 ------------------ 发件人: "Russell @.>; 发送时间: 2023年9月13日(星期三) 上午7:32 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [beeware/briefcase] Write a PyCharm plugin (Issue #1450)

虽然我自己不使用PyCharm,但我完全赞成有人编写一个插件,使在PyCharm中编写和调试BeeWare应用程序更容易。

然而,它并不完全清楚你所要求的关于建造目录下。

中的代码:建造目录不是模板——它是输出属于一个模板。它被称为建造目录,特别是因为它应该被认为是短暂的,因此在你的.gitignore文件夹中。之所以特别选择这个名字,是因为Python生态系统中使用建造作为未提交到版本控制的文件夹。

无可否认,这是应用开发视角中的“纯”视角。我了解,在实际应用中,有时候需要对已经生成的build文件夹中的代码进行修改。然而,我们不打算对项目布局进行根本性的更改,以适应这样一个用例:不应该(至少在理论上)存在。

我们将,但是,考虑允许在中定义配置更改的想法投影并应用于项目——即使那些配置项是平台特定的。例如,我们添加了累积额外含量配置设置,以便您可以在项目的gradle文件末尾注入a birt ary gradle内容。如果你有一个特定的用例,需要添加额外的第三方库,而这些库不受累积额外含量,或者可以用一个特定的功能来更优雅地表达,这绝对是我们会考虑添加的东西。

而且——严格地说——你甚至不需要等待我们添加它。中定义的任何变量,你的投影文件将在呈现时作为上下文传递给模板;您可以派生默认的公文包模板,并在您自己的项目中使用该派生。如果定义了一个模板=“https://github.com/...设置,公文包将使用该模板,而不是默认的Android模板,所以你可以修改模板,以包括任何你想要的;如果你的模板使用了一个额外_库属性,您可以定义额外_库在你的投影,当您构建页面时,这些内容将是可用的

— 直接回复此邮件,在GitHub上查看,或取消订阅. @.***与>.

mhsmith commented 9 months ago

I believe all the things you mentioned can be done using the build_gradle_extra_content setting. In each case, after changing the setting, run briefcase create android to copy it into your project.

Due to some Python binary dependency libraries not being available on Android, many times I need to compile so libraries

If you've built some wheels using the Chaquopy build tool, you can use them like this:

build_gradle_extra_content = """
android.defaultConfig.python.pip.options "--extra-index-url", "path/to/dist"
"""

... where path/to/dist is the location of your wheel files, with one subdirectory per package.

use some third-party jars

build_gradle_extra_content = """
dependencies.implementation fileTree(dir: 'path/to/libs', include: ['*.jar'])
"""

or add Java code files myself

build_gradle_extra_content = """
android.sourceSets.main.java.srcDir "path/to/source"
"""

All of these paths are relative to the directory containing the build.gradle file, so you can prefix them with some number of ../ to refer to another location in your project.

And of course, if you want to do more than one of these things, just concatenate them within the build_gradle_extra_content triple quotes. Anything that can go in a build.gradle file can go in there.

mzdk100 commented 9 months ago

Okay, I'll read the briefcase documentation again to familiarize myself with this toolkit in more detail.

------------------ 原始邮件 ------------------ 发件人: "Malcolm @.>; 发送时间: 2023年9月13日(星期三) 下午4:41 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [beeware/briefcase] Write a PyCharm plugin (Issue #1450)

I believe all the things you mentioned can be done using the build_gradle_extra_content setting. In each case, after changing the setting, run briefcase create android to copy it into your project.

Due to some Python binary dependency libraries not being available on Android, many times I need to compile so libraries

If you've built some wheels using the Chaquopy build tool, you can use them like this: build_gradle_extra_content = """ android.defaultConfig.python.pip.options "--extra-index-url", "path/to/dist" """
... where path/to/dist is the location of your wheel files, with one subdirectory per package.

use some third-party jars build_gradle_extra_content = """ dependencies.implementation fileTree(dir: 'path/to/libs', include: ['*.jar']) """
or add Java code files myself build_gradle_extra_content = """ android.sourceSets.main.java.srcDir "path/to/source" """
All of these paths are relative to the directory containing the build.gradle file, so you can prefix them with some number of ../ to refer to another location in your project.

And of course, if you want to do more than one of these things, just concatenate them within the build_gradle_extra_content triple quotes. Anything that can go in a build.gradle file can go in there.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>