https://pulumi.com logo
#python
Title
# python
t

thousands-knife-3009

02/23/2024, 3:35 PM
why are all of the pulumi packages listed as pulumi-<pkg name> in pypi but imported as pulumi_<pkg name> ?
h

hundreds-gpu-71155

02/23/2024, 3:39 PM
python convention
t

thousands-knife-3009

02/23/2024, 3:42 PM
I don't think that's the normal pattern.
h

hundreds-gpu-71155

02/23/2024, 3:42 PM
-
isn't a valid symbol in python names, and I think in package names
_
is replaced with
-
it's not uncommon for extension and related packages
t

thousands-knife-3009

02/23/2024, 3:44 PM
just because a couple projects do it, does not make it proper.
h

hundreds-gpu-71155

02/23/2024, 3:45 PM
i just pulled 3 unrelated projects without working at it. bet i can find one for numpy
just because you personally haven't seen it much doesn't mean it's rare
t

thousands-knife-3009

02/23/2024, 3:47 PM
it seems to be an anti-pattern for the module name not to match the package imported in requirements.
h

hundreds-gpu-71155

02/23/2024, 3:47 PM
yup
which is why it's
pulumi_spam
pulumi-spam
isn't a valid python variable name
it would be parsed as
pulumi - spam
t

thousands-knife-3009

02/23/2024, 3:48 PM
i'm talking module and package names, not variables.
h

hundreds-gpu-71155

02/23/2024, 3:48 PM
they're the same thing in the python language
they're just names
all names are equal
the earliest explicit mention of this normalization I can find is 2012 with PEP 426 (referenced by PEP 508). The earlier PEP 345 (2005) and PEP 314 (2003) and PEP 241 (2001) don't mention any kind of name normalization. (Not that I think it didn't happen, it just wasn't mentioned in the PEPs I can trace.)
t

thousands-knife-3009

02/23/2024, 3:56 PM
i just told pycharm to ignore imported modules not found in requirements and ignore requirements not satisfied in my venv.
h

hundreds-gpu-71155

02/23/2024, 3:56 PM
unfortunately, I'm not readily finding the source of the old cheeseshop version of PyPI, so I can't confirm that against implementation.
(i could probably find easy_install, though)
pycharm definitely knows about this convention
l

limited-rainbow-51650

02/23/2024, 3:58 PM
I think this comes back to PEP 8:
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
https://peps.python.org/pep-0008/#package-and-module-names
t

thousands-knife-3009

02/23/2024, 4:15 PM
If anyone else is using Pycharm, here are the relevant bug reports: PY-54850 PY-49425
d

dry-keyboard-94795

02/23/2024, 4:29 PM
You can use
pulumi_<provider>
in your requirements files if you want, pip/pypi will resolve it correctly
t

thousands-knife-3009

02/23/2024, 4:31 PM
@dry-keyboard-94795 that's interesting. wouldn't that be susceptible to package hijacking though if someone published a package with the same name?
d

dry-keyboard-94795

02/23/2024, 4:32 PM
No, pypi treats - and _ as the same to prevent duplication
t

thousands-knife-3009

02/23/2024, 4:32 PM
oh, i didn't know that.
h

hundreds-gpu-71155

02/23/2024, 4:32 PM
like i said, it's specified as normalized since 2012
d

dry-keyboard-94795

02/23/2024, 4:33 PM
I believe you can also replace with
.
as well
t

thousands-knife-3009

02/23/2024, 4:35 PM
i appreciate the help and i've learned a few things. i think it's just that pycharm is having issues. using
pulumi_gcp
in requirements shows the warning that requirements are unsatisfied despite
pulumi_gcp
already being installed.
d

dry-keyboard-94795

02/23/2024, 4:35 PM
It's disappointing that pycharm has a regression like that. My main usecase for it was for django projects, and many django extensions don't have package names aligned with module names.
a

ambitious-king-70853

02/24/2024, 7:45 AM
Off topic of module naming but within the context of pulumi & pycharm. One thing that threw me for a loop is that on project creation and open, pycharm will automatically spin up a venv for the root of the project. So, if you're initializing several pulumi projects/stacks within a single pycharm project - the terminal will show xyz
(venv)
for the home project which may not have the same requirements that your various pulumi projects have. Again, this threw me for a loop and maybe it'll help someone down the road in when sifting through this thread.
d

dry-keyboard-94795

02/24/2024, 10:36 AM
Been a while since I've used pycharm, but I believe you can setup workspaces/projects within the project Explorer for individual directories, which can be configured with different venvs; this will help with linters/autocomplete in editor, and provide terminal opening within those directories to use the correct venv. If you've a venv specified in your pulumi config in each project, pulumi will always that specified venv, even if you're already in a venv