flaskerize icon indicating copy to clipboard operation
flaskerize copied to clipboard

cannot find ts when running tests

Open gabrielfior opened this issue 5 years ago • 12 comments

Hi,

I have been trying to run the tests before possibly submitting a PR. I am running Python 3.6 within a conda environment on Windows 10, but I cannot run the fz command in the shell. I noticed the file is inside the bin folder and I also added the folder /bin to my PATH env variable. Nevertheless I could not find it. Is there a proper way to handle this? Thanks in advance for the help, Best, Gabriel

============================= test session starts =============================
platform win32 -- Python 3.6.6, pytest-5.1.2, py-1.6.0, pluggy-0.13.0 -- C:\Users\xxxx\AppData\Local\Continuum\miniconda3\envs\brasa36\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\d91421\Code\flaskerize, inifile: pytest.ini
collecting ... collected 78 items / 77 deselected / 1 selected

attach_test.py::test_flaskerize_generate FAILED                          [100%]'fz' is not recognized as an internal or external command,
operable program or batch file.

flaskerize\attach_test.py:8 (test_flaskerize_generate)
0 != 1

Expected :1
Actual   :0
 <Click to see difference>

        status = os.system("fz bundle --dry-run --from test/build/ --to app:create_app")
>       assert status == 0
E       assert 1 == 0
E         -1
E         +0

attach_test.py:16: AssertionError


================================== FAILURES ===================================
__________________________ test_flaskerize_generate ___________________________    
        status = os.system("fz bundle --dry-run --from test/build/ --to app:create_app")
>       assert status == 0
E       assert 1 == 0
E         -1
E         +0

attach_test.py:16: AssertionError
---------------------------- Captured stderr call -----------------------------
'fz' is not recognized as an internal or external command,
operable program or batch file.
================ 1 failed, 77 deselected, 1 warnings in 0.52s =================
Process finished with exit code 0

gabrielfior avatar Sep 16 '19 09:09 gabrielfior

Disclaimer: I work primarily off of a Mac and haven't verified the following within a Windows environment

If you pip install flaskerize or python setup.py install it should also install the script (added here). I would have expected your solution with PATH to have worked. If you provide the full path to the fz script, does it then work? Are you running this from Powershell, anaconda prompt, git bash, WSL, or something else?

Edit: Also, how are you running the tests? If it's within an IDE then any PATH modifications you make would also need to be known there (e.g. if you add something to system PATH you might need to restart the IDE to take effect)

apryor6 avatar Sep 16 '19 12:09 apryor6

The script is indeed added to the Scripts folder of Miniconda (C:\Users\d91421\AppData\Local\Continuum\miniconda3\envs\brasa36\Scripts\fz), but the command fz returns the following:

(brasa36) C:\Users\d91421>fz
'fz' is not recognized as an internal or external command,
operable program or batch file.

Next I tried starting fz from the Git Bash, and it works.

d91421@T46NB109 MINGW64 ~
$ activate brasa36

d91421@T46NB109 MINGW64 ~
$ fz
usage: fz [-h] {attach,bundle,generate} [{attach,bundle,generate} ...]
fz: error: the following arguments are required: command
Flaskerizing...

Now I try to run commands similar to the ones performed in the tests, but they were unsuccessful.

>>> os.system('fz')
'fz' is not recognized as an internal or external command,
operable program or batch file.
1

Is there a different way to start the fz CLI?

gabrielfior avatar Sep 16 '19 22:09 gabrielfior

Hmm. Well as to the issue of why the command is recognized in git bash but not in your python interpreter it's hard to know for sure. It looks like in git bash there was no problem, but fz is not found in your python interpreter. Is that python interpreter being run from the same git bash instance? Or are you opening python from the anaconda prompt, which is an entirely different shell that might not have PATH setup the same. This could be the difference, but just speculation. I have a windows box somewhere at home that I can give it a whirl on, but I know I won't be able to get to that for some time. Hopefully in the short term we can find a workaround.

If you look at the contents of fz, it is quite trivial

import sys

from flaskerize.parser import Flaskerize

print("Flaskerizing...")
Flaskerize(sys.argv)

Perhaps you could just invoke commands in the same way. sys.argv captures arguments from the command line as an array of strings. You could replicate the commands in this way, though it won't solve the issue of the tests that invoke os.system failing. These tests do pass in circle, so if you were to open a PR that will validate these tests, though I understand this is very inconvenient.

apryor6 avatar Sep 17 '19 20:09 apryor6

Was this ever resolved?

apryor6 avatar Oct 24 '19 16:10 apryor6

No. I realized that, if I change the name of the fz file (in my case located under C:\Users\username\AppData\Local\Continuum\miniconda3\envs\my-env\Scripts) to fz.exe, the cmd prompt is able to start the script, which then crashes since it is not a proper .exe file.

Some other packages that offer CLI features (such as flask and pytest) have files in the Scripts folder which end with .exe (pytest.exe, flask.exe). It might be interesting to take a look at those packages to understand how they tackle this Windows-compatibility issue.

gabrielfior avatar Oct 25 '19 08:10 gabrielfior

