0

So, I was working on one of my projects when I decided that I would make it a command-line-based tool. I could not find any reliable information (maybe I just searched for the wrong thing, sorry if this is a duplicate, I am new to packaging). I have seen many other projects do it so that all they need to do is:

pip install packageName

packageName -args

I tried doing this, I added arguments, so that works, but I am not sure how to do this. I have tried looking for solutions, and I have only come across some topics on stackoverflow that only talk about dealing with file permissions using chmod commands, etc. I am just confused.

So at this point, I was expecting my file to be executable, or make it in an easy way / have a way to do it through python packaging, but I still am not sure how. I just want my package to be installed with pip, and then easily executed without having to use "python3" and ".py" and having to CD into the project directory every time of use.

I tried searching the internet but no information has come across to me yet.

I am sorry for duplicates. I have looked at other solutions but they all use chmod and I just want to package it in a python package through PyPi.

Please, if you can help, it would be great.

Thanks in advance.

PatzEdi
  • 1
  • 3
  • Are you looking for an entrypoint? See https://packaging.python.org/en/latest/specifications/entry-points/ – Sören Feb 17 '23 at 16:19
  • https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html – Jared Smith Feb 17 '23 at 16:24
  • @JaredSmith ah. Thanks so much. I was looking at the article/documentation you gave me, and I am wondering, under where it says "The scripts KeyWord argument", why do I need to add a bin directory within the project? – PatzEdi Feb 17 '23 at 16:29
  • @Sören, the article the other guy gave me was based off of python2, which had different importing mechanisms, so it does not work. Yes, I am trying to do that. Can you help me out please? Thanks. – PatzEdi Feb 17 '23 at 16:47
  • @PatzEdi that is traditional but not required, the path in your argument to scripts just needs to point at your executable – Jared Smith Feb 17 '23 at 17:01
  • 1
    @JaredSmith I see... I will try things out – PatzEdi Feb 17 '23 at 18:27

1 Answers1

0

After a couple of hours, I was able to solve the problem.

Here is the full explanation:

https://setuptools.pypa.io/en/latest/userguide/entry_point.html

This helped so much. All I needed to do was to put:

[project.scripts]

projectName = "pathtofunction"

I solved all the issues regarding importing by putting all of the code in the init.py file.

Hope this helps to anyone who had any trouble.

PatzEdi
  • 1
  • 3