Giter Club home page Giter Club logo

briefcase-windows-visualstudio-template's Introduction

Briefcase Windows Visual Studio Template

A Cookiecutter template for building Python apps from a Visual Studio project, that can then be packaged with an MSI installer.

Using this template

The easiest way to use this project is to not use it at all - at least, not directly. Briefcase is a tool that uses this template, rolling it out using data extracted from a pyproject.toml configuration file.

However, if you do want use this template directly...

  1. Install cookiecutter. This is a tool used to bootstrap complex project templates:

    $ pip install cookiecutter
    
  2. Run cookiecutter on the template:

    $ cookiecutter https://github.com/beeware/briefcase-windows-visualstudio-template
    

    This will ask you for a number of details of your application, including the name of your application (which should be a valid PyPI identifier), and the Formal Name of your application (the full name you use to describe your app). The remainder of these instructions will assume a name of my-project, and a formal name of My Project.

  3. Build the project. You can do this by opening the solution file in Visual Studio and building the Release configuration, or by using MSBuild:

    $ MSBuild.exe "My Project.sln" -target:restore -property:RestorePackagesConfig=true -target:"My Project" -property:Configuration=Release

    In order to build the project, you will need to configure Visual Studio to include the following modules:

    • .NET Desktop development - default options
    • Deskop Development with C++ - default options, plus the "C++/CLI Support for v143 build tools".
  4. Obtain a Python Windows Embeddable package, and extract it into the My Project/x64/Release directory generated by the template. This will give you a python3.dll (amongst other artefacts) in the My Project/x64/Release folder.

  5. Add your code to the template, into the My Project/x64/Release/app directory. At the very minimum, you need to have an app/<app name>/__main__.py file that defines an entry point that will start your application.

    If your code has any dependencies, they should be installed under the My Project/x64/Release/app_packages directory.

If you've done this correctly, a project with a formal name of My Project, with an app name of my-project should have a directory structure that looks something like:

My Project/
    x64/
        Release/
            app/
                my_project/
                    __init__.py
                    __main__.py
                    app.py
            app_packages/
                ...
            python3.dll
            ...
            My Project.exe
            My Project.exe.metagen
            My Project.pdb
    My Project/
        My Project.vcxproj
        My Project.vcxproj.filters
        ...
    My Project.sln
    briefcase.toml
    my-project.wxs
    unicode.wxl

The executable in x64/Release will start your application.

This project can now be compiled with WiX to produce an MSI file. This is a three step process. Open a command prompt, and change into the My Project directory. Then:

  1. Generate a manifest of the files in your project:

    C:\...>"%WIX%\bin\heat.exe" dir x64/Release -gg -sfrag -sreg -srd -scom -dr my_project_ROOTDIR -cg my_project_COMPONENTS -var var.SourceDir -out my-project-manifest.wxs
    
  2. Compile the .wxs files:

    C:\...>"%WIX%\bin\candle.exe" -ext WixUtilExtension -ext WixUIExtension -dSourceDir=x64/Release -arch x64 my-project.wxs my-project-manifest.wxs
    
  3. Link the compiled output to produce the MSI:

    C:\...>"%WIX%\bin\light.exe" -ext WixUtilExtension -ext WixUIExtension -loc unicode.wxl my-project.wixobj my-project-manifest.wixobj -o "My Project.msi"
    

The MSI file can then be used to install your application. When installed, your application will have an entry in your Start menu.

Next steps

Of course, running Python code isn't very interesting by itself - you won't be able to do any console input or output, because a Windows app doesn't display a console.

To do something interesting, you'll need to work with the native Windows system libraries to draw widgets and respond to screen taps. The Python for .NET bridging library can be used to interface with the Windows system libraries. Alternatively, you could use a cross-platform widget toolkit that supports Windows (such as Toga) to provide a GUI for your application.

If you have any external library dependencies (like Toga, or anything other third-party library), you should install the library code into the app_packages directory. This directory is the same as a site_packages directory on a desktop Python install.

briefcase-windows-visualstudio-template's People

Contributors

astraluma avatar brutusthebee avatar davidfokkema avatar dependabot[bot] avatar drewbrew avatar freakboy3742 avatar mhsmith avatar nadi726 avatar rmartin16 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

briefcase-windows-visualstudio-template's Issues

