RandomCoder
RandomCoder

Reputation: 7024

Can't make CircleCI work along Python project set through pyproject.toml

I have setup a Python Project with dependencies listed in a pyproject.toml file as explained in PyPI packaging tutorial. Here is pyproject.toml file:

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "easypeasy"
version = "0.0.0"

readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.9"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]
dependencies = [
  'pytest',
  'numpy',
]

[project.urls]
"Homepage" = "https://github.com/RandomCraftr/easypeasy"
"Bug Tracker" = "https://github.com/RandomCraftr/easypeasy/issues"

Whatever configuration file I use, CircleCI desperately look for petry section in my pyproject.toml file or look for requirement.txt, which is defintely uselesss given pyproject.toml file.

What should be config.yaml configuration file for this project to enable CircleCI to work ?

Upvotes: 0

Views: 355

Answers (2)

Sequestered1776Vexer
Sequestered1776Vexer

Reputation: 508

So my pyproject.toml looks like this:

[build-system]
requires = ['setuptools', 'wheel']
build-backend = "setuptools.build_meta"

[project]
name='codeallybasic'
dynamic = ["version"]
description = 'Humberto`s Basic Common Code'
readme = "README.md"
license = {text = 'GNU AFFERO GENERAL PUBLIC LICENSE'}
authors = [{name = 'Humberto A. Sanchez II', email = '[email protected]'}]
maintainers = [{name = 'Humberto A. Sanchez II', email = '[email protected]'}]
keywords = ['pyut', 'python',]

dependencies = [
  'Deprecated==1.2.14',
]

[project.optional-dependencies]
test = [
    "html-testRunner~=1.2.1",
    "mypy== 1.12.1",
    "mypy-extensions==1.0.0",
    "typing_extensions==4.10.0",
    "types-Deprecated==1.2.9.20240311",
    "buildlackey==1.7.0",
]

deploy = [
    "wheel==0.45.1",
    "setuptools==75.7.0",
    "twine==6.0.1",
    "build==1.2.2.post1",
]

[project.urls]
Repository = 'https://github.com/hasii2011/code-ally-basic'


[tool.setuptools.packages.find]
where = ['src']

[tool.setuptools.package-data]
codeallybasic = ['py.typed']

[tool.setuptools.dynamic]
version = {attr = 'codeallybasic.__version__'}

Then the config.yml looks like this:

version: '2.1'

orbs:
  python: circleci/[email protected]

workflows:
  main:
    jobs:
      - build:
          filters:
            tags:
              only: /.*/

jobs:
  build:
    docker:
      - image: cimg/python:3.12
    executor: python/default
    steps:
      - checkout
      - run:
          name: Install dependencies from pyproject.toml
          command: |
            pip install .
            pip install .[test]
      - run:
            name: run tests
            command: | 
              unittests

The unittest command is a custom python script of mine that is a wrapper around the Python test loader; Insert your own mechanism

Upvotes: 0

RandomCoder
RandomCoder

Reputation: 7024

After digging documentation, it appears none "orbs" (some kind of pre-defined actions you can import) provided by circleci does the trick off the shelf for pyproject.toml configured project. Hence, I had to start from a blank config.yml to make it happen. Moreover, I had to test both Win and Linux platform. Which leads me to the following.

  • If you want to test your Python package with circleai
  • If your Python package relies exclusively on pyproject.toml definition
  • If you selected pytest testing framework

Then, the following config.yml file will allow you to make use of circleci CI solution for your package.

version: 2.1
jobs:
  buildandtest_linux_latest:
    machine:
      image: ubuntu-2004:current
    resource_class: medium
    steps:
      - checkout
      - run: python3 -m pip install .
      - run: python3 -m pytest
  buildandtest_win_latest:
    machine:
      image: windows-server-2022-gui:current
    resource_class: windows.medium
    steps:
      - checkout
      - run: python -m pip install .
      - run: python -m pytest
workflows:
  main:
    jobs:
      - buildandtest_linux_latest
      - buildandtest_win_latest

Upvotes: 0

Related Questions