0

Few days ago I've created a little project called pyblime and right now I was trying to figure out how to create a proper setup.py that allowed me to upload the "right stuff" to PyPi so users will be able to enjoy the project by using pip without doing anything "too fancy" like calling fancy custom dev scripts, right now the project tree structure looks like this:

│   .gitignore
│   configure.py
│   MANIFEST.in
│   README.md
│   requirements.txt
│   setup.py
│   
├───data
│   ├───commands
│   │       comment.py
│   │       fold.py
│   │       
│   ├───screenshots
│   │       test_simple.png
│   │       test_themes.gif
│   │       
│   ├───st_build_3149
│   │   ├───syntax
│   │   └───themes
│   └───testfiles
├───docs
│       build.md
│       contributing.md
│       guidelines.md
│       usage.md
│       
├───examples
│       demo_00.py
│       tutorials.py
│       tutorial_00.py
│       tutorial_01.py
│       tutorial_02.py
│       tutorial_03.py
│       tutorial_04.py
│       tutorial_05.py
│       tutorial_06.py
│       
├───pyblime
│       utils.py
│       view.py
│       __init__.py
│       
├───sublime_text
│       sublime.py
│       sublime_plugin.py
│       
└───tests
        run_all.py
        test_scopes.py
        test_view.py
        x.py

Rather than 1 question, I've got few simple doubts:

  • What'd be the "standard" way to instruct setup.py to copy sublime_text/sublime.py and sublime_text/sublime_plugin.py files into Lib/site-packages root?
  • How'd you tell setup.py to copy the whole folder pyblime adhoc in Lib/site-packages?
  • Finally, is it correct to upload tests/examples/tests/docs/data to PyPi? This is, content that won't be necessary to use the SDK/library itself... If it's not, where would you include this type of data... I'm aware there exists the concept of sdist&dist folders and I've already read a bit about it here but the question still remains :)

Right now my setup.py looks something like this:

from pathlib import Path
from setuptools import setup

root_path = Path(__file__).parent
requirements = (root_path / "requirements.txt").read_text()
requirements = [
    v for v in requirements.split("\n")
    if v.strip() and not v.strip().startswith("#")
]
readme = (root_path / "README.md").read_text()

setup(
    author="mcve",
    author_email="mcve",
    classifiers=["mcve"],
    description="mcve",
    install_requires=requirements,
    keywords=["mcve"],
    long_description=(root_path / "README.md").read_text(),
    name="mcve",
    # package_data = {}, <---- How do i use this?
    # packages = [], <---- Do I need to use this?
    url="mcve",
    version="0.0.1",
)

Ps. And yeah... I've already read the official docs out there about packaging... but if I had understood those docs I wouldn't be asking this on SO ;D . Thanks in advance!

1 Answer 1

2

Well, let's step by step.


For the first question. Mostly you shouldn't do that, instead, you should consider sublime_text as a package too. The structure should look like:

├───sublime_text
|       __init__.py
│       sublime.py
│       sublime_plugin.py

And you should use it like from sublime_text import sublime in your other packages. That's could be better as you won't pollute the global namespace too much. Or if this is not a common package that you want to share between many other packages, you can directly include it as a submodule in your main package.

Or if you really wanna do this, you can place those two files in the root directory and use:

...
packages = find_packages(),
py_modules=["sublime", "sublime_plugin"],
...

For the second question. As that is a package, you can add that path to packages: packages=[""]. Or for convenience, you can use packages=find_packages(). It will help you to find all packages under the current directory which is "".


For your third question. Mostly it is not correct, you just need to submit what user needs to the PyPi. For docs, you should use readthedocs website. And for other examples and tests, just leave them on your Github. That's enough.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.