├── .github └── workflows │ ├── publish.yml │ ├── test.yml │ └── welcome.yml ├── .gitignore ├── Makefile ├── README.md ├── setup.py ├── src ├── __init__.py └── hello.py └── test └── test_hello.py /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish WorkFlow 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | python-version: [3.8] 13 | steps: 14 | - name: 🛎️ Checkout 15 | uses: actions/checkout@v3 16 | with: 17 | ref: ${{ github.head_ref }} 18 | - name: 🐍 Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | - name: 🦾 Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install ".[dev]" 26 | - name: 🚀 Publish to PyPi 27 | env: 28 | PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} 29 | PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 30 | PYPI_TEST_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }} 31 | run: | 32 | make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test WorkFlow 2 | 3 | on: 4 | pull_request: 5 | branches: [main] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | python-version: [3.7, 3.8, 3.9] 13 | steps: 14 | - name: 🛎️ Checkout 15 | uses: actions/checkout@v3 16 | with: 17 | ref: ${{ github.head_ref }} 18 | - name: 🐍 Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | - name: 🦾 Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install ".[dev]" 26 | - name: 🧹 Lint with flake8 27 | run: | 28 | make check_code_quality 29 | - name: 🧪 Test 30 | run: "python -m pytest ./test" -------------------------------------------------------------------------------- /.github/workflows/welcome.yml: -------------------------------------------------------------------------------- 1 | on: 2 | issues: 3 | types: [opened] 4 | pull_request_target: 5 | types: [opened] 6 | 7 | jobs: 8 | build: 9 | name: 👋 Welcome 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/first-interaction@v1.1.1 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | issue-message: "Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap." 16 | pr-message: "Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap." -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 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 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: style check_code_quality 2 | 3 | export PYTHONPATH = . 4 | check_dirs := src 5 | 6 | style: 7 | black $(check_dirs) 8 | isort --profile black $(check_dirs) 9 | 10 | check_code_quality: 11 | black --check $(check_dirs) 12 | isort --check-only --profile black $(check_dirs) 13 | # stop the build if there are Python syntax errors or undefined names 14 | flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics 15 | # exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators 16 | flake8 $(check_dirs) --count --max-line-length=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics 17 | 18 | publish: 19 | python setup.py sdist bdist_wheel 20 | twine upload -r testpypi dist/* -u ${PYPI_USERNAME} -p ${PYPI_TEST_PASSWORD} --verbose 21 | twine check dist/* 22 | twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --verbose -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Template 🐍 2 | A template repo holding our common setup for a python project. 3 | 4 | ## Installation 5 | 6 | You can install the package using pip 7 | 8 | ```bash 9 | pip install -e . 10 | ``` 11 | 12 | or for development 13 | 14 | ```bash 15 | pip install -e ".[dev]" 16 | ``` 17 | 18 | ## Structure 19 | 20 | The project has the following structure 21 | 22 | ``` 23 | ├── .github 24 | │ └── workflows 25 | │ └── test.yml # holds our github action config 26 | ├── .gitignore 27 | ├── Makefile 28 | ├── README.md 29 | ├── setup.py 30 | ├── src 31 | │ ├── __init__.py 32 | │ ├── hello.py 33 | └── test 34 | └── test_hello.py 35 | ``` 36 | 37 | ### Code Quality 🧹 38 | 39 | We provide two handy commands inside the `Makefile`, namely: 40 | 41 | - `make style` to format the code 42 | - `make check_code_quality` to check code quality (PEP8 basically) 43 | 44 | So far, **there is no types checking with mypy**. See [issue](https://github.com/roboflow-ai/template-python/issues/4). 45 | 46 | ### Tests 🧪 47 | 48 | [`pytests`](https://docs.pytest.org/en/7.1.x/) is used to run our tests. 49 | 50 | ### Publish on PyPi 🚀 51 | 52 | **Important**: Before publishing, edit `__version__` in [src/__init__](/src/__init__.py) to match the wanted new version. 53 | 54 | We use [`twine`](https://twine.readthedocs.io/en/stable/) to make our life easier. You can publish by using 55 | 56 | ``` 57 | export PYPI_USERNAME="you_username" 58 | export PYPI_PASSWORD="your_password" 59 | export PYPI_TEST_PASSWORD="your_password_for_test_pypi" 60 | make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD 61 | ``` 62 | 63 | You can also use token for auth, see [pypi doc](https://pypi.org/help/#apitoken). In that case, 64 | 65 | ``` 66 | export PYPI_USERNAME="__token__" 67 | export PYPI_PASSWORD="your_token" 68 | export PYPI_TEST_PASSWORD="your_token_for_test_pypi" 69 | make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD 70 | ``` 71 | 72 | **Note**: We will try to push to [test pypi](https://test.pypi.org/) before pushing to pypi, to assert everything will work 73 | 74 | ### CI/CD 🤖 75 | 76 | We use [GitHub actions](https://github.com/features/actions) to automatically run tests and check code quality when a new PR is done on `main`. 77 | 78 | On any pull request, we will check the code quality and tests. 79 | 80 | When a new release is created, we will try to push the new code to PyPi. We use [`twine`](https://twine.readthedocs.io/en/stable/) to make our life easier. 81 | 82 | The **correct steps** to create a new realease are the following: 83 | - edit `__version__` in [src/__init__](/src/__init__.py) to match the wanted new version. 84 | - create a new [`tag`](https://git-scm.com/docs/git-tag) with the release name, e.g. `git tag v0.0.1 && git push origin v0.0.1` or from the GitHub UI. 85 | - create a new release from GitHub UI 86 | 87 | The CI will run when you create the new release. 88 | 89 | # Q&A 90 | 91 | ## Why no cookiecutter? 92 | This is a template repo, it's meant to be used inside GitHub upon repo creation. 93 | 94 | ## Why reinvent the wheel? 95 | 96 | There are several very good templates on GitHub, I prefer to use code we wrote instead of blinding taking the most starred template and having features we don't need. From experience, it's better to keep it simple and general enough for our specific use cases. -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | from setuptools import find_packages 3 | import re 4 | 5 | with open("./src/__init__.py", 'r') as f: 6 | content = f.read() 7 | # from https://www.py4u.net/discuss/139845 8 | version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1) 9 | 10 | with open("README.md", "r") as fh: 11 | long_description = fh.read() 12 | 13 | setuptools.setup( 14 | name="template-python-zuppif#1", 15 | version=version, 16 | author="zuppif", 17 | author_email="francesco.zuppichini@gmail.com", 18 | description="", 19 | long_description=long_description, 20 | long_description_content_type="text/markdown", 21 | url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", 22 | install_requires=[ 23 | # list your requires 24 | ], 25 | packages=find_packages(exclude=("tests",)), 26 | extras_require={ 27 | "dev": ["flake8", "black==22.3.0", "isort", "twine", "pytest", "wheel"], 28 | }, 29 | classifiers=[ 30 | "Programming Language :: Python :: 3", 31 | "License :: OSI Approved :: MIT License", 32 | "Operating System :: OS Independent", 33 | ], 34 | python_requires=">=3.7", 35 | ) 36 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.0.5" 2 | -------------------------------------------------------------------------------- /src/hello.py: -------------------------------------------------------------------------------- 1 | def hello() -> str: 2 | return "World" 3 | -------------------------------------------------------------------------------- /test/test_hello.py: -------------------------------------------------------------------------------- 1 | from src.hello import hello 2 | 3 | 4 | def test_hello(): 5 | res = hello() 6 | assert res == "World" --------------------------------------------------------------------------------