Python Forum
Packaging a single module(file) with a non-code file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Packaging a single module(file) with a non-code file
#1
I'm trying to package my single-file tool with a README.md file for pip. I've tried couple of ways but failed. Here is one of them.

The file structure is very simple:

pytreelog/
|- README.md
|- pytreelog.py


I suppose the following would have worked (added 3 files: ):

pytreelog/
|- README.md
|- pytreelog.py
|
|- __init__.py
|- setup.py
|- MANIFEST.in

Where:

__init__.py:
name = "pytreelog"

MANIFEST.in:
include README.md

setup.py:
#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='pytreelog-runsun',
      version='20190405.post6',
      description='Tree-like logging util for python',
      author='runsun',
      author_email= <my email>,
      url= <the url>,
      packages=find_packages(),
      py_modules = ["pytreelog"],
      include_package_data=True, # Need this to include README.md in the pacakge
      classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
       ]
     )
Then I run this:

...pytreelog> python setup.py sdist bdist_wheel

The new folder structure (dist/* are displayed):

pytreelog/
|- README.md
|- pytreelog.py
|
|- __init__.py
|- setup.py
|- MANIFEST.in
|
|- build/
|- dist/
| -- pytreelog-runsun-20190405.post6.tar.gz
| -- pytreelog_runsun-20190405.post6-py3-none-any.whl
|- pytreelog_runsun.egg-info/


Then I switch to dist/ and run this:

...pytreelog\dist> pip install pytreelog_runsun-20190405.post6-py3-none-any.whl

The console responded saying it's successfully installed. So now I have my lib in the /site-packages:

C:/python37/Lib/site-packages/
| ...
|- pytreelog_runsun-20190405.post6.dist-info/
|- pytreelog.py

The pytreelog.py is there (as a stand-alone file) but, where is my README.md? How can I get it installed with my lib?
Reply
#2
(Apr-06-2019, 12:31 AM)runsun Wrote: How can I get it installed with my lib?
If you want to add files when build it,you should build it as package not as a module.
So eg pytreelog should be you package folder,then one level up setup.py,MANIFEST.in,setup.cfg ect...

If look at part of tutorial here a part of this tutorial
So if add a folder in div_pack\doc with README.md,README.rst.
Then in MANIFEST.in:
include div_pack/LICENSE.txt
include div_pack/doc/README.md
include div_pack/doc/README.rst
Then stuff over will be added when built it:
python setup.py bdist_wheel
Reply
#3
Thx, that works nicely.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file open "file not found error" shanoger 8 1,087 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 761 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 921 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,089 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,541 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,111 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 721 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  How to run code again in module ? rajamani 2 896 Nov-10-2022, 02:38 PM
Last Post: snippsat
  python Multithreading on single file mg24 3 1,725 Nov-05-2022, 01:33 PM
Last Post: snippsat
  Code Assistance needed in saving the file MithunT 0 811 Oct-09-2022, 03:50 PM
Last Post: MithunT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020