├── setup.cfg ├── index.py ├── structure ├── __init__.py └── structure.py ├── requirements.txt ├── setup.py ├── .gitignore ├── LICENSE └── README.md /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /index.py: -------------------------------------------------------------------------------- 1 | import structure 2 | g1 = structure.greeter() 3 | g1.greet() 4 | 5 | structure.hi() 6 | 7 | -------------------------------------------------------------------------------- /structure/__init__.py: -------------------------------------------------------------------------------- 1 | __title__ = 'structure' 2 | __version__ = '0.1.7' 3 | 4 | from .structure import greeter, hi -------------------------------------------------------------------------------- /structure/structure.py: -------------------------------------------------------------------------------- 1 | 2 | class greeter(object): 3 | # constructor 4 | def __init__(self, name='greeter'): 5 | self.name = name 6 | 7 | # method 8 | def greet(self, msg='Hello World'): 9 | print(msg) 10 | 11 | def hi(msg='Say Hi'): 12 | print(msg) 13 | 14 | if __name__ == '__main__': 15 | h1 = greeter() 16 | h1.greet() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cffi==1.5.0 2 | characteristic==14.3.0 3 | cryptography==1.2.2 4 | cssselect==0.9.1 5 | idna==2.0 6 | lxml==3.5.0 7 | pyasn1==0.1.9 8 | pyasn1-modules==0.0.8 9 | pycparser==2.14 10 | pyOpenSSL==0.15.1 11 | queuelib==1.4.2 12 | Scrapy==1.0.4 13 | service-identity==14.0.0 14 | six==1.10.0 15 | Twisted==15.5.0 16 | w3lib==1.13.0 17 | wheel==0.26.0 18 | zope.interface==4.1.3 19 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | from setuptools import setup, find_packages 5 | from structure import __version__ 6 | 7 | 8 | # Utility function to read the README file. 9 | # Used for the long_description. It's nice, because now 1) we have a top level 10 | # README file and 2) it's easier to type in the README file than to put a raw 11 | # string in below ... 12 | def read(fname): 13 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 14 | 15 | # the setup 16 | setup( 17 | name='structure', 18 | version=__version__, 19 | description='An demonstration of PyPi.', 20 | # long_description=read('README'), 21 | url='https://github.com/kengz/structure', 22 | author='kengz', 23 | author_email='kengzwl@gmail.com', 24 | license='MIT', 25 | keywords='example pypi tutorial', 26 | packages=find_packages(exclude=('docs', 'tests', 'env', 'index.py')), 27 | include_package_data=True, 28 | install_requires=[ 29 | ], 30 | extras_require={ 31 | 'dev': [], 32 | 'docs': [], 33 | 'testing': [], 34 | }, 35 | classifiers=[], 36 | ) 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # System Files 2 | .DS_Store 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | env/ 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *,cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | 59 | # Sphinx documentation 60 | docs/_build/ 61 | 62 | # PyBuilder 63 | target/ 64 | 65 | #Ipython Notebook 66 | .ipynb_checkpoints 67 | 68 | # pyenv 69 | .python-version -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Wah Loon Keng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-structure 2 | Sample project structure for a python package, contains all the necessary files to publish a PyPI package. 3 | 4 | 5 | ## Guide 6 | 7 | - use `Python 3` and `pip3` like `npm` 8 | - use `virtualenv` like `node_modules` 9 | 10 | ### Tool Installation 11 | 12 | ```bash 13 | pip3 install virtualenvwrapper 14 | echo " 15 | # python virtualenv 16 | source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bash_profile 17 | ``` 18 | 19 | ### Project creation 20 | 21 | I'm assuming my PyPI package name is `structure`. Also, don't use non-alphabetic characters; for exampl PyPI will not allow '-' and '_'. 22 | 23 | - create a project on Github, add `README, .gitignore, LICENSE`. Clone your git repo locally. 24 | - update your `.gitignore` (see example) and remove `.md` from `README.md` cuz PyPI can't even 25 | - create a `setup.py` (see example). 26 | - make a folder with your package name to contain your source code. `mkdir structure` in my case. 27 | - since the folder will be a module, add `structure/__init__.py`; this file will also contain the version, and the packaged methods. 28 | - add any of your Python source code under `structure.py` and import the needed module methods in `structure/__init__.py` 29 | - finally, at the root, do `pip3 freeze > requirements.txt` to generate list of dependencies you used, so it can install with `pip3 install -r requirements.txt` 30 | 31 | 32 | ### Packaging 33 | 34 | Now that you have the project, it's time to publish. Navigate to the project root. First, register your package name; this may prompt you to create an account and login if it's your first time: 35 | 36 | ``` 37 | python setup.py register 38 | ``` 39 | 40 | Then, if the package name is registered successfully, upload your source to PyPI: 41 | 42 | ``` 43 | python setup.py sdist upload 44 | ``` 45 | 46 | Then wait for a **bazillion years** for PyPI to update it on their server before you can `pip install` it. 47 | 48 | 49 | ### Usage 50 | 51 | The `./index.py` is a test file ignored in `setup.py`. A close thing to npm's `node_modules` is to create a virtual env to install dependencies and run code from: 52 | 53 | ``` 54 | # go to the root of your project folder to create env 55 | virtualenv env 56 | # activate the created virtual env 57 | source env/bin/activate 58 | # type 'deactivate' inside to quit 59 | 60 | # install the package inside env 61 | pip3 install -U structure 62 | # Get ready the source code below before run: 63 | python3 index.py 64 | ``` 65 | 66 | 67 | Inside `./index.py` there's a sample code: 68 | 69 | ```python 70 | # the package 71 | import structure 72 | 73 | # using class 74 | g1 = structure.greeter() 75 | g1.greet() 76 | 77 | # using module method 78 | structure.hi() 79 | ``` 80 | --------------------------------------------------------------------------------