why are all of the pulumi packages listed as pulum...
# python
t
why are all of the pulumi packages listed as pulumi-<pkg name> in pypi but imported as pulumi_<pkg name> ?
h
python convention
t
I don't think that's the normal pattern.
h
-
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
just because a couple projects do it, does not make it proper.
h
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
it seems to be an anti-pattern for the module name not to match the package imported in requirements.
h
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
i'm talking module and package names, not variables.
h
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
i just told pycharm to ignore imported modules not found in requirements and ignore requirements not satisfied in my venv.
h
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
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
If anyone else is using Pycharm, here are the relevant bug reports: PY-54850 PY-49425
d
You can use
pulumi_<provider>
in your requirements files if you want, pip/pypi will resolve it correctly
t
@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
No, pypi treats - and _ as the same to prevent duplication
t
oh, i didn't know that.
h
like i said, it's specified as normalized since 2012
d
I believe you can also replace with
.
as well
t
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
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
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
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