Packaged windows app includes unnecessary support artefacts

Describe the bug

When deployed, a Briefcase Windows app unpacks the Python support package; this includes a copy of python.exe and pythonw.exe. These files are unnecessary, increase the size of the packaged app, and potentially represent a security issue. They should be stripped before packaging.

Steps to reproduce

  1. Generate a windows app
  2. See python.exe and pythonw.exe in the packaged app.

Expected behavior

The Python binaries should be stripped as part of the build process.

Screenshots

No response

Environment

  • Operating System: Windows
  • Python version: All
  • Software versions:
    • Briefcase: 0.3.12

Logs

n/a

Additional context

The briefcase.toml file on a template can contain a cleanup_paths definition; this allows a template to specify files that should be deleted after the template is rolled out. See the beeware/briefcase-macOS-app-template for an example of usage.

Include a PYTHONPATH extension allowing for user-space packages

What is the problem or limitation you are having?

The stub app currently sets a PYTHONPATH that includes the app and app_packages paths, plus the stdlib.

These paths are all inside the application bundle, which the user may not have access to modify.

If a user wants to add additional files to the PYTHONPATH (e.g., if you were building a "Jupyter Notebook" app, and wanted the user to be able to access user-installed packages), you can't install that code into app or app_packages.

Describe the solution you'd like

The stub app should include an Application Data folders as part of the standard app path. This is probably:

C:\Users\<User>\AppData\Local\<AppAuthor>\<AppName>\user_packages

The first part of the path should be returned as the %APPDATA% environment variable.

Describe alternatives you've considered

Don't allow user-installed packages.

Additional context

Once this feature lands, the windows app template will need a new binary.

PySide2 and PySide6 tests are disabled

Due to beeware/briefcase#948, testing of PySide2 and PySide 6 projects has been disabled.

To Reproduce
Steps to reproduce the behavior:

  1. Restore the Pyside2/Pyside6 builds
  2. See error

Additional context

Pyside2 and Pyside6 configurations were added in #2, but were disabled because of the issue with WiX Packaging.

Stub application doesn't have stderr when running without console.

Describe the bug

I'm trying to deploy my ML model with briefcase. It works with briefcase run but i have an error when launch an .exe

CatBoostError: Expected callable object or stream-like object
\windows\app\src\app_packages\catboost\core.py", line 120, in _get_stream_like_object

https://github.com/catboost/catboost/blob/master/catboost/python-package/catboost/core.py

i found out that sys.stderr is None in case of running exe file

How can i fix it? I really appreciate any help you can provide

Expected behavior

sys.stderr is not None

Environment

  • Operating System: Windows
  • Python version: 3.9.13
  • Software versions:
    • Briefcase:

Stub binary doesn't support `sys.executable` spawn/multiprocessing

Describe the bug

The stub binary used to start an app is an effective replacement for the python.exe binary; however, it isn't a perfect replacements. multiprocessing in spawn mode will try to invoke sys.executable to spawn a child; it's also common to use subprocess or os.spawn to try and start sys.exectuable to run other Python code as a subprocess. However, the stub binary doesn't support this kind of execution.

Steps to reproduce

  1. Generate a stub Windows app
  2. Add a call to call multiprocessing.Process() and start it with .start()

The subprocess will call the parent process entry point, and fail.

Expected behavior

The function targeted by Process() should be invoked with the provided arguments.

Screenshots

No response

Environment

  • Operating System: All Windows
  • Python version: All
  • Software versions:
    • Briefcase: 0.3.12

Logs

n/a

Additional context

See beeware/briefcase-macOS-app-template#7 for an analogous report on macOS.

One possible solution would be to add some logic to the stub binary to inspect to see if the parent process is "self"; if so, the execution of the app should be modified to behave as if it were a normal Python binary.

Any solution should also be ported to macOS (beeware/briefcase-macOS-Xcode-template#20) and Linux (beeware/briefcase-linux-flatpak-template#10)

make the release folder more clearly

What is the problem or limitation you are having?

@freakboy3742 Hi, when we build win app, it will put the python runtime files into the root folder, and it looks messy, would u consider to make the template as follows,
1715737087341

Describe the solution you'd like

change the template as above

Describe alternatives you've considered

change the template as above

Additional context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.