Skip to content

Commit

Permalink
Merge pull request #77 from zhiwei2017/enhancement/upgrade-to-pyproject
Browse files Browse the repository at this point in the history
Enhancement/upgrade to pyproject
  • Loading branch information
zhiwei2017 authored Oct 30, 2023
2 parents 3b92946 + 50e9752 commit 2e764a7
Show file tree
Hide file tree
Showing 19 changed files with 1,422 additions and 204 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_REPOSITORY_URL: ${{ secrets.TWINE_REPOSITORY_URL }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Build and publish package
run: make publish
37 changes: 14 additions & 23 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,32 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Upgrade pip
run: |
# install pip=>20.1 to use "pip cache dir"
python3 -m pip install --upgrade pip
- name: Get pip cache dir
id: pip-cache
run: echo "::set-output name=dir::$(pip cache dir)"

- name: Cache dependencies
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python3 -m pip install -r ./requirements/doc.txt
python3 -m pip install .
run: poetry install --no-interaction --with docs
- name: Build sphinx docs
run: |
cd docs
make html
poetry run make html
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
61 changes: 47 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: make install
- name: Run flake8 check
run: make flake8
- name: Run mypy check
Expand All @@ -42,7 +56,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -51,15 +65,24 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/dev.txt
pip install -e .
run: make install
- name: Test with pytest
run: |
pytest
coverage xml
run: make test
- name: Make coverage report
run: poetry run coverage xml
- name: Codecov Action
uses: Atrox/[email protected]
# This workflow contains a single job called "build"
Expand All @@ -74,11 +97,21 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: pip install twine
- name: Build and test publishing package
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and check package with twine
run: |
python setup.py sdist bdist_wheel
twine check dist/*.whl
make build
poetry run twine check dist/*.whl
18 changes: 8 additions & 10 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ Ready to contribute? Here's how to set up `named_enum` for local development.

Now you can install `named_enum` in develop mode in your virtual environment::

$ python setup.py develop
$ pip install -e .

or::

$ pip install -e .
$ poetry install

4. Create a branch for local development::

Expand All @@ -78,14 +78,13 @@ Ready to contribute? Here's how to set up `named_enum` for local development.
5. When you're done making changes, check that your changes pass all linting checks and the
tests, including testing other Python versions with tox::

$ make install
$ make flake8
$ make mypy
$ make bandit
$ make test
$ tox

To get **flake8**, **mypy**, **bandit** and **tox**, just pip install them into your virtualenv.

6. Commit your changes and push your branch to GitHub::

$ git add .
Expand All @@ -103,17 +102,16 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9.
3. The pull request should work for Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.

Deploying
---------

Assume that bump2version_ is installed. To deploy the package, just run::
To deploy the package, just run::

$ bump2version patch # possible: major / minor / patch
$ poetry version patch # possible: major / minor / patch / premajor / preminor / prepatch
$ git commit -m "Bump version: {old_version} -> {new_version}."
$ git push
$ git push --tags

Github Actions will do the rest.

.. _bump2version: https://github.com/c4urself/bump2version
Github Actions will do the rest.
Empty file removed MANIFEST.in
Empty file.
47 changes: 31 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ help:
@echo "clean : Remove autogenerated folders";
@echo "clean-pyc : Remove python artifacts."
@echo "clean-build : Remove build artifacts."
@echo "bandit : Install and run bandit security analysis.";
@echo "mypy : Install and run mypy type checking.";
@echo "flake8 : Install and run flake8 linting.";
@echo "install : Install all dependencies and the package itself."
@echo "bandit : Run bandit security analysis.";
@echo "mypy : Run mypy type checking.";
@echo "flake8 : Run flake8 linting.";
@echo "test : Run tests and generate coverage report.";
@echo "build_whl : Build a python wheel package.";
@echo "build : Build a python wheel package.";
@echo "publish : Publish a python wheel package to package index.";

# Clean the folder from build/test related folders
clean: clean-build clean-pyc
Expand All @@ -25,28 +27,41 @@ clean-pyc:
clean-build:
rm -rf build/ dist/ *.egg-info

# Install development dependencies
install:
poetry install --with dev,test,docs

# Install and run bandit security analysis
bandit:
python3 -m pip install bandit
python3 -mbandit -r $(SOURCE_DIR)
poetry run bandit -r $(SOURCE_DIR)

# Install and run mypy type checking
mypy:
python3 -m pip install -r requirements/dev.txt
python3 -m pip install mypy
python3 -mmypy $(SOURCE_DIR)
poetry run mypy $(SOURCE_DIR)

# Install and run flake8 linting
flake8:
python3 -m pip install flake8
python3 -mflake8 $(SOURCE_DIR)
poetry run flake8 $(SOURCE_DIR)

# Install requirements for testing and run tests
test:
python3 -m pip install -r requirements/dev.txt
python3 -m pip install -e .
python3 -m pytest
poetry run pytest

# build wheel package
build_whl:
python3 setup.py bdist_wheel
build:
poetry build -f wheel

# publish the built package
publish:
@if [ -n "${POETRY_PYPI_TOKEN_PYPI}" ]; then\
echo "Uploading package to PyPi.";\
poetry publish --build --skip-existing;\
elif [ -n "${PACKAGE_INDEX_REPOSITORY_URL}" ] && [ -n "${PACKAGE_INDEX_USERNAME}" ] && [ -n "${PACKAGE_INDEX_PASSWORD}" ]; then\
echo "Uploading package to private package index ${PACKAGE_INDEX_REPOSITORY_URL}.";\
poetry config repositories.packagidx ${PACKAGE_INDEX_REPOSITORY_URL};\
poetry config http-basic.packagidx "${PACKAGE_INDEX_USERNAME}" "${PACKAGE_INDEX_PASSWORD}";\
poetry publish --build --skip-existing -r packagidx;\
else\
echo "To upload package to a private package index, you need to set environment variables \033[1mPACKAGE_INDEX_REPOSITORY_URL\033[0m \033[1mPACKAGE_INDEX_USERNAME\033[0m and \033[1mPACKAGE_INDEX_PASSWORD\033[0m.";\
exit 1;\
fi
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ To install Named Enum, run this command in your terminal:
$ pip install named_enum
or

.. code-block:: console
$ poetry self add named_enum
This is the preferred method to install Named Enum, as it will always install the most recent stable release.


Expand All @@ -87,13 +93,13 @@ Once you have a copy of the source, you can install it with:

.. code-block:: console
$ python setup.py install
$ pip install .
or

.. code-block:: console
$ pip install .
$ poetry install
Quick Start
-----------
Expand Down
3 changes: 2 additions & 1 deletion docs/source/03_authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Authors
..
Format: `Name <mailto:email>`_ - *Role/Responsibility* - `email <mailto:email?subject=[GitHub]Named%20Enum>`_
* `Zhiwei Zhang <https://github.com/zhiwei2017>`_ - *Maintainer* - `[email protected] <mailto:[email protected]?subject=[GitHub]Named%20Enum>`_
* `Zhiwei Zhang <https://github.com/zhiwei2017>`_ - *Maintainer* - `[email protected] <mailto:[email protected]?subject=[GitHub]Named%20Enum>`_
* `Jianlan Shao <https://github.com/Lan314>`_ - *Developer* - `[email protected] <mailto:[email protected]?subject=[GitHub]Named%20Enum>`_
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import datetime
import importlib.metadata

# -- Project information -----------------------------------------------------

Expand All @@ -23,7 +24,7 @@


# The short X.Y version
version = "1.2.0"
version = importlib.metadata.version("named_enum")
# The full version, including alpha/beta/rc tags
release = version

Expand Down
2 changes: 0 additions & 2 deletions named_enum/version.py

This file was deleted.

Loading

0 comments on commit 2e764a7

Please sign in to comment.