How to structure python project with dot "." or underscore "-" in project/package name?
Asked Answered
C

2

7

PEP 423 states that project names and package names should be the same and later gives an example where the project/package name contains a dot:

Yes:
Package name: "kheops.pyramid", i.e. import kheops.pyramid
Project name: "kheops.pyramid", i.e. pip install kheops.pyramid

What would the directory structure be for kheops.pyramid and how would setup.py be written (specifically the name and packages values) for that directory structure?

I've also seen that PEP 503 states that names should be normalized by replacing _, -, and . with -. Does this mean that kheops-pyramid should be used rather than kheops.pyramid? If so, wouldn't I need a package whose directory name is kheops-pyramid and wouldn't the - cause issues (eg. syntax error) when trying to import kheops-pyramid?

EDIT:
I tried to make a project/package kheops.pyramid to adhere to PEP 423 but I cannot figure out what directory structure and setup.py combination will allow me to import kheops.pyramid after pip install kheops.pyramid without an error like ImportError: No module named kheops.pyramid.

Carlie answered 11/6, 2016 at 15:46 Comment(7)
Have you looked at "namespace packages"? See e.g. python.org/dev/peps/pep-0420Bovine
@Bovine I had not seen PEP 420 before. It definitely seems relevant but not sure I understand how to address my problem still.Carlie
What is your problem? Are you trying to make a package with a . in the name and failing?Bovine
@Bovine yes. i am trying to make a project/package like username.package to adhere to PEP 423 python.org/dev/peps/pep-0423/… but I cannot figure out what directory structure and setup.py combination will allow me to import username.package after pip install username.package without an error like ImportError: No module named username.package. Will edit the question to make this more apparent.Carlie
You need kheops to exist first in order for kheops.pyramid to be possible.Forefend
@Forefend not sure what type of thing kheops is in your comment: project, package, directory?Carlie
A package, I guess. Tangentially, see also https://mcmap.net/q/18827/-what-39-s-the-difference-between-a-module-and-package-in-pythonForefend
C
1

PEP 423 is deferred, so I ended doing to equivalent of pyramid rather than kheops.pyramid via standard python packaging. Here is the package I came up with as an example.

Carlie answered 12/6, 2016 at 17:29 Comment(0)
H
0

from username import package should work.

Are you sure about your PYTHONPATH ?

You might want to try executing the system commands after PYTHONPATH=. ? This is because you perhaps haven't set PYTHONPATH to include the directory which contains username/

You might also want to check Python Package Structure.

Heilbronn answered 12/6, 2016 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.