Okay thank you for the update and lead!

On Fri, Oct 25, 2019 at 4:53 AM Gabriel Fior [email protected] wrote:

No. I realized that, if I change the name of the fz file (in my case located under C:\Users\username\AppData\Local\Continuum\miniconda3\envs\my-env\Scripts) to fz.exe, the cmd prompt is able to start the script, which then crashes since it is not a proper .exe file.

Some other packages that offer CLI features (such as flask and pytest) have files in the Scripts folder which end with .exe (pytest.exe, flask.exe). It might be interesting to take a look at those packages to understand how they tackle this Windows-compatibility issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apryor6/flaskerize/issues/32?email_source=notifications&email_token=AEWCXBLC2AUA73JBUO7UKY3QQKXYRA5CNFSM4IW7ZXDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECHVXDI#issuecomment-546265997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWCXBO5G4ZOKJXT6UHFYELQQKXYRANCNFSM4IW7ZXDA .

--

Alan (AJ) Pryor, Ph.D. (478-232-2486)

apryor6 avatar Oct 25 '19 08:10 apryor6

FYI I just realized that one could use the py2exe package to create an exe file for windows from a setup.py file. It could be an interesting option for windows support.

gabrielfior avatar Oct 25 '19 09:10 gabrielfior

I have the same issue. After installing, fz was not available, so I looked at the fz file and noticed that it is a really simple script and just copied it to a regular Python file and invoked it via python script.py generate flask-api my_app which throws following error:

Flaskerizing...
Traceback (most recent call last):
  File "tmp.py", line 6, in <module>
    Flaskerize(sys.argv)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\parser.py", line 72, in __init__
    getattr(self, parsed.command[0])(args[2:])
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\parser.py", line 174, in generate
    args=rest,
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\parser.py", line 260, in _check_render_schematic
    args=args,
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\parser.py", line 279, in render_schematic
    ).render(name, args)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\render.py", line 224, in render
    run(renderer=self, context=context)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\render.py", line 239, in default_run
    renderer.copy_static_file(filename, context=context)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\flaskerize\render.py", line 152, in copy_static_file
    if self.sch_fs.isdir(filename):
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\fs\base.py", line 933, in isdir
    return self.getinfo(path).is_dir
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\fs\osfs.py", line 286, in getinfo
    _path = self.validatepath(path)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\fs\osfs.py", line 678, in validatepath
    return super(OSFS, self).validatepath(path)
  File "C:\Users\xxx\Projects\xxx\.venv\lib\site-packages\fs\base.py", line 1489, in validatepath
    raise errors.InvalidCharsInPath(path)
fs.errors.InvalidCharsInPath: path '{{ name }}.template\app\widget\service.py' contains invalid characters

.../service.py is not the only offending file/path. When I run the script again it picks a file from the template directory seemingly at random and complains about invalid characters.

I realize that this might be a separate issue, however I wasn't sure if this is just somehow a side effect of the way I'm invoking flaskerize. Has anyone tried to use flaskerize on Windows? Is it supposed to work?

bk-m avatar Nov 02 '19 12:11 bk-m

This is an issue on Windows that I haven’t yet been able to find time to fix (all my machines are Mac). I’d be happy to accept a PR.

apryor6 avatar Nov 02 '19 17:11 apryor6

Hello @apryor6

Thank you for creating this library, i REALLY want to use it but iám having the same issue as bk-m with the path.

I know you said you don't have the time but could you tell me what the code does with the {{ x }}.template files on your Mac so i can try and edit the source code so it might work on my windows machine? I tried understanding this by reading your code but i could'nt figure out what i had to change.

Also what is a PR (you mention this above) ? If it is something you need to fix this issue maybe i can help!

yannickspies avatar Nov 22 '19 15:11 yannickspies

The {{ variable_name }} syntax comes from Jinja which is what flaskerize uses to render the templates.

A PR is a pull request is the most common way in which new changes are proposed for a shared, version controlled project. It just means while I haven't (yet) found the time to look into the issue, if somebody else were to solve and open a pull request into this code base I would happily accept a resolution.

apryor6 avatar Nov 22 '19 15:11 apryor6

Thanks for the fast reply! I wil try and see ifi can get it to work with this info. I wil let you know!

On Fri, Nov 22, 2019, 16:08 AJ Pryor, Ph.D. [email protected] wrote:

The {{ variable_name }} syntax comes from Jinja https://jinja.palletsprojects.com/en/2.10.x/ which is what flaskerize uses to render the templates.

A PR is a pull request https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests is the most common way in which new changes are proposed for a shared, version controlled project. It just means while I haven't (yet) found the time to look into the issue, if somebody else were to solve and open a pull request into this code base I would happily accept a resolution.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apryor6/flaskerize/issues/32?email_source=notifications&email_token=AFQRWO4Z4LRHURRYNXIYDFDQU7YXTA5CNFSM4IW7ZXDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE543XI#issuecomment-557567453, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQRWO2UT7GJFSXFM5NHSKLQU7YXTANCNFSM4IW7ZXDA .

yannickspies avatar Nov 22 '19 15:11 yannickspies