Uncategorized

pypi – Python install from subdirectory without changing folder structure


So I made a whole github repo with a LOT of stuff in it, but then one day I wanted to turn it into a pypi project

So I spend a very long time fiddling with the setup.py and the auto-python-upload.yaml github action and I figure out that for it to work I need it to put all the files in a directory lower

Example:

Instead of the github repo baz looking like this:

├── readme.md
├── __init__.py
│── foo
│   ├── bar.py
│   └── __init__.py

It needs to be something like:

├── readme.md
├── setup.py
│── baz
|   ├── __init__.py
|   │── foo
│   |   ├── bar.py
│   |   └── __init__.py

And that’s an issue, both for the user having to deal with the project not being shown like it usually is where you can see all the top-level files and also for another situation I also need to solve

But I managed to only fix this because pypi was having a good day and let me upload the entire thing

Is when you do NOT wish to upload to pypi and just wish to install it from git.

In a separate repo, I figured out with the command pip install "git+https://github.com/authour/repo#egg=subdir&subdirectory=subdir" and with a setup.py being put in that folder you can install the package….. but there’s a catch.

Example

I attempted to install the package foo with a file directory like this:

├── readme.md
├── __init__.py
│── foo
|   ├── setup.py
│   ├── bar.py
|   |── hi
|   |   └── hi.py
│   └── __init__.py
├── other files and folders

But when I looked in site-packages the only folder that was there was hi, not foo which was the folder I wished to install.

So I believe I have to change it to:

├── readme.md
├── __init__.py
│── foo
|   ├── setup.py
|   |── foo
│   |   ├── bar.py
|   |   |── hi
|   |   |   └── hi.py
│   |   └── __init__.py
├── other files and folders

But that would

  1. Be silly to have the code look like import foo.foo.bar
  2. be annoying if you’ve referenced it in A LOT of other files, having to change them all
  3. be an annoying directory structure to look at

Please help fix! Would be appreciated.

Thanks!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *