python packaging with flit: specifying dependencies: nox, flit, pyproject.toml,

282 Views Asked by At

I am using nox to automate various python packaging tasks. I am using flit to build dist package and pyproject.toml is the metadata file. My pyproject.toml looks as follows:

[build-system]
requires = ["flit_core >=3,<4", "ofjustpy-engine"]
build-backend = "flit_core.buildapi"


[tool.flit.metadata]
name = "ofjustpy"
module = "ofjuspty"  # Replace with your actual package name
version = "1.0.0"  # Replace with your desired version number
author = "Kabira K."
author-email = "[email protected]"
description = "Full stack webdev framework in pure Python"

[tool.flit.metadata.dependencies]
python = ">=3.6"
ofjustpy_engine = "*"

[project]
 name = "ofjustpy"
 maintainers = [
 { name="Kabira K", email= "[email protected]"}
]

 dynamic = ["version", "description"]
 readme= "README.md"
 license = { file="LICENSE" }
 dependencies = [
'ofjustpy-engine'
        ]
                
                
[project.urls]
Home = "http://webworks.monallabs.in/ofjustpy/ofjustpy"
Documentation = "https://github.com/monallabs-org/ofjustpy/ofjustpy"
Source = "https://github.com/monallabs-org/ofjustpy/"

[tool.pytest.ini_options]
addopts = [
    "--import-mode=importlib"
]

The nox file for running tests and creating badages looks as follows:

@nox.session(python="3.11")
def badges(session):
    # Install pytest, pytest-cov, flake8 and genbadge
    session.install("pytest", "pytest-cov", "flake8", "flake8-html", "ofjustpy-engine", "genbadge[all]")

    with tempfile.NamedTemporaryFile(delete=False) as fp:
        print("THE FILE PATH NAME = ", fp.name)
        session.run(
            "pipenv",
            "run",
            "pip",
            "freeze",
            external=True,
            stdout=fp,
        )
        
        
    session.env["PIPENV_VERBOSITY"] = "-1"

    
    # Install dependencies from the temporary requirements.txt
    session.install("-r", fp.name)

    # Install your package in editable mode
    session.run("pip", "install", "-e", ".")

    # Run pytest to generate the junit and html reports
    session.run(
        "pytest",
        "--cov",
        "--junitxml=reports/junit/junit.xml",
        "--cov-report=xml:reports/coverage/coverage.xml",
        "--cov-report=html:reports/coverage/coverage.html",
    )

    # Run flake8 to generate the HTML report and statistics
    session.run(
        "flake8",
        "src/addict_tracking_changes",
        "--exit-zero",
        "--format=pylint",
        # "--htmldir=./reports/flake8",
        "--statistics",
        "--output-file=reports/flake8/flake8stats.txt",
    )

    # Generate a badge for tests
    session.run(
        "genbadge", "tests", "-i", "reports/junit/junit.xml", "-o", "badge_tests.svg"
    )

    # Generate a badge for coverage
    session.run(
        "genbadge",
        "coverage",
        "-i",
        "reports/coverage/coverage.xml",
        "-o",
        "badge_coverage.svg",
    )

    # Generate a badge for flake8 based on the statistics text report
    session.run(
        "genbadge",
        "flake8",
        "-i",
        "reports/flake8/flake8stats.txt",
        "-o",
        "badge_flake8.svg",
    )
```.

when i run `nox -rs badges`; it fails with error:

```bash 
Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "/home/kabiraatmonallabs/to_githubcodes/ofjustpy-new/.nox/badges/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/kabiraatmonallabs/to_githubcodes/ofjustpy-new/.nox/badges/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/kabiraatmonallabs/to_githubcodes/ofjustpy-new/.nox/badges/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 181, in prepare_metadata_for_build_editable
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-js3x92v0/overlay/lib/python3.11/site-packages/flit_core/buildapi.py", line 49, in prepare_metadata_for_build_wheel
          metadata = make_metadata(module, ini_info)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-js3x92v0/overlay/lib/python3.11/site-packages/flit_core/common.py", line 425, in make_metadata
          md_dict.update(get_info_from_module(module, ini_info.dynamic_metadata))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-js3x92v0/overlay/lib/python3.11/site-packages/flit_core/common.py", line 222, in get_info_from_module
          docstring, version = get_docstring_and_version_via_import(target)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-js3x92v0/overlay/lib/python3.11/site-packages/flit_core/common.py", line 195, in get_docstring_and_version_via_import
          spec.loader.exec_module(m)
        File "<frozen importlib._bootstrap_external>", line 940, in exec_module
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "/home/kabiraatmonallabs/to_githubcodes/ofjustpy-new/src/ofjustpy/__init__.py", line 2, in <module>
          import ofjustpy_engine as jp
      ModuleNotFoundError: No module named 'ofjustpy_engine'
      [end of output]

I am just not sure where to add the ofjustpy_engine dependency so that it gets picked up when nox invokes flit.

0

There are 0 best solutions below