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

Issues with flet build --template_dir option (flet 0.19.0) #2437

Closed
tokyohandsome opened this issue Jan 20, 2024 · 13 comments
Closed

Issues with flet build --template_dir option (flet 0.19.0) #2437

tokyohandsome opened this issue Jan 20, 2024 · 13 comments

Comments

@tokyohandsome
Copy link

Description
A couple of issues when building app with --template_dir option.

Code example to reproduce the issue:

  1. Build option --template_dir explained in the online document must be a typo. --template-dir (not an underscore but a dash between template and dir) is correct.

Result with --template_dir:

usage: flet [-h] [--version] {create,run,pack,publish,build} ...
flet: error: unrecognized arguments: --template_dir flet-build-template  
  1. Specifying the template folder by relative path flet build macos --template-dir flet-build-template won't work. Need to give it a full-path or use pwd like: --template-dir `pwd`/flet-build-template.

Result of relative path:

Creating Flutter bootstrap project...Traceback (most recent call last):
  File "/Users/handsome/Documents/Python/passgen/.venv/bin/flet", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/handsome/Documents/Python/passgen/.venv/lib/python3.11/site-packages/flet/cli/cli.py", line 83, in main
    args.handler(args)
  File "/Users/handsome/Documents/Python/passgen/.venv/lib/python3.11/site-packages/flet/cli/commands/build.py", line 342, in handle
    cookiecutter(
  File "/Users/handsome/Documents/Python/passgen/.venv/lib/python3.11/site-packages/cookiecutter/main.py", line 80, in cookiecutter
    base_repo_dir, cleanup_base_repo_dir = determine_repo_dir(
                                           ^^^^^^^^^^^^^^^^^^^
  File "/Users/handsome/Documents/Python/passgen/.venv/lib/python3.11/site-packages/cookiecutter/repository.py", line 128, in determine_repo_dir
    raise RepositoryNotFound(
cookiecutter.exceptions.RepositoryNotFound: A valid repository for "https://github.com/flet-dev/flet-build-template.git" could not be found in the following locations:
/Users/handsome/.cookiecutters/flet-build-template/flet-build-template

Describe the results you received:

See above.

Describe the results you expected:

See above.

Flet version (pip show flet):

Name: flet
Version: 0.19.0
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: hello@flet.dev
License: Apache-2.0
Location: /Users/handsome/Documents/Python/passgen/.venv/lib/python3.11/site-packages
Requires: cookiecutter, flet-runtime, packaging, qrcode, watchdog, websocket-client, websockets
Required-by:

Operating system:

OS: macOS 14.2.1

Additional environment details:

pipenv version 2023.10.24

@taaaf11
Copy link
Contributor

taaaf11 commented Jan 22, 2024

Option has been fixed in the docs. What is the problem? Actually, it is absolute path to the flet-build-template directory cloned from https://github.com/flet-dev/flet-build-template .

And why are you using pwd? Is this directory present in the path? Try using --template-dir pwd

@tokyohandsome
Copy link
Author

@taaaf11 , thanks for fixing the typo in the guide.

If --template-dir requires absolute path, docs should be corrected as well.

From:

--template-dir option specifies a relative path to a cookiecutter template in a repository.

To:

--template-dir option specifies an absolute path to a cookiecutter template in a repository.

I used `pwd` because the cookiecutter.json is in the cloned folder flet-build-template (see below). Not a big deal if the guide is corrected. Thanks!

% tree -L 2
.
├── assets
│   └── icon.png
├── build
│   └── macos
├── flet-build-template
│   ├── LICENSE
│   ├── README.md
│   ├── cookiecutter.json
│   └── {{cookiecutter.out_dir}}
├── main.py
└── requirements.txt

6 directories, 6 files

@taaaf11
Copy link
Contributor

taaaf11 commented Jan 22, 2024

Yup you are right. Actually, it's a path relative to the HOME directory of the user. Like, when I was trying to reproduce, it suggests that it searches for the the template in path C:\Users\USER\.cookiecutters\flet-build-template\<the-value-to-the-option-you-specify>

@tokyohandsome
Copy link
Author

On macOS, below is the code to build specifying the local template. `pwd` adds absolute path to the current working directory, so it works the same as specifying absolute path to the local template directory in Unix/Linux worlds.

flet build macos --template-dir `pwd`/flet-build-template

If there's no plan to fix Flet codes to accept relative path soon, the online guide should explain "--template-dir option specifies an absolute path to a cookiecutter template in a repository."

@taaaf11
Copy link
Contributor

taaaf11 commented Jan 22, 2024

"--template-dir option specifies an absolute path to a cookiecutter template in a repository."

@FeodorFitsner

@FeodorFitsner
Copy link
Contributor

@tokyohandsome wait a second, that --template-dir goes directly and unchanged to a call to cookiecutter and it says "Relative path to a cookiecutter template in a repository." You are saying it must be an absolute path if directory specified in --template parameter?

@taaaf11
Copy link
Contributor

taaaf11 commented Jan 22, 2024

@tokyohandsome wait a second, that --template-dir goes directly and unchanged to a call to cookiecutter and it says "Relative path to a cookiecutter template in a repository." You are saying it must be an absolute path if directory specified in --template parameter?

nope, I tried, but it gave an error like repositorynotfound, giving C:\Users\USER\.cookiecutters\flet-build-template\<the-value-to-the-option-you-specify>

@FeodorFitsner
Copy link
Contributor

OK, will take a look. But again, it's only when --template is a path to directory, not a GH repo?

@FeodorFitsner FeodorFitsner added the bug Something isn't working label Jan 22, 2024
@FeodorFitsner FeodorFitsner self-assigned this Jan 22, 2024
@taaaf11
Copy link
Contributor

taaaf11 commented Jan 22, 2024

OK, will take a look. But again, it's only when --template is a path to directory, not a GH repo?

yes

@tokyohandsome
Copy link
Author

Sorry for not getting back sooner.
I suppose @FeodorFitsner got it but just in case, only when specifying local template directory by --template-dir relative_path flet fails to build. Removing the --template-dir option at all or giving it absolute path will build with no problem. Actual error was in my initial post of this issue report.

@taaaf11
Copy link
Contributor

taaaf11 commented Jan 24, 2024

Sorry for not getting back sooner. I suppose @FeodorFitsner got it but just in case, only when specifying local template directory by --template-dir relative_path flet fails to build. Removing the --template-dir option at all or giving it absolute path will build with no problem. Actual error was in my initial post of this issue report.

You are right. Absolute path works

@FeodorFitsner
Copy link
Contributor

OK, I'm going to resolve --template-dir relative to the current directory (pwd).

@FeodorFitsner FeodorFitsner removed the bug Something isn't working label Jan 24, 2024
@FeodorFitsner
Copy link
Contributor

OK, have a misunderstanding here!
Apparently, everything works as expected.

Look, to provide a path to a directory with your custom template you have to use --template parameter, as stated in the docs - it's either git URL or a path.

--template-dir, however specifies a relative path inside that directory or git repo.

For example, if my template is in /Users/john/projects/my-template I can specify path to it as:

flet build web --template /Users/john/projects/my-template

or (relatively to current dir):

flet build web --template ../../../projects/my-template

or I can specify /Users/john/projects as a root and then my-template as a relative path under that root:

flet build web --template /Users/john/projects --template-dir my-template

so, --template-dir is used if you have multiple templates under --template.

@FeodorFitsner FeodorFitsner removed their assignment Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants