-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: Fix the default slug used for the package name #245
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abhijeetSaroha thanks for working on that.
I think that the only (or most only) place you need to change is here: https://github.com/osl-incubator/scicookie/blob/main/src/scicookie/profiles/base.yaml#L40
@xmnlab |
Yep the point is to not have a default value wrong. If the user decide any wrong value it should just fail. Does it make sense? |
package_slug:
message: Type the code name for your package (the name used to import your package)
help: https://osl-incubator.github.io/scicookie/guide/#information-about-the-project
type: text
default: "{{project_slug.replace('-', '_').replace('.', '').replace('@', '').replace('&', '').replace('$', '').replace('%', '').replace('#', '')}}"
visible: true This is one of the way (works fine), but It doesn't seem to be good for production. Then, I also tried regex, but I am not able to find Builtin Filter which has support of regex. Then, I tried to build the logic which looks like this: package_slug:
message: Type the code name for your package (the name used to import your package)
help: https://osl-incubator.github.io/scicookie/guide/#information-about-the-project
type: text
default: "{% set res='' %}{% for char in project_slug.replace('-','_') %}{% if char.isalnum() or char == '_' %}{% set res = res + char %}{% endif %}{% endfor %}{{ res }}"
visible: true But, after this, it gives me default value as empty string, if I give some initial value to the Do you have any idea more about this? |
I think that the way to go using jinja2 filters. so you could create a more robust regex here: https://github.com/osl-incubator/scicookie/blob/main/src/scicookie/ui.py Here is an example of implementation (pseudo code) and how to use it:
in the original code we are using Template, so you will need to change it to Environment (as the same in the example) |
@xmnlab , can you please review the changes, on my side I test the changes and works fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for working on that @abhijeetSaroha
just added a few notes here.
src/scicookie/ui.py
Outdated
@@ -3,13 +3,14 @@ | |||
from __future__ import annotations | |||
|
|||
import os | |||
import re # Add this import for regex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need this comment here .. it is really clear that re
is used for regex among the python users
so no worries about the comment
src/scicookie/ui.py
Outdated
@@ -96,11 +104,17 @@ def make_questions(questions: dict[str, Any]) -> dict[str, str]: | |||
) | |||
print("." * columns) | |||
|
|||
# Create a Jinja2 environment and add the custom filter | |||
env = Environment(autoescape=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use autoescape=false.
if bandit complains, just skip the issue there, for example: https://github.com/osl-incubator/makim/blob/main/pyproject.toml#L105
I removed the comment and |
thanks @abhijeetSaroha |
🎉 This PR is included in version 0.8.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
I added a function to sanitize the
package_slug
. So, now, It will remove the non-alphanumeric characters from thepackage_slug
and will not give error.Solves #197