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

Using a hyphen in the name when scaffolding causes the application to error out #38

Closed
j2salmingo opened this issue Feb 10, 2024 · 1 comment · Fixed by #40
Closed
Assignees
Labels
bug Something isn't working priority:1 High priority issue

Comments

@j2salmingo
Copy link

Used the following command:
bl-python-scaffold create -n test-scaffold -t openapi -m database

After creating the virtual environment and installing the app, the program crashes when trying to run.

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 189, in _run_module_as_main
    mod_name, mod_spec, code = _get_main_module_details(_Error)
  File "/usr/lib/python3.10/runpy.py", line 238, in _get_main_module_details
    return _get_module_details(main_name)
  File "/usr/lib/python3.10/runpy.py", line 157, in _get_module_details
    code = loader.get_code(mod_name)
  File "<frozen importlib._bootstrap_external>", line 1017, in get_code
  File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/jsalmingo/python_projects/test-scaffold/test-scaffold/__main__.py", line 1
    from test-scaffold import create_app
             ^
SyntaxError: invalid syntax

This seems to occur because when the code is generated, invalid module names can be used and therefore causes failure when importing.

@j2salmingo j2salmingo added the bug Something isn't working label Feb 10, 2024
@aholmes aholmes added the good first issue Good for newcomers label Feb 12, 2024
@aholmes
Copy link
Member

aholmes commented Feb 12, 2024

Thanks for the report. Indeed the issue is caused by not sanitizing hyphens in the application name. This also occurs with endpoint names. For example, this will generate an application module and endpoint module both with hyphens in their names.

bl-python-scaffold create -n foo-foo -e foo-bar

Hyphens are not always invalid - for example, a URL can contain hyphens, which the scaffolder generates from the application and endpoint names. As such, we can resolve this by replacing hyphens with underscores for the module names only.

We need to be mindful of a user specifying a command like this.

bl-python-scaffold create -n foo \
    -e foo-bar \
    -e foo_bar

It may be appropriate to display a warning and continue generating the application anyway, or prompt the user whether to continue. If generating cannot be done safely in this case, the scaffolder should error and quit.

@aholmes aholmes added the priority:1 High priority issue label Feb 12, 2024
@aholmes aholmes self-assigned this Feb 13, 2024
aholmes added a commit that referenced this issue Feb 15, 2024
aholmes added a commit that referenced this issue Feb 15, 2024
aholmes added a commit that referenced this issue Feb 15, 2024
aholmes added a commit that referenced this issue Feb 15, 2024
aholmes added a commit that referenced this issue Feb 15, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
…d endpoint names.

- disallows duplicate endpoint names
- disallows endpoints that share the same name as an application

Closes #38
aholmes added a commit that referenced this issue Feb 16, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
aholmes added a commit that referenced this issue Feb 16, 2024
@aholmes aholmes removed the good first issue Good for newcomers label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:1 High priority issue
Projects
Status: Done
2 participants