question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to generate this setup.py for a namespace subpackage?

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Question

Hi!

I’m moving all my projects to Poetry and have issues with some of them. Namely, it’s packages that are subpackages to a bigger project.

Here is one example: https://github.com/foliant-docs/foliantcontrib.bump. It’s an extension for https://github.com/foliant-docs/foliant.

It means that during installation, the file foliant/cli/bump.py should be placed in foliant/cli folder in Foliant installation. To accomplish this, I’m using namespace package in setup.py.

I haven’t found a way to achieve the same thing with Poetry. Tried using packages in pyproject.toml, but that gives me a package name cli, not foliant.cli.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
RaptDeptcommented, Aug 3, 2018

Your pyproject.toml link leads to a 404. How did you use packages?

I’ve been able to use namespace packages in Poetry just fine, but my use case is slightly different. I don’t have projects that share innermost (leaf) packages, so I’m not sure if this will work for you.

I have two projects, foo-project and bar-project:

foo-project
├── pyproject.toml
└── root_namespace
    └── nested_namespace
        └── subpackage_a
        │   └── __init__.py
        └── subpackage_b
            └── __init__.py
bar-project
├── pyproject.toml
└── root_namespace
    └── nested_namespace
        └── subpackage_c
            └── __init__.py

This is how I use packages in each pyproject.toml:

[tool.poetry]
...
packages = [{ include = "root_namespace" }]
...

This picks up root_namespace and the subpackages in the generated setup.py.

foo-project/setup.py:

packages = \
['root_namespace',
 'root_namespace.nested_namespace.subpackage_a',
 'root_namespace.nested_namespace.subpackage_b']

bar-project/setup.py:

packages = \
['root_namespace',
 'root_namespace.nested_namespace.subpackage_c']

Installing both places the files in the correct directories.

0reactions
dfeecommented, Aug 9, 2018

@moigagoo I’m not understanding how your project doesn’t follow the PEP420 guidelines. Is it because you don’t have and __init__.py https://github.com/foliant-docs/foliantcontrib.bump/tree/develop/foliant/cli

Read more comments on GitHub >

github_iconTop Results From Across the Web

Packaging namespace packages
Each sub-package can now be separately installed, used, and versioned. Namespace packages can be useful for a large collection of loosely-related packages (such ......
Read more >
Python package with optional namespace sub-packages
I am trying to create a python package with optional namespace sub-package dependencies that I can install from a private git repo. Below...
Read more >
Create python package toolbox using poetry + namespace
In this case, each sub-package can be separately installed, used, and versioned. There are three ways to create namespace package: native namespace packages....
Read more >
4. Package structure and distribution
A “namespace” in Python is a mapping from names to objects. ... To create an installable package, we need a tool capable of...
Read more >
Making a Python Package
A python “module” is a single namespace, with a collection of values: ... There are a bunch of nifty tools that help you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found