Skip to content

Commit

Permalink
More cleanup & modernization (#247)
Browse files Browse the repository at this point in the history
* Remove un-needed flake8 config.

* Reorganize .gitignore.

* Update changelog.

* Reorg requirements, add script folder.

* Fix tox.

* Test switch to pyproject.toml.

* Doc dev improvements, add pylint back for vscode, pyenv based devcontainer.
  • Loading branch information
ivanklee86 authored Apr 17, 2023
1 parent 699ca31 commit ec75580
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 92 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,30 @@ RUN apt-get update && apt-get install gnupg2 -y

# Update pip
RUN pip install -U pip

# Install pyenv
USER vscode
WORKDIR /home/vscode

RUN git clone --depth=1 https://github.com/pyenv/pyenv.git .pyenv

ENV PYENV_ROOT="/home/vscode/.pyenv"
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"

RUN pyenv install 3.7 3.8 3.9 3.10 3.11
RUN pyenv local 3.7 3.8 3.9 3.10 3.11
RUN pyenv global ${VARIANT}

# Set up pyenv-virtualenv
RUN git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

# Modify dotfile
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
RUN echo 'export PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
RUN echo 'export PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc

# Back to root
USER root
13 changes: 6 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.formatting.blackPath": "${workspaceFolder}/.venv/bin/black",
"python.defaultInterpreterPath": "/home/vscode/.pyenv/shims/python",
"python.formatting.blackPath": "/home/vscode/.pyenv/shims/black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.flake8Path": "${workspaceFolder}/.venv/bin/flake8",
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy",
"python.linting.pylintPath": "${workspaceFolder}/.venv/bin/pylint",
"python.linting.flake8Path": "/home/vscode/.pyenv/shims/flake8",
"python.linting.mypyPath": "/home/vscode/.pyenv/shims/mypy",
"python.linting.pylintPath": "/home/vscode/.pyenv/shims/pylint",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.venvPath": "${workspaceFolder}/.venv"
"python.testing.pytestEnabled": true
},

// Add the IDs of extensions you want installed when the container is created.
Expand Down
5 changes: 1 addition & 4 deletions .devcontainer/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
set -ex

# Install package
sudo su - vscode bash -c "cd /workspaces/unleash-client-python; python -m venv .venv; source .venv/bin/activate; pip install -U -r requirements.txt; python setup.py install; ./get-spec.sh;"
sudo su - vscode bash -c "cd /workspaces/unleash-client-python; pip install -U -r requirements.txt; python -m build; ./scripts/get-spec.sh;"

# Install pre-config
pip install pre-commit
pre-commit install
pre-commit

# Configure git
git config --global --add --bool push.autoSetupRemote true

# Woohoo!
echo "Hooray, it's done!"
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

