Repository: flet-dev/flet
Issue category: Bug Report

Issue:
`flet build` fails to parse file and git dependencies from `tool.poetry.dependencies` in `pyproject.toml`
### Discussed in https://github.com/flet-dev/flet/discussions/4546

<div type='discussions-op-text'>

<sup>Originally posted by **amcraig** December 11, 2024</sup>
### Question

Hi all, 
I've tried including my python package(not on PyPi) through both relative paths to the whl/tar.gz and via git in both `requirements.txt` and in `pyproject.toml` (including poetry) but any attempts I do fail due to a `distutils Module not found` error or `KeyError: 'version'`.

Does anyone have a guaranteed way to provide a local/private python package to Flet in the build process?
Thanks!

### Code sample

```python
##### Pyproject Poetry 
[tool.poetry]
name = "file_tracker"
version = "0.5.0"
description = "redacted"
authors = ["amcraig"]

[tool.poetry.dependencies]
python = "^3.10"
private_package = { git = "https://github.com/private/package.git" }
flet = "^0.25.1"

##### requirements.txt
python==3.10
flet
datateam @ git+https://github.com/private/package
```


### Error message

_No response_

### ------------------------------------------------------

- [X] I have searched for answers to my question both in the issues and in previous discussions.</div>
`flet build` fails to parse file and git dependencies from `tool.poetry.dependencies` in `pyproject.toml`
### Discussed in https://github.com/flet-dev/flet/discussions/4546

<div type='discussions-op-text'>

<sup>Originally posted by **amcraig** December 11, 2024</sup>
### Question

Hi all, 
I've tried including my python package(not on PyPi) through both relative paths to the whl/tar.gz and via git in both `requirements.txt` and in `pyproject.toml` (including poetry) but any attempts I do fail due to a `distutils Module not found` error or `KeyError: 'version'`.

Does anyone have a guaranteed way to provide a local/private python package to Flet in the build process?
Thanks!

### Code sample

```python
##### Pyproject Poetry 
[tool.poetry]
name = "file_tracker"
version = "0.5.0"
description = "redacted"
authors = ["amcraig"]

[tool.poetry.dependencies]
python = "^3.10"
private_package = { git = "https://github.com/private/package.git" }
flet = "^0.25.1"

##### requirements.txt
python==3.10
flet
datateam @ git+https://github.com/private/package
```


### Error message

_No response_

### ------------------------------------------------------

- [X] I have searched for answers to my question both in the issues and in previous discussions.</div>


Hints:

Patch:
diff --git a/sdk/python/packages/flet-cli/src/flet_cli/utils/project_dependencies.py b/sdk/python/packages/flet-cli/src/flet_cli/utils/project_dependencies.py
index 218705576..f39561bfc 100644
--- a/sdk/python/packages/flet-cli/src/flet_cli/utils/project_dependencies.py
+++ b/sdk/python/packages/flet-cli/src/flet_cli/utils/project_dependencies.py
@@ -14,29 +14,69 @@ def get_poetry_dependencies(
     if poetry_dependencies is None:
         return None
 
-    def format_dependency_version(dependency: str, version_value: Any):
+    def format_dependency_version(dependency_name: str, dependency_value: Any):
+        sep = "@"
+        value = ""
         suffix = ""
-        if isinstance(version_value, dict):
-            version = version_value["version"]
-            markers = version_value.get("markers")
+
+        if isinstance(dependency_value, dict):
+            version = dependency_value.get("version")
+            if version:
+                sep = "=="
+                value = version
+            else:
+                git_url = dependency_value.get("git")
+                if git_url:
+                    value = (
+                        f"git+{git_url}" if not git_url.startswith("git@") else git_url
+                    )
+                    rev = (
+                        dependency_value.get("branch")
+                        or dependency_value.get("rev")
+                        or dependency_value.get("tag")
+                    )
+                    if rev:
+                        value = f"{value}@{rev}"
+                    subdirectory = dependency_value.get("subdirectory")
+                    if subdirectory:
+                        value = f"{value}#subdirectory={subdirectory}"
+                else:
+                    path = dependency_value.get("path")
+                    if path:
+                        value = path
+                        dependency_name = ""
+                        sep = ""
+                    else:
+                        url = dependency_value.get("url")
+                        if url:
+                            value = url
+                            dependency_name = ""
+                            sep = ""
+                        else:
+                            raise Exception(
+                                f"Unsupported dependency specification: {dependency_name} = {dependency_value}"
+                            )
+
+            # markers - common for all
+            markers = dependency_value.get("markers")
             if markers is not None:
                 suffix = f";{markers}"
         else:
-            version = version_value
+            value = dependency_value
+            sep = "=="
 
-        sep = "=="
-        if version.startswith("^"):
+        if value.startswith("^"):
             sep = ">="
-            version = version[1:]
-        elif version.startswith("~"):
+            value = value[1:]
+        elif value.startswith("~"):
             sep = "~="
-            version = version[1:]
-            return f"{dependency}~={version[1:]}"
-        elif "<" in version or ">" in version:
+            value = value[1:]
+            return f"{dependency_name}~={value[1:]}"
+        elif "<" in value or ">" in value:
             sep = ""
-            version = version.replace(" ", "")
+            value = value.replace(" ", "")
 
-        return f"{dependency}{sep}{version}{suffix}"
+        return f"{dependency_name}{sep}{value}{suffix}"
 
     dependencies: set[str] = {
         format_dependency_version(dependency, version)


Test patch: