Code Monkey home page Code Monkey logo

Comments (7)

egpbos avatar egpbos commented on July 28, 2024 1

Ok, Sphinx compatibility is important. I will retract my issue then, thanks for the discussion all.

from python-template.

egpbos avatar egpbos commented on July 28, 2024

Btw (besides the point, but related): the __init__.py in the module is currently not strictly PEP8 compliant, the metadata tags should always come before any imports: https://peps.python.org/pep-0008/#module-level-dunder-names. If we don't remove it, we should fix it.

from python-template.

sjvrijn avatar sjvrijn commented on July 28, 2024

+1 for deleting

from python-template.

bouweandela avatar bouweandela commented on July 28, 2024

From the documentation on packaging namespace packages:

Namespace packages allow you to split the sub-packages and modules within a single package across multiple, separate distribution packages (referred to as distributions in this document to avoid ambiguity).
...
Namespace packages can be useful for a large collection of loosely-related packages (such as a large corpus of client libraries for multiple products from a single company). However, namespace packages come with several caveats and are not appropriate in all cases

The impression I get from reading this, is that they are needlessly complex for most use cases and should probably be avoided unless you have a good reason to use them. Having the __init__.py files around also gives you a good place to write documentation for your modules.

We probably don't need metadata tags in the __init__.py file, I've never seen that used in the wild.

from python-template.

egpbos avatar egpbos commented on July 28, 2024

The impression I get from reading this, is that they are needlessly complex for most use cases and should probably be avoided unless you have a good reason to use them.

Do you mean namespace packages are complex? There's really not much complexity about them that I can see... Yes, they allow the more complex packaging option of splitting out optional parts of packages into separate packages, but in fact they do so in a way that makes it seem trivial. No configuration is necessary in most cases, everything is autodiscovered.

from python-template.

bouweandela avatar bouweandela commented on July 28, 2024

I mean

namespace packages come with several caveats and are not appropriate in all cases

Personally I do not have experience with using namespace packages, so I cannot tell what those caveats are, but one of those caveats that I am aware of is that standard tricks to figure out where a file is located (e.g. when you need some data that is located in the same directory as the Python module that is using it) module_name.__file__ or module_name.__path__ does not work in namespace packages and you need to use the more complicated importlib.resources standard library module. This can come as a surprise to unsuspecting users.

from python-template.

BSchilperoort avatar BSchilperoort commented on July 28, 2024

Do note that while __init__ is not required anymore for Python packaging, some tools still do depend on it.

I experienced that this week with the sphinx autoapi extension. It still doesn't fully/easily/properly support implicit namespace packages. For me the easiest fix here was to just add a __init__.py file in the right folder...

from python-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.