From 70992b2f6d76f6c92744a3a3cd063f3318906636 Mon Sep 17 00:00:00 2001 From: BJ Dierkes Date: Mon, 20 May 2024 00:32:23 -0400 Subject: [PATCH] Additional modifications to PR #681 --- .github/workflows/pythonpublish.yml | 29 ------------- CHANGELOG.md | 38 +++++++++++++++++ Dockerfile | 5 ++- Makefile | 6 ++- cement/core/foundation.py | 4 +- cement/utils/shell.py | 2 +- docker-compose.yml | 56 +++++++++++++------------ docker/Dockerfile.dev | 2 +- docker/Dockerfile.dev-py310 | 2 +- docker/Dockerfile.dev-py311 | 2 +- docker/Dockerfile.dev-py312 | 2 +- docker/Dockerfile.dev-py38 | 2 +- docker/Dockerfile.dev-py39 | 2 +- docker/bashrc | 3 ++ pdm.lock | 13 +++++- pyproject.toml | 65 ++++++++++++++++------------- tests/utils/test_shell.py | 8 ++-- 17 files changed, 141 insertions(+), 100 deletions(-) delete mode 100644 .github/workflows/pythonpublish.yml create mode 100644 docker/bashrc diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml deleted file mode 100644 index 3452ec1c..00000000 --- a/.github/workflows/pythonpublish.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Upload Python Package - -on: - release: - types: [published] - -permissions: - id-token: write # trusted publishing - contents: read - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish a Python distribution to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f42964..a9814ebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,43 @@ # ChangeLog +## 3.0.11 - DEVELOPMENT (will be released as stable/3.0.12) + +Bugs: + +- ? + + +Features: + +- ? + + +Refactoring: + +- `[dev]` Modernize Packaging (pyproject.toml, PDM) + - [Issue #680](https://github.com/datafolklabs/cement/issues/680) + - [PR #681](https://github.com/datafolklabs/cement/pull/681) +- `[dev]` Implement Ruff for Code Compliance + - [Issue #671](https://github.com/datafolklabs/cement/issues/671) + - [PR #681](https://github.com/datafolklabs/cement/pull/681) +- `[dev]` Remove Python 3.5, 3.6, 3.7 Docker Dev Targets + + +Misc: + +- ? + + +Deprecations: + +- ? + + +Special Recognitions: + +Many thanks to `sigma67` for their contributions in modernizing the packaging system. Cement was started in 2009, and has some lingering technical debt that is now being addressed. Their contribution was a major help in moving off of setuptools and on to PDM and `pyproject.toml`, along with initial implementations of Ruff for a new generation of code compliance. I sincerely appreciate your help! + + ## 3.0.10 - Feb 28, 2024 Bugs: diff --git a/Dockerfile b/Dockerfile index b0e33ff4..9b916644 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,8 @@ ENV PS1="\[\e[0;33m\]|> cement <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " WORKDIR /src COPY . /src ENV PDM_BUILD_SCM_VERSION=0.0.0.dev -RUN pip install . \ - && rm -rf /src +# RUN pip install . \ +# && rm -rf /src +RUN pip install . WORKDIR / ENTRYPOINT ["/usr/local/bin/cement"] diff --git a/Makefile b/Makefile index 618aa274..5b878738 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,11 @@ dev: docker-compose up -d - docker-compose exec cement pip install . + docker-compose exec cement pdm install + docker-compose exec cement-py38 pdm install + docker-compose exec cement-py39 pdm install + docker-compose exec cement-py310 pdm install + docker-compose exec cement-py311 pdm install docker-compose exec cement /bin/bash test: comply diff --git a/cement/core/foundation.py b/cement/core/foundation.py index 406b8fbd..caabf5a5 100644 --- a/cement/core/foundation.py +++ b/cement/core/foundation.py @@ -1065,7 +1065,7 @@ def render(self, data, template=None, out=sys.stdout, handler=None, **kw): """ for res in self.hook.run('pre_render', self, data): - if not type(res) is dict: + if type(res) is not dict: LOG.debug("pre_render hook did not return a dict().") else: data = res @@ -1090,7 +1090,7 @@ def render(self, data, template=None, out=sys.stdout, handler=None, **kw): out_text = oh.render(data, **kw) for res in self.hook.run('post_render', self, out_text): - if not type(res) is str: + if type(res) is not str: LOG.debug('post_render hook did not return a str()') else: out_text = str(res) diff --git a/cement/utils/shell.py b/cement/utils/shell.py index bd5dd747..877629a0 100644 --- a/cement/utils/shell.py +++ b/cement/utils/shell.py @@ -476,7 +476,7 @@ def prompt(self): if self._meta.case_insensitive is True: lower_options = [x.lower() for x in self._meta.options] - if not self.input.lower() in lower_options: + if self.input.lower() not in lower_options: self.input = None continue else: diff --git a/docker-compose.yml b/docker-compose.yml index 524bcb4b..b98208bb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,32 @@ volumes: mailpit-data: services: + redis: + image: redis:latest + hostname: redis + + memcached: + image: memcached:latest + hostname: memcached + + mailpit: + image: axllent/mailpit + container_name: mailpit + restart: always + volumes: + - mailpit-data:/data + - ./docker/mailpit:/certificates + ports: + - 8025:8025 + - 1025:1025 + environment: + MP_MAX_MESSAGES: 5000 + MP_DATA_FILE: /data/mailpit.db + MP_SMTP_AUTH_ACCEPT_ANY: 1 + MP_SMTP_AUTH_ALLOW_INSECURE: 1 + MP_SMTP_TLS_CERT: /certificates/dev-cert.pem + MP_SMTP_TLS_KEY: /certificates/dev-key.pem + cement: &DEFAULTS image: "cement:dev" build: @@ -23,6 +49,10 @@ services: MEMCACHED_HOST: memcached SMTP_HOST: mailpit SMTP_PORT: 1025 + depends_on: + - redis + - memcached + - mailpit cement-py38: <<: *DEFAULTS @@ -51,29 +81,3 @@ services: build: context: . dockerfile: docker/Dockerfile.dev-py311 - - redis: - image: redis:latest - hostname: redis - - memcached: - image: memcached:latest - hostname: memcached - - mailpit: - image: axllent/mailpit - container_name: mailpit - restart: always - volumes: - - mailpit-data:/data - - ./docker/mailpit:/certificates - ports: - - 8025:8025 - - 1025:1025 - environment: - MP_MAX_MESSAGES: 5000 - MP_DATA_FILE: /data/mailpit.db - MP_SMTP_AUTH_ACCEPT_ANY: 1 - MP_SMTP_AUTH_ALLOW_INSECURE: 1 - MP_SMTP_TLS_CERT: /certificates/dev-cert.pem - MP_SMTP_TLS_KEY: /certificates/dev-key.pem diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 789fe393..7b96dd46 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/Dockerfile.dev-py310 b/docker/Dockerfile.dev-py310 index 86cd8189..b6b59c27 100644 --- a/docker/Dockerfile.dev-py310 +++ b/docker/Dockerfile.dev-py310 @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/Dockerfile.dev-py311 b/docker/Dockerfile.dev-py311 index 996e766f..75f2a74e 100644 --- a/docker/Dockerfile.dev-py311 +++ b/docker/Dockerfile.dev-py311 @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/Dockerfile.dev-py312 b/docker/Dockerfile.dev-py312 index 789fe393..7b96dd46 100644 --- a/docker/Dockerfile.dev-py312 +++ b/docker/Dockerfile.dev-py312 @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/Dockerfile.dev-py38 b/docker/Dockerfile.dev-py38 index 584d9fb3..b44a8ea1 100644 --- a/docker/Dockerfile.dev-py38 +++ b/docker/Dockerfile.dev-py38 @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/Dockerfile.dev-py39 b/docker/Dockerfile.dev-py39 index 581d3778..d04438a9 100644 --- a/docker/Dockerfile.dev-py39 +++ b/docker/Dockerfile.dev-py39 @@ -23,6 +23,6 @@ RUN pipx install pdm ENV PATH="${PATH}:/root/.local/bin" COPY . /src COPY docker/vimrc /root/.vimrc -RUN pdm venv create +COPY docker/bashrc /root/.bashrc RUN pdm install CMD ["/bin/bash"] diff --git a/docker/bashrc b/docker/bashrc new file mode 100644 index 00000000..6a1d5478 --- /dev/null +++ b/docker/bashrc @@ -0,0 +1,3 @@ + +export PATH="${PATH}:/root/.local/bin" +alias cement='pdm run cement' diff --git a/pdm.lock b/pdm.lock index 8a7e6f33..2fb23a9a 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "alarm", "argparse", "colorlog", "configparser", "daemon", "dev", "docs", "dummy", "generate", "jinja2", "json", "logging", "memcached", "mustache", "plugin", "print", "redis", "scrub", "smtp", "tabulate", "watchdog", "yaml"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:7ee1b527b606c4f99aa980b75b4591ee99f97bd57e78a773fcdb8c3b36f6fd93" +content_hash = "sha256:b3e19108389b63d5ab60634d76e82d6ef472cc06a5f8a81e98c57d30bf92c2b3" [[package]] name = "alabaster" @@ -451,6 +451,17 @@ files = [ {file = "MarkupSafe-2.1.5.tar.gz", hash = "sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b"}, ] +[[package]] +name = "mock" +version = "5.1.0" +requires_python = ">=3.6" +summary = "Rolling backport of unittest.mock for all Pythons" +groups = ["dev"] +files = [ + {file = "mock-5.1.0-py3-none-any.whl", hash = "sha256:18c694e5ae8a208cdb3d2c20a993ca1a7b0efa258c247a1e565150f477f83744"}, + {file = "mock-5.1.0.tar.gz", hash = "sha256:5e96aad5ccda4718e0a229ed94b2024df75cc2d55575ba5762d31f5767b8767d"}, +] + [[package]] name = "mypy" version = "1.9.0" diff --git a/pyproject.toml b/pyproject.toml index 5e8d299e..8cbd13f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,9 +18,6 @@ dynamic = ["version", "README"] requires-python = ">=3.8" -dependencies = [ -] - [project.optional-dependencies] alarm = [] argparse = [] @@ -44,6 +41,9 @@ tabulate = ["tabulate"] watchdog = ["watchdog"] yaml = ["pyYaml"] +[tool.pdm.scripts] +cement = {call = "cement.cli.main:main"} + [project.scripts] cement = "cement.cli.main:main" @@ -94,10 +94,13 @@ dev = [ "coverage>=4.5.3", "mypy>=1.9.0", "ruff>=0.3.2", + "mock>=5.1.0", ] [tool.ruff] -line-length = 100 +target-version = "py38" +line-length = 99 +indent-width = 4 exclude = [ ".git", "cement/cli/templates", @@ -105,25 +108,42 @@ exclude = [ ] [tool.ruff.lint] -extend-select = [ - "F", # pyflakes - "E", "W", # pycodestyle - # "N", # pep8-naming - enable later, some variables are not lowercase -] -ignore = [ - "E402", - "E713", - "E721", - "E714", - "F841", - "F507" -] +preview = true +extend-select = ["E", "F", "W"] +ignore = [] +fixable = ["ALL"] +unfixable = [] + +# ignore = [ +# "E402", +# "E713", +# "E721", +# "E714", +# "F841", +# "F507" +# ] # TBD # [tool.ruff.format] # quote-style = "single" +# [[tool.mypy.overrides]] +# module = "cement.*" +# ignore_missing_imports = true + [tool.mypy] +python_version = "3.8" +disallow_untyped_calls = true +disallow_untyped_defs = true +disallow_any_unimported = false +disallow_incomplete_defs = true +disallow_untyped_decorators = true +no_implicit_optional = true +strict_optional = true +check_untyped_defs = true +warn_return_any = true +warn_unused_ignores = true +show_error_codes = true files = [ "cement/", # "tests/" @@ -134,14 +154,3 @@ exclude = """(?x)( ^.git/ | ^tests )""" - -# https://mypy.readthedocs.io/en/stable/config_file.html#untyped-definitions-and-calls -disallow_untyped_calls = true -disallow_untyped_defs = true -disallow_incomplete_defs = true -check_untyped_defs = true -disallow_untyped_decorators = true - -# https://mypy.readthedocs.io/en/stable/config_file.html#none-and-optional-handling -no_implicit_optional = true -strict_optional = true diff --git a/tests/utils/test_shell.py b/tests/utils/test_shell.py index d612ed50..b0222e21 100644 --- a/tests/utils/test_shell.py +++ b/tests/utils/test_shell.py @@ -15,7 +15,7 @@ def add(a, b): def test_cmd(): - out, err, ret = shell.cmd('echo KAPLA!') + out, err, ret = shell.cmd('echo KAPLA!') # noqa: F841 assert ret == 0 assert out == b'KAPLA!\n' @@ -24,13 +24,13 @@ def test_cmd(): def test_exec_cmd(): - out, err, ret = shell.exec_cmd(['echo', 'KAPLA!']) + out, err, ret = shell.exec_cmd(['echo', 'KAPLA!']) # noqa: F841 assert ret == 0 assert out == b'KAPLA!\n' def test_exec_cmd_shell_true(): - out, err, ret = shell.exec_cmd(['echo KAPLA!'], shell=True) + out, err, ret = shell.exec_cmd(['echo KAPLA!'], shell=True) # noqa: F841 assert ret == 0 assert out == b'KAPLA!\n' @@ -46,7 +46,7 @@ def test_exec_cmd2_shell_true(): def test_exec_cmd_bad_command(): - out, err, ret = shell.exec_cmd(['false']) + out, err, ret = shell.exec_cmd(['false']) # noqa: F841 assert ret == 1