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

Source Code Question #6227

Open
icbd opened this issue Aug 30, 2024 · 1 comment
Open

Source Code Question #6227

icbd opened this issue Aug 30, 2024 · 1 comment
Labels
Type: Question ❔ This is a question or a request for support.

Comments

@icbd
Copy link

icbd commented Aug 30, 2024

When I initialized the Pipefile, pipenv helped me create the directory of virtualenv, e.g. creator CPython3Posix(dest=/Users/icbd/.local/share/virtualenvs/未命名文件夹-AsmMYtXt

I was curious about how the name of this directory was generated, so I found the source code implementation.

pipenv/pipenv/project.py

Lines 539 to 546 in 32e18cd

def get_name(name, location):
name = self._sanitize(name)
hash = hashlib.sha256(location.encode()).digest()[:6]
encoded_hash = base64.urlsafe_b64encode(hash).decode()
return name, encoded_hash[:8]
clean_name, encoded_hash = get_name(name, self.pipfile_location)
venv_name = f"{clean_name}-{encoded_hash}"

Does the processing of base64.urlsafe_b64encode have any special considerations? It seems that using hex() would be enough.

Thanks

@oz123
Copy link
Contributor

oz123 commented Sep 10, 2024

What would be the advantage of hex over base64.urlsafe_b64encode?

@matteius matteius added the Type: Question ❔ This is a question or a request for support. label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question ❔ This is a question or a request for support.
Projects
None yet
Development

No branches or pull requests

3 participants