Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify "setup.py"(entry_points) when I want to generate multiple command-line applications from sub-module and in a python package #3

Open
chxp opened this issue Apr 6, 2021 · 2 comments

Comments

@chxp
Copy link

chxp commented Apr 6, 2021

I want to write a small personal package based on your scripts.
The structure of the directory is showed here:
I further add a new module (src) and script (case.py) under bootstrap fold like this:

python-cmdline-bootstrap/
...
├── bootstrap
│   ├── __init__.py
│   ├── __main__.py
│   ├── bootstrap.py
│   ├── stuff.py
│   ├── src
│       ├── __init__.py
│       ├── case.py
├── bootstrap-runner.py
...

the content of case.py showed below:

# -*- coding: utf-8 -*-

import argparse


def case():
    print("This a new command.")

I add the following lines into the setup.py:

console_scripts = """
[console_scripts]
bootstrap = bootstrap.bootstrap:main
cccase = bootstrap.src.case:case
"""

When I execute python setup.py install and run cccase in the terminal after installation, it shows the error:

Traceback (most recent call last):
  File "/home/chxp/tmp/python3-test/bin/cccase", line 11, in <module>
    load_entry_point('cmdline-bootstrap==0.2.0', 'console_scripts', 'cccase')()
  File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'bootstrap.src'

It works fine if I use ./bootstrap-runner.py or python -m bootstrap (I modify them also), I think it may a mistake in the setup.py.
Thus, how do I revise the setup.py? I want to generate different command-line applications in a python package.

Meanwhile, how do I test multiple command-line applications by using ./bootstrap-runner.py or python -m bootstrap in a single run.
It seems I need to change the content in __main__.py or bootstrap-runner.py to test each command-line application, such as bootstrap, cccase.

The original scripts are upload at " https://gitee.com/chxp/python-cmdline-bootstrap " and download by git clone https://gitee.com/chxp/python-cmdline-bootstrap.git.

Thanks for your help. (I also asked it on Stackoverflow: https://stackoverflow.com/questions/66954048/how-to-write-the-accurate-setup-pyentry-points-when-i-want-to-generate-multi )

@chxp
Copy link
Author

chxp commented Apr 7, 2021

I find a solution! It seems parameter of packages in function setup could not recongnize the sub module if you specify the packages.

So the following changes will work:

from setuptools import setup, find_packages

setup(
    name="cmdline-bootstrap",
    packages=find_packages(),
    entry_points=console_scripts,
    version=version,
    description="Python command line application bare bones template.",
    long_description=long_descr,
    author="Jan-Philip Gehrcke",
    author_email="jgehrcke@googlemail.com",
    url="http://gehrcke.de/2014/02/distributing-a-python-command-line-application",
)

Just replace the packages=["bootstrap"] by using packages=find_packages().

But I still do not know how to really explain the problem and what I need to do if I still want to use packages=["bootstrap"].

@jgehrcke
Copy link
Owner

jgehrcke commented Jun 1, 2022

Thank you for documenting things here @chxp ❤️!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants