chkpkg


Namechkpkg JSON
Version 0.5.2 PyPI version JSON
download
home_pagehttps://github.com/rtmigo/chkpkg_py#readme
SummaryTests Python package sources to see if they build successfully to a PyPi compatible distribution
upload_time2022-10-26 14:31:29
maintainer
docs_urlNone
authorArteom iG
requires_python>=3.6
licenseMIT
keywords package packaging distribution wheel whl testing setup build setuptools twine pypi qa ci
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [chkpkg](https://github.com/rtmigo/chkpkg_py#readme)

Checks a Python package intended to be published on PyPi:

- can we build a `.whl` distribution from it?
- сan we install a package from the newly built `.whl`?
- can we import the installed package into the code?

Thus, we test the correctness of `setup.py` or `setup.cfg`.

`chkpkg` can be used as part of CI pipeline. The check can be run from a `.py`
script, which is as cross-platform as Python itself.

---

`chkpkg` supports Python 3.6+ on Linux, macOS and Windows.

# Install

``` bash
pip3 install chkpkg
```

# Use

``` python3
from chkpkg import Package

with Package() as pkg:
    pkg.run_python_code('import mypackage; mypackage.myfunc()')
    pkg.run_shell_code('mypackage_cli --version')
    
print("Package is OK!")
```

This **test script** creates a distribution from project sources, installs the
package from the distribution into a virtual environment, tries importing and
running the installed package from python and command line.

If any results in an error, an exception is thrown. The absence of exceptions
means that the package is fine.

By default, we assume that the `setup.py` or `setup.cfg` is located in the
current working directory. You can specify a different path using the
argument `Package(project_dir=...)`

# Steps

Without context, the test script would look like this:

``` python3
from chkpkg import Package

pkg = Package()

try:
    # step 1
    pkg.init()
    
    # step 2   
    pkg.run_python_code('import mypackage; mypackage.myfunc()')
    pkg.run_shell_code('mypackage_cli --version')

finally:
    # step 3
    pkg.cleanup()    
```

## Step 1: Build, Verify, Install

``` python3
pkg.init()
```

The `init` method:

- Creates a temporary virtual environment capable of building `.whl` files
    - Creates a distribution as a `.whl` file (`python -m build`)
    - Verifies the package source (`twine check --strict`)
- Creates another temporary virtual environment without preinstalled packages
    - Installs the package from the newly created `.whl` into the clean virtual
      environment

## Step 2: Import, Run

``` python3
pkg.run_python_code('import mypackage')
```

The `run_python_code` method allows you to check that the package is installed
and can be imported without errors.

You can also run some functions from the imported package and check the output.

``` python3
output = pkg.run_python_code('import mypackage; print(mypackage.plus(2, 3))')
assert output == "5"
```

If the package must be installed as a CLI program, this can be tested with
the `run_shell_code`. This function calls `cmd.exe` on Windows and `bash`
on other systems.

``` python3
output = pkg.run_shell_code('mypackage_cli --version')
assert output[0].isdigit()
```

The current working directory will be a random temporary one. If `mypackage_cli`
can be run, then it really is available as a shell command from any directory.

However, such tests are best done on a clean system. If we run the tests on
development machine, it may turn out that we are running a command that was in
the system before the package was installed.

## Step 3: Cleanup

``` python3
pkg.cleanup()
```

The `cleanup` method removes all temporary directories created during building
and testing.

# License

Copyright © 2021 [Arteom iG](https://github.com/rtmigo).
Released under the [MIT License](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rtmigo/chkpkg_py#readme",
    "name": "chkpkg",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "package,packaging,distribution,wheel,whl,testing,setup,build,setuptools,twine,pypi,qa,ci",
    "author": "Arteom iG",
    "author_email": "ortemeo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/55/e1/cb1967c83f65ee387c12dfcbb495804200fe20067c7ae2ab9821d6a48b3c/chkpkg-0.5.2.tar.gz",
    "platform": null,
    "description": "[chkpkg](https://github.com/rtmigo/chkpkg_py#readme)\n\nChecks a Python package intended to be published on PyPi:\n\n- can we build a `.whl` distribution from it?\n- \u0441an we install a package from the newly built `.whl`?\n- can we import the installed package into the code?\n\nThus, we test the correctness of `setup.py` or `setup.cfg`.\n\n`chkpkg` can be used as part of CI pipeline. The check can be run from a `.py`\nscript, which is as cross-platform as Python itself.\n\n---\n\n`chkpkg` supports Python 3.6+ on Linux, macOS and Windows.\n\n# Install\n\n``` bash\npip3 install chkpkg\n```\n\n# Use\n\n``` python3\nfrom chkpkg import Package\n\nwith Package() as pkg:\n    pkg.run_python_code('import mypackage; mypackage.myfunc()')\n    pkg.run_shell_code('mypackage_cli --version')\n    \nprint(\"Package is OK!\")\n```\n\nThis **test script** creates a distribution from project sources, installs the\npackage from the distribution into a virtual environment, tries importing and\nrunning the installed package from python and command line.\n\nIf any results in an error, an exception is thrown. The absence of exceptions\nmeans that the package is fine.\n\nBy default, we assume that the `setup.py` or `setup.cfg` is located in the\ncurrent working directory. You can specify a different path using the\nargument `Package(project_dir=...)`\n\n# Steps\n\nWithout context, the test script would look like this:\n\n``` python3\nfrom chkpkg import Package\n\npkg = Package()\n\ntry:\n    # step 1\n    pkg.init()\n    \n    # step 2   \n    pkg.run_python_code('import mypackage; mypackage.myfunc()')\n    pkg.run_shell_code('mypackage_cli --version')\n\nfinally:\n    # step 3\n    pkg.cleanup()    \n```\n\n## Step 1: Build, Verify, Install\n\n``` python3\npkg.init()\n```\n\nThe `init` method:\n\n- Creates a temporary virtual environment capable of building `.whl` files\n    - Creates a distribution as a `.whl` file (`python -m build`)\n    - Verifies the package source (`twine check --strict`)\n- Creates another temporary virtual environment without preinstalled packages\n    - Installs the package from the newly created `.whl` into the clean virtual\n      environment\n\n## Step 2: Import, Run\n\n``` python3\npkg.run_python_code('import mypackage')\n```\n\nThe `run_python_code` method allows you to check that the package is installed\nand can be imported without errors.\n\nYou can also run some functions from the imported package and check the output.\n\n``` python3\noutput = pkg.run_python_code('import mypackage; print(mypackage.plus(2, 3))')\nassert output == \"5\"\n```\n\nIf the package must be installed as a CLI program, this can be tested with\nthe `run_shell_code`. This function calls `cmd.exe` on Windows and `bash`\non other systems.\n\n``` python3\noutput = pkg.run_shell_code('mypackage_cli --version')\nassert output[0].isdigit()\n```\n\nThe current working directory will be a random temporary one. If `mypackage_cli`\ncan be run, then it really is available as a shell command from any directory.\n\nHowever, such tests are best done on a clean system. If we run the tests on\ndevelopment machine, it may turn out that we are running a command that was in\nthe system before the package was installed.\n\n## Step 3: Cleanup\n\n``` python3\npkg.cleanup()\n```\n\nThe `cleanup` method removes all temporary directories created during building\nand testing.\n\n# License\n\nCopyright \u00a9 2021 [Arteom iG](https://github.com/rtmigo).\nReleased under the [MIT License](LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tests Python package sources to see if they build successfully to a PyPi compatible distribution",
    "version": "0.5.2",
    "project_urls": {
        "Homepage": "https://github.com/rtmigo/chkpkg_py#readme"
    },
    "split_keywords": [
        "package",
        "packaging",
        "distribution",
        "wheel",
        "whl",
        "testing",
        "setup",
        "build",
        "setuptools",
        "twine",
        "pypi",
        "qa",
        "ci"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb97947611a9ffc776e871439814c2e244a680f3399c8237917f3aa1da98ad2d",
                "md5": "71d374c98380b0280cb3a4301858c485",
                "sha256": "022eec53aec374b8423eeb9f303a3cf887c9dab85827600457d211ebc46af5b5"
            },
            "downloads": -1,
            "filename": "chkpkg-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71d374c98380b0280cb3a4301858c485",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 10717,
            "upload_time": "2022-10-26T14:31:27",
            "upload_time_iso_8601": "2022-10-26T14:31:27.134599Z",
            "url": "https://files.pythonhosted.org/packages/eb/97/947611a9ffc776e871439814c2e244a680f3399c8237917f3aa1da98ad2d/chkpkg-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55e1cb1967c83f65ee387c12dfcbb495804200fe20067c7ae2ab9821d6a48b3c",
                "md5": "11a3f6e12d60d4edfe7875851eea8a19",
                "sha256": "73b038752b725d499f378edd5235b6c6d15c039d34e5232bd80663b20d5247bc"
            },
            "downloads": -1,
            "filename": "chkpkg-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "11a3f6e12d60d4edfe7875851eea8a19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 10231,
            "upload_time": "2022-10-26T14:31:29",
            "upload_time_iso_8601": "2022-10-26T14:31:29.609975Z",
            "url": "https://files.pythonhosted.org/packages/55/e1/cb1967c83f65ee387c12dfcbb495804200fe20067c7ae2ab9821d6a48b3c/chkpkg-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-10-26 14:31:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rtmigo",
    "github_project": "chkpkg_py#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "chkpkg"
}
        
Elapsed time: 0.12062s