From 722a4a8ba841eadea92a3651320a2f9f69ba311e Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 15:59:01 +0700 Subject: [PATCH 01/11] doc: update REAMDE to include description, how to install the CLI --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eaea4a4..28cbce5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -# cli -Aitomatic CLI +# Aitomatic CLI + +The Command Line Interface (CLI) to create a project, build an image or deploy apps to Aitomatic cloud. + +## Prerequisite + +1. python3 +2. pip + +## Installing + +To install this CLI tool you can run the below command +```shell +pip3 install aitomatic +``` +Alternatively, you clone this repo and then run this command from within the repository folder +```shell +python3 setup.py install +``` +Both the above commands would install the package globally and `aitomatic` will be available on your system. + +## How to use + +## Feedback From b9687f70845c1072b66be45fff3fa7117db629d2 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 16:00:04 +0700 Subject: [PATCH 02/11] doc: add CODEOWNERS, guide to contribute, LICENSE and MANIFEST, requirements.txt --- CODEOWNERS | 5 +++++ CONTRIBUTING.md | 31 +++++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ MANIFEST.in | 1 + requirements.txt | 3 +++ 5 files changed, 61 insertions(+) create mode 100644 CODEOWNERS create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 requirements.txt diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..7b2bee1 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,5 @@ +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# following users will be requested for +# review when someone opens a pull request. +* @phamhoangtuan @phanhongan diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b44c9b5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# Guide to contribute to this repository + +## Prerequisite + +1. python3 +2. pip +3. virtualenv +```shell +pip install virtualenv +``` + +## Steps to setup dev environment + +1. Create a python3 virtual environment +```shell +virtualenv .venv -p python3 +``` +2. Activate the virtual environment created in step 1 +```shell +source .venv/bin/activate +``` +3. Install libraries in file requirements.txt +```shell +pip install -r requirements.txt +``` + +## Steps to test code in local + +## Steps to install the CLI to virtual environment and test it + +## Steps to package and distribute CLI to PyPI diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a291151 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Aitomatic + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..cc0d116 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a07df44 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +setuptools >= 60.10.0 # library to package code +twine >= 3.8.0 # library to distribute package to PyPI +click >= 8.0.4 # library to create CLI From 0b806348394f0ed76a96cf21bd4822b5fe912f21 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 16:21:56 +0700 Subject: [PATCH 03/11] doc: update step to install lib, remove libs in requirements.txt --- CONTRIBUTING.md | 6 +++++- requirements.txt | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b44c9b5..449e265 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,11 @@ virtualenv .venv -p python3 ```shell source .venv/bin/activate ``` -3. Install libraries in file requirements.txt +3. Install `setuptools` to package code, `twine` to distribute package to PyPI and `black` to format python code +```shell +pip install setuptools twine black +``` +4. Install libraries in file requirements.txt ```shell pip install -r requirements.txt ``` diff --git a/requirements.txt b/requirements.txt index a07df44..0c2a774 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -setuptools >= 60.10.0 # library to package code -twine >= 3.8.0 # library to distribute package to PyPI click >= 8.0.4 # library to create CLI From 1dcf7d65274d88ed0ba89fdde077fbb5bc57b643 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 17:10:24 +0700 Subject: [PATCH 04/11] doc: add step to remove old package in local --- CONTRIBUTING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 449e265..808275a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,4 +32,21 @@ pip install -r requirements.txt ## Steps to install the CLI to virtual environment and test it +1. Remove old CLI package in local +```shell +rm -rf .venv/bin/aitomatic aitomatic.egg-info +``` +2. Run command to install CLI +```shell +python setup.py develop +``` +3. Verify the CLI +```shell +which aitomatic +``` +4. Run CLI hello command +```shell +aitomatic hello +``` + ## Steps to package and distribute CLI to PyPI From 24d9fa5e85595ab3ec659de346901802a0b28aaa Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 17:11:11 +0700 Subject: [PATCH 05/11] feat: add code to hello cli --- aitomatic.py | 13 +++++++++++++ app/deploy.py | 0 setup.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 aitomatic.py create mode 100644 app/deploy.py create mode 100644 setup.py diff --git a/aitomatic.py b/aitomatic.py new file mode 100644 index 0000000..34f7d1f --- /dev/null +++ b/aitomatic.py @@ -0,0 +1,13 @@ +import click + + +@click.group() +def aitomatic_cli(): + pass + +@aitomatic_cli.command() +def hello(): + click.echo('Welcome to Aitomatic CLI!') + +if __name__ == '__main__': + aitomatic_cli() diff --git a/app/deploy.py b/app/deploy.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fe5dc23 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +from setuptools import setup, find_packages + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() +with open("requirements.txt", "r", encoding="utf-8") as fh: + requirements = fh.read() + +setup( + name = 'aitomatic', + version = '0.1.0', + author = 'Pham Hoang Tuan', + author_email = 'tuan@aitomatic.com', + license = 'MIT', + description = 'aitomatic CLI', + long_description = long_description, + long_description_content_type = "text/markdown", + url = 'https://github.com/aitomatic/aitomatic-cli', + py_modules = ['aitomatic', 'app'], + packages = find_packages(), + install_requires = [requirements], + python_requires='>=3.7', + classifiers=[ + "Programming Language :: Python :: 3.8", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + entry_points = ''' + [console_scripts] + aitomatic=aitomatic:aitomatic_cli + ''' +) From 097027092ee3c1bc6b0f1e72c0fcee8cf377ac5b Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 22 Mar 2022 17:21:45 +0700 Subject: [PATCH 06/11] doc: update step to dev and test script --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 808275a..c342d02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,15 @@ pip install -r requirements.txt ## Steps to test code in local +1. Run `black` command to format code +```shell +black -S . +``` +2. Run command to test script +```shell +python aitomatic.py hello +``` + ## Steps to install the CLI to virtual environment and test it 1. Remove old CLI package in local From 7eff992205a05846195ad9ed179999fc12574fce Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 23 Mar 2022 14:48:49 +0700 Subject: [PATCH 07/11] feat: orgade to src folder --- CONTRIBUTING.md | 14 +++++--------- app/deploy.py | 0 setup.py | 3 +-- aitomatic.py => src/aitomatic.py | 9 +++++++++ src/app/deploy.py | 5 +++++ 5 files changed, 20 insertions(+), 11 deletions(-) delete mode 100644 app/deploy.py rename aitomatic.py => src/aitomatic.py (64%) create mode 100644 src/app/deploy.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c342d02..60e1696 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,24 +36,20 @@ black -S . ``` 2. Run command to test script ```shell -python aitomatic.py hello +python src/aitomatic.py hello ``` ## Steps to install the CLI to virtual environment and test it -1. Remove old CLI package in local +1. Run command to install CLI ```shell -rm -rf .venv/bin/aitomatic aitomatic.egg-info +pip install -e . ``` -2. Run command to install CLI -```shell -python setup.py develop -``` -3. Verify the CLI +2. Verify the CLI ```shell which aitomatic ``` -4. Run CLI hello command +3. Run `aitomatic hello` command ```shell aitomatic hello ``` diff --git a/app/deploy.py b/app/deploy.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.py b/setup.py index fe5dc23..6b12667 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,6 @@ long_description = long_description, long_description_content_type = "text/markdown", url = 'https://github.com/aitomatic/aitomatic-cli', - py_modules = ['aitomatic', 'app'], packages = find_packages(), install_requires = [requirements], python_requires='>=3.7', @@ -26,6 +25,6 @@ ], entry_points = ''' [console_scripts] - aitomatic=aitomatic:aitomatic_cli + aitomatic=src.aitomatic:aitomatic_cli ''' ) diff --git a/aitomatic.py b/src/aitomatic.py similarity index 64% rename from aitomatic.py rename to src/aitomatic.py index 34f7d1f..43e054d 100644 --- a/aitomatic.py +++ b/src/aitomatic.py @@ -1,13 +1,22 @@ import click +from src.app.deploy import deploy @click.group() def aitomatic_cli(): pass + @aitomatic_cli.command() def hello(): click.echo('Welcome to Aitomatic CLI!') + +@aitomatic_cli.group() +def app(): + pass + +app.add_command(deploy) + if __name__ == '__main__': aitomatic_cli() diff --git a/src/app/deploy.py b/src/app/deploy.py new file mode 100644 index 0000000..8006dc9 --- /dev/null +++ b/src/app/deploy.py @@ -0,0 +1,5 @@ +import click + +@click.command() +def deploy(): + click.echo('Deploy app to Aitomatic') From 562050f215d172562c5711e4182fa6c56ffc53d9 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 23 Mar 2022 14:55:39 +0700 Subject: [PATCH 08/11] feat: remove hello command, add help to command group, fix contributing doc --- CONTRIBUTING.md | 6 +++--- src/aitomatic.py | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60e1696..06ca1ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,7 @@ black -S . ``` 2. Run command to test script ```shell -python src/aitomatic.py hello +python src/aitomatic.py ``` ## Steps to install the CLI to virtual environment and test it @@ -49,9 +49,9 @@ pip install -e . ```shell which aitomatic ``` -3. Run `aitomatic hello` command +3. Run `aitomatic` command ```shell -aitomatic hello +aitomatic ``` ## Steps to package and distribute CLI to PyPI diff --git a/src/aitomatic.py b/src/aitomatic.py index 43e054d..cfaaee6 100644 --- a/src/aitomatic.py +++ b/src/aitomatic.py @@ -2,17 +2,16 @@ from src.app.deploy import deploy -@click.group() +@click.group(help=''' + Aitomatic CLI tool to help manage aitomatic projects and apps +''') def aitomatic_cli(): pass -@aitomatic_cli.command() -def hello(): - click.echo('Welcome to Aitomatic CLI!') - - -@aitomatic_cli.group() +@aitomatic_cli.group(help=''' + CLI sub-command to help manage aitomatic apps +''') def app(): pass From 1b8f8d9b0b1f6c46f4e75c49fced119191d53cd2 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 23 Mar 2022 15:26:29 +0700 Subject: [PATCH 09/11] feat: change to use setup.cfg and pyproject.toml as setuptools best practice --- pyproject.toml | 3 +++ setup.cfg | 30 ++++++++++++++++++++++++++++++ setup.py | 30 ------------------------------ 3 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7badb6e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=60"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..78f2637 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,30 @@ +[metadata] +name = aitomatic-cli +version = 0.1.0 +author = Pham Hoang Tuan +author_email = tuan@aitomatic.com +description = aitomatic CLI to manage projects and apps +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/aitomatic/aitomatic-cli +project_urls = + Bug Tracker = https://github.com/aitomatic/aitomatic-cli/issues +classifiers = + Programming Language :: Python :: 3.8 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +package_dir = + = src +packages = find: +install_requires = + click >= 8.0.4 +python_requires = >=3.7 + +[options.packages.find] +where = src + +[options.entry_points] +console_scripts = + aitomatic = src.aitomatic:aitomatic_cli diff --git a/setup.py b/setup.py deleted file mode 100644 index 6b12667..0000000 --- a/setup.py +++ /dev/null @@ -1,30 +0,0 @@ -from setuptools import setup, find_packages - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() -with open("requirements.txt", "r", encoding="utf-8") as fh: - requirements = fh.read() - -setup( - name = 'aitomatic', - version = '0.1.0', - author = 'Pham Hoang Tuan', - author_email = 'tuan@aitomatic.com', - license = 'MIT', - description = 'aitomatic CLI', - long_description = long_description, - long_description_content_type = "text/markdown", - url = 'https://github.com/aitomatic/aitomatic-cli', - packages = find_packages(), - install_requires = [requirements], - python_requires='>=3.7', - classifiers=[ - "Programming Language :: Python :: 3.8", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - entry_points = ''' - [console_scripts] - aitomatic=src.aitomatic:aitomatic_cli - ''' -) From 8fff297d39ef52ded49a9b8ee7a32514bcb9d20d Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 23 Mar 2022 17:11:52 +0700 Subject: [PATCH 10/11] doc: add steps to distribute package to PyPI, update README doc --- CONTRIBUTING.md | 36 ++++++++++++++++++++++++++++++++++-- README.md | 4 ++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06ca1ae..544f3dd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,9 +19,9 @@ virtualenv .venv -p python3 ```shell source .venv/bin/activate ``` -3. Install `setuptools` to package code, `twine` to distribute package to PyPI and `black` to format python code +3. Install `setuptools` to package code and `black` to format python code ```shell -pip install setuptools twine black +pip install setuptools black ``` 4. Install libraries in file requirements.txt ```shell @@ -54,4 +54,36 @@ which aitomatic aitomatic ``` +## Steps to package and distribute CLI to TestPyPI + +1. Install `build` to generate distribution packages and `twine` to distribute package to PyPI +```shell +pip install build twine +``` +2. Run `build` command as the root folder, where file `pyproject.toml` is located +```shell +python -m build +``` +After that command, we will have `tar.gz` and `.whl` files in `dist` folder + +3. Register an account in TestPyPI and create an API token with `Entire account` scope +4. Using twine to upload the distribution packages created in step 2 to TestPyPI +```shell +twine upload --repository testpypi --skip-existing dist/* +``` +`--repository` used to choose upload to PyPI or TestPyPI, `--skip-existing` if we want to distribute further versions of the cli. + +You will be prompted for a username and password. For the username, use __token__. For the password, use the token value, including the pypi- prefix. +5. Using another virtual environment and install the `aitomatic-cli` using pip to verify that it works +```shell +deactivate +virtualenv .venv-test -p python3 +source .venv-test/bin/activate +pip install --index-url https://test.pypi.org/simple/ aitomatic-cli +``` + ## Steps to package and distribute CLI to PyPI + +Similar to steps to distribute to TestPyPI, except: +- Don't need to specify `--repository` when running twine command +- Don't need to specify `--index-url` when running pip install command diff --git a/README.md b/README.md index 28cbce5..e2c21a7 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ The Command Line Interface (CLI) to create a project, build an image or deploy a To install this CLI tool you can run the below command ```shell -pip3 install aitomatic +pip3 install aitomatic-cli ``` Alternatively, you clone this repo and then run this command from within the repository folder ```shell -python3 setup.py install +pip3 install . ``` Both the above commands would install the package globally and `aitomatic` will be available on your system. From 21cc3a9a93f910b441c1b5c9f494ce3cab4e80e4 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 23 Mar 2022 17:34:43 +0700 Subject: [PATCH 11/11] fix: fix setup.cfg, fix guide in contributing --- .gitignore | 2 ++ CONTRIBUTING.md | 4 ++-- setup.cfg | 11 ++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index b6e4761..7f6b817 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ + +.DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 544f3dd..4bab2a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -79,11 +79,11 @@ You will be prompted for a username and password. For the username, use __token_ deactivate virtualenv .venv-test -p python3 source .venv-test/bin/activate -pip install --index-url https://test.pypi.org/simple/ aitomatic-cli +pip install -i https://test.pypi.org/simple/ aitomatic-cli ``` ## Steps to package and distribute CLI to PyPI Similar to steps to distribute to TestPyPI, except: - Don't need to specify `--repository` when running twine command -- Don't need to specify `--index-url` when running pip install command +- Don't need to specify `-i` when running pip install command diff --git a/setup.cfg b/setup.cfg index 78f2637..7a5b5fe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = aitomatic-cli -version = 0.1.0 +version = 0.1.1 author = Pham Hoang Tuan author_email = tuan@aitomatic.com description = aitomatic CLI to manage projects and apps @@ -15,16 +15,13 @@ classifiers = Operating System :: OS Independent [options] -package_dir = - = src -packages = find: +packages = + src + src.app install_requires = click >= 8.0.4 python_requires = >=3.7 -[options.packages.find] -where = src - [options.entry_points] console_scripts = aitomatic = src.aitomatic:aitomatic_cli