Embarcadero / PythonEnvironments

Components to simplify the deployment for Python environments for Delphi applications using Python4Delphi.
MIT License
44 stars 15 forks source link

Allow passing a blank string as a FilePath #16

Closed peardox closed 2 years ago

peardox commented 2 years ago

This extremely minor modification makes LocalPython far easier to use.

If a TPyLocalDistribution is added to the Distributions and a blank FilePath is passed then calling Setup will result in the recently added TPyLocalDistribution being used (providing it matches the PythonVersion of course).

I did think of checking if Distributions was empty to trigger this functionality but there exists the possibility that you want to add a new Distribution by FilePath so checking for blank FilePath covers more use cases.

I've tested this and, somewhat to my amazement, it worked first time.

Prior to this change I was having to write out a JSON file just so I could pass it into LocalPython as a parameter (not elegant at all)

image

Cool, Eh?

PyScripter's PythonVersions is highly Windows-centric (there are a few bits of portable code) with his function GetRegisteredPythonVersion being highly desirable for FMX but not usable (Windows Only). I adapted what he was doing and produced a basic Mac version of the same thing (Linux later...) - currently mine is a little rudimentary and needs testing against more Distributions but it does work with the official distribution (tested with 3.9.12)

lmbelo commented 2 years ago

I've thought to create a new component that would try to discovery system Python installations and/or use static distributions. This one is intended to use a config. file, thus it must have a valid file.

peardox commented 2 years ago

This still allows the config file, it's just a non-JSON way of providing the data you would supply in a file.

Yeah, a proper system would be better but as it stands this is a useful addition.

Why not merge this PR for now then if/when you do a proper implementation deprecate this PR in favour of the new component? That makes the feature available immediately which seems a good idea.

I worked this way out specifically to avoid writing a config file.

Alternate methods would be to allow the FilePath to be a TStream or a TJsonObject for example. Forcing a file to be placed on the target system that will very seldom be the same on two systems seems a bit convoluted.

As I've said I was planning to do Install docs / videos and this is the only way to get a Mac working as Embedded is not suitable for a distributed solution (doesn't work apart from on your system). I was going to do Embedded on Windows and Local on Mac (plus whichever works on Linux) the reasoning being that these deployment methods demonstrably work on factory-fresh kit.

Without this PR the only alternative it to write to file and read it back (yuck)

peardox commented 2 years ago

Oh, another thought I has was to use a 'Special' filename for this mode to be enabled - e.g. if FilePath = 'DISTRIBUTION-ASSIGNED' then skip the file read

lmbelo commented 2 years ago

It doesn't make much sense a component that was supposed to work based on a configuration file whereas it doesn't require the configuration file. I'm currently porting the FMXBuilder to the PyScripter. There are many pending things that I will work out in the Python environments components, Python common components, delphifmx and delphivcl. Tune in :D

peardox commented 2 years ago

OK, I've written a Mac specific json file for LocalPython - it seems sensible to include it in the repo

The entries are based on the info I can glean from PythonEngine.pas - it works with 3.9.12 and has definitions for all entries in KNOWN_PYTHON_VERSIONS

I'd PR it but dunno where to stick it in the source tree

macpython.zip

lmbelo commented 2 years ago

OK, I've written a Mac specific json file for LocalPython - it seems sensible to include it in the repo

The entries are based on the info I can glean from PythonEngine.pas - it works with 3.9.12 and has definitions for all entries in KNOWN_PYTHON_VERSIONS

I'd PR it but dunno where to stick it in the source tree

macpython.zip

Configuration file are supposed to be distributed by vendors. We can't assume any static configuration.