9 changes: 3 additions & 6 deletions .github/workflows/release-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ jobs:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install wheel
python setup.py install
make install
- name: Build package
run: |
python setup.py sdist bdist_wheel
make build
- name: Upload package to pypi
run: |
twine upload dist/*
make upload
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
Expand Down
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,22 @@ ENV/
# Rope project settings
.ropeproject

#Custom
# Custom

# - IDEs
.idea
.vscode
assets

# - Linting
.ruff_cache

# - Testing
results*
tests/specification_tests/client-specification

# - Docs
assets
site
test_results
_static
_templates
tests/specification_tests/client-specification
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Next
* (Minor) Switch to ruff for linting and black for formatting.

## v5.6.0
* (Major) Add support for event callbacks.

Expand Down
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ SHELL := /bin/bash
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROJECT_NAME = UnleashClient

.PHONY: sphinx

#-----------------------------------------------------------------------
# Rules of Rules : Grouped rules that _doathing_
#-----------------------------------------------------------------------
Expand All @@ -13,14 +15,16 @@ build: clean build-package upload

build-local: clean build-package

docs: docker-docs-stop sphinx docker-docs

#-----------------------------------------------------------------------
# Install
#-----------------------------------------------------------------------

install:
pip install -U -r requirements.txt && \
python setup.py install && \
./get-spec.sh
pip install . && \
./scripts/get-spec.sh

#-----------------------------------------------------------------------
# Testing & Linting
Expand Down Expand Up @@ -54,7 +58,21 @@ clean:
rm -rf UnleashClient.egg-info;

build-package:
python setup.py sdist bdist_wheel
python -m build

upload:
twine upload dist/*

#-----------------------------------------------------------------------
# Docs
#-----------------------------------------------------------------------
docker-docs-stop:
docker stop unleash-docs | true

sphinx:
cd docs; \
rm -rf _build; \
make html;

docker-docs:
docker run -d --name unleash-docs --rm -v `pwd`/docs/_build/html:/web -p 8080:8080 halverneus/static-file-server:latest
2 changes: 1 addition & 1 deletion UnleashClient/api/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def send_metrics(
data=json.dumps(request_body),
headers={**custom_headers, **APPLICATION_HEADERS},
timeout=REQUEST_TIMEOUT,
**custom_options
**custom_options,
)

if resp.status_code != 202:
Expand Down
2 changes: 1 addition & 1 deletion docs/eventcallbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example code using `blinker <https://github.com/pallets-eco/blinker>`_:

.. code-block:: python
from blinker import ignal
from blinker import signal
from UnleashClient import UnleashClient
from UnleashClient.events import UnleashEvent
Expand Down
44 changes: 39 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools_scm[toml]>=6.2"]

[project]
name = "UnleashClient"
authors = [
{ name = "Ivan Lee", email = "[email protected]" },
]
description = "Python client for the Unleash feature toggle system!"
dynamic = ["version"]
readme = "README.md"
requires-python = ">=3.7"
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Typing :: Typed",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
]

[project.urls]
Homepage = "https://github.com/Unleash/unleash-client-python"
Documentation = "https://docs.getunleash.io/unleash-client-python"
Changelog = "https://github.com/Unleash/unleash-client-python/blob/main/CHANGELOG.md"
Repository = "https://github.com/Unleash/unleash-client-python"
Issues = "https://github.com/Unleash/unleash-client-python/issues"

[tool.isort]
profile = "black"

[tool.mypy]
strict_optional = false
ignore_missing_imports = true
Expand Down Expand Up @@ -31,10 +65,10 @@ fixable = ["I"]
[tool.ruff.pylint]
max-args = 25

[tool.isort]
profile = "black"
[tool.setuptools]
include-package-data = true

[tool.setuptools_scm]
[tool.setuptools.packages]
find = {}

[build-system]
requires = ["setuptools", "wheel", "setuptools_scm>=6.2"]
[tool.setuptools_scm]
38 changes: 23 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
# App packages
importlib_metadata
requests
APScheduler
fcache
importlib_metadata
mmhash3
APScheduler
python-dateutil
requests
semver

# Development packages
# - Testing
black
coveralls
isort
mimesis
mypy
black
ruff
isort
pylint
pytest
pytest-cov
pytest-flake8
pytest-html
pytest-html==4.0.0rc4
pytest-mock
pytest-rerunfailures
pytest-runner
pytest-xdist
responses
ruff
tox

# - Testing ()
blinker

# - Tooling
build
setuptools_scm
twine

# - Docs
enum-tools[sphinx]
m2r2
sphinx
sphinx-rtd-theme
m2r2
tox

# - Typing
types-requests
twine
blinker
enum-tools[sphinx]
File renamed without changes.
43 changes: 0 additions & 43 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ envlist = py37,py38,py39,py310,py311
deps = -rrequirements.txt
allowlist_externals = sh
commands =
sh get-spec.sh
sh ./scripts/get-spec.sh
py.test tests/unit_tests
py.test tests/specification_tests

0 comments on commit ec75580

Please sign in to comment.