pigar


Namepigar JSON
Version 2.1.4 PyPI version JSON
download
home_page
SummaryA tool to generate requirements.txt for Python project.
upload_time2024-03-09 07:37:24
maintainer
docs_urlNone
author
requires_python>=3.8
licenseBSD 3-Clause License
keywords requirements.txt automation tool module-search
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## pigar

[![](https://img.shields.io/github/actions/workflow/status/damnever/pigar/ci.yml?branch=main&style=flat-square)](https://github.com/damnever/pigar/actions) [![](https://img.shields.io/pypi/v/pigar.svg?style=flat-square)](https://pypi.org/project/pigar)


- Generating requirements.txt for Python project.
   - Handling the difference between different Python versions.
   - Jupyter notebook (`*.ipynb`) support.
   - Including the import statements/magic from ``exec``/``eval``/``importlib``, doctest of docstring, etc.
- Searching ditributions(packages) by the top level import/module names.
- Checking the latest versions of requirements.

**NOTE**: [Pipenv or other tools](https://packaging.python.org/tutorials/managing-dependencies/#managing-dependencies) is recommended for improving your development flow.


### Installation

`pigar` can run on Python 3.7+.

To install it with `pip`, use:
```
[sudo] pip install pigar
```
To install it with ``conda``, use:
```
conda install -c conda-forge pigar
```
To get the newest code from GitHub:
```
pip install git+https://github.com/damnever/pigar.git@[main or other branch] --upgrade
```

### Usage

- `pigar` can consider most kinds of complicated situations(see [FAQ](#faq)). For example, `pigar v1` has [py2_requirements.txt](https://github.com/damnever/pigar/blob/c68d372fba4a6f98228ec3cf8e273f59d68d0e3c/py2_requirements.txt) and [py3_requirements.txt](https://github.com/damnever/pigar/blob/c68d372fba4a6f98228ec3cf8e273f59d68d0e3c/py3_requirements.txt) for different Python versions.

    ```
    # Generate requirements.txt for current directory.
    $ pigar generate

    # Generating requirements.txt for given directory in given file.
    $ pigar gen -f ../dev-requirements.txt ../
    ```

    `pigar gen --with-referenced-comments` can list all files which referenced the package/distribution(the line numbers for Jupyter notebook may be a bit confusing), for example:
    ```
    # project/foo.py: 2,3
    # project/bar/baz.py: 2,7,8,9
    foobar == 3.3.3
    ```

    If the requirements.txt is overwritten, ``pigar`` will show the difference between the old and the new, use `--dont-show-differences` to disable it.

    **NOTE**, `pigar` will search the packages/distributions in local environment first, then it will do further analysis and search missing packages/distributions on PyPI.

    See also: [EXPERIMENTAL FEATURES](https://github.com/damnever/pigar#experimental-features).

- If you do not know the import name that belongs to a specific distribution (more generally, does `Import Error: xxx` drive you crazy?), such as `bs4` which may come from `beautifulsoup4` or `MySQLdb` which could come from `mysql-python`, try searching for it:

    ```
    $ pigar search bs4 MySQLdb
    ```

- Checking for the latest version:

    ```
    # Specify a requirements file.
    $ pigar check -f ./requirements.txt

    # Or, you can let pigar searching all *requirements.txt in the current directory
    # level by itself.
    $ pigar check
    ```

- More:

  TIP: `pigar` accepts a prefix for a command, such as `pigar gen`, `pigar c`.
   ```
   pigar --help
   ```


### EXPERIMENTAL FEATURES

- `requirement-annotations`

    Some packages may require optional packages/distributions to be installed depending on your usage. To make `pigar` a little bit more useful, use `pigar generate --enable-feature requirement-annotations` in conjunction with comments following the format below:
    ```python
    import foo # pigar: required-imports=import_name_bar,import_name_baz
    import foo # pigar: required-packages=package-name-bar,package-name-baz # Extra comments are allowed.
    foo(features=['bar', 'baz']) # pigar: required-distributions=package-name-bar,package-name-baz
    ```
    If you find the comment intrusive, you can extract those comments into a separate Python file and delete it as needed, for example, 'pigar_annotations.py'.


### FAQ

<details>
  <summary>
  Is `pigar` a dependency management tool?
  </summary>

**No.** I've thought about this many times, but there is too much dirty work to be done to make `pigar`'s way reliable.

I like the way `pigar` does the job, but sadly, `pigar` does a bad job of managing dependencies, `pigar` is more like a tool to assist an old project to migrate to a new development workflow.
</details>

<details>
  <summary>
  (1) Why does `pigar` show multiple packages/distributions for the same import name?

  (2) Why does `pigar` generate different packages/distributions for the same import name in different environment?
  </summary>

`pigar` can not handle those situations gracefully, you may need to remove the duplicate packages in requirements.txt manually, or select one of them when `pigar` asks you.
Install the required packages/distributions(remove others) in local environment should fix it as well.

Related issues: [#32](https://github.com/damnever/pigar/issues/32), [#68](https://github.com/damnever/pigar/issues/68), [#75](https://github.com/damnever/pigar/issues/75#issuecomment-605639825).
</details>

<details>
  <summary>
  Why can't `pigar` find the packages/distributions that have not been explicit import?
  </summary>

Some frameworks may use some magic to import the modules for users automatically, and `pigar` can not handle it, you may need to fix it manually or use the [EXPERIMENTAL FEATURES](https://github.com/damnever/pigar#experimental-features).

Related issues: [#33](https://github.com/damnever/pigar/issues/33), [#103](https://github.com/damnever/pigar/issues/103)
</details>


### More

`pigar` does not use regular expressions in such a violent way. Instead, it uses AST, which is a better method for extracting imported names from arguments of `exec`/`eval`/`importlib`, doctest of docstring, etc. However, `pigar` can not solve all the tricky problems, see [FAQ](https://github.com/damnever/pigar#faq).

Also, `pigar` can detect the difference between different Python versions. For example, you can find `concurrent.futures` from the Python 3.2 standard library, but you will need install `futures` in earlier versions of Python to get `concurrent.futures`, this is not a hardcode.

If you have any issues or suggestions, [please submit an issue on GitHub](https://github.com/damnever/pigar/issues). [**All contributions are appreciated!**](https://github.com/damnever/pigar/graphs/contributors)


### LICENSE

[The BSD 3-Clause License](https://github.com/damnever/pigar/blob/master/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pigar",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "requirements.txt,automation,tool,module-search",
    "author": "",
    "author_email": "damnever <the.xcdong@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/34/e7/e9f40fe0b2cfb5a8cc9ef0a7bc56dfb9c53f02001b73ce4a46337ec51318/pigar-2.1.4.tar.gz",
    "platform": null,
    "description": "## pigar\n\n[![](https://img.shields.io/github/actions/workflow/status/damnever/pigar/ci.yml?branch=main&style=flat-square)](https://github.com/damnever/pigar/actions) [![](https://img.shields.io/pypi/v/pigar.svg?style=flat-square)](https://pypi.org/project/pigar)\n\n\n- Generating requirements.txt for Python project.\n   - Handling the difference between different Python versions.\n   - Jupyter notebook (`*.ipynb`) support.\n   - Including the import statements/magic from ``exec``/``eval``/``importlib``, doctest of docstring, etc.\n- Searching ditributions(packages) by the top level import/module names.\n- Checking the latest versions of requirements.\n\n**NOTE**: [Pipenv or other tools](https://packaging.python.org/tutorials/managing-dependencies/#managing-dependencies) is recommended for improving your development flow.\n\n\n### Installation\n\n`pigar` can run on Python 3.7+.\n\nTo install it with `pip`, use:\n```\n[sudo] pip install pigar\n```\nTo install it with ``conda``, use:\n```\nconda install -c conda-forge pigar\n```\nTo get the newest code from GitHub:\n```\npip install git+https://github.com/damnever/pigar.git@[main or other branch] --upgrade\n```\n\n### Usage\n\n- `pigar` can consider most kinds of complicated situations(see [FAQ](#faq)). For example, `pigar v1` has [py2_requirements.txt](https://github.com/damnever/pigar/blob/c68d372fba4a6f98228ec3cf8e273f59d68d0e3c/py2_requirements.txt) and [py3_requirements.txt](https://github.com/damnever/pigar/blob/c68d372fba4a6f98228ec3cf8e273f59d68d0e3c/py3_requirements.txt) for different Python versions.\n\n    ```\n    # Generate requirements.txt for current directory.\n    $ pigar generate\n\n    # Generating requirements.txt for given directory in given file.\n    $ pigar gen -f ../dev-requirements.txt ../\n    ```\n\n    `pigar gen --with-referenced-comments` can list all files which referenced the package/distribution(the line numbers for Jupyter notebook may be a bit confusing), for example:\n    ```\n    # project/foo.py: 2,3\n    # project/bar/baz.py: 2,7,8,9\n    foobar == 3.3.3\n    ```\n\n    If the requirements.txt is overwritten, ``pigar`` will show the difference between the old and the new, use `--dont-show-differences` to disable it.\n\n    **NOTE**, `pigar` will search the packages/distributions in local environment first, then it will do further analysis and search missing packages/distributions on PyPI.\n\n    See also: [EXPERIMENTAL FEATURES](https://github.com/damnever/pigar#experimental-features).\n\n- If you do not know the import name that belongs to a specific distribution (more generally, does `Import Error: xxx` drive you crazy?), such as `bs4` which may come from `beautifulsoup4` or `MySQLdb` which could come from `mysql-python`, try searching for it:\n\n    ```\n    $ pigar search bs4 MySQLdb\n    ```\n\n- Checking for the latest version:\n\n    ```\n    # Specify a requirements file.\n    $ pigar check -f ./requirements.txt\n\n    # Or, you can let pigar searching all *requirements.txt in the current directory\n    # level by itself.\n    $ pigar check\n    ```\n\n- More:\n\n  TIP: `pigar` accepts a prefix for a command, such as `pigar gen`, `pigar c`.\n   ```\n   pigar --help\n   ```\n\n\n### EXPERIMENTAL FEATURES\n\n- `requirement-annotations`\n\n    Some packages may require optional packages/distributions to be installed depending on your usage. To make `pigar` a little bit more useful, use `pigar generate --enable-feature requirement-annotations` in conjunction with comments following the format below:\n    ```python\n    import foo # pigar: required-imports=import_name_bar,import_name_baz\n    import foo # pigar: required-packages=package-name-bar,package-name-baz # Extra comments are allowed.\n    foo(features=['bar', 'baz']) # pigar: required-distributions=package-name-bar,package-name-baz\n    ```\n    If you find the comment intrusive, you can extract those comments into a separate Python file and delete it as needed, for example, 'pigar_annotations.py'.\n\n\n### FAQ\n\n<details>\n  <summary>\n  Is `pigar` a dependency management tool?\n  </summary>\n\n**No.** I've thought about this many times, but there is too much dirty work to be done to make `pigar`'s way reliable.\n\nI like the way `pigar` does the job, but sadly, `pigar` does a bad job of managing dependencies, `pigar` is more like a tool to assist an old project to migrate to a new development workflow.\n</details>\n\n<details>\n  <summary>\n  (1) Why does `pigar` show multiple packages/distributions for the same import name?\n\n  (2) Why does `pigar` generate different packages/distributions for the same import name in different environment?\n  </summary>\n\n`pigar` can not handle those situations gracefully, you may need to remove the duplicate packages in requirements.txt manually, or select one of them when `pigar` asks you.\nInstall the required packages/distributions(remove others) in local environment should fix it as well.\n\nRelated issues: [#32](https://github.com/damnever/pigar/issues/32), [#68](https://github.com/damnever/pigar/issues/68), [#75](https://github.com/damnever/pigar/issues/75#issuecomment-605639825).\n</details>\n\n<details>\n  <summary>\n  Why can't `pigar` find the packages/distributions that have not been explicit import?\n  </summary>\n\nSome frameworks may use some magic to import the modules for users automatically, and `pigar` can not handle it, you may need to fix it manually or use the [EXPERIMENTAL FEATURES](https://github.com/damnever/pigar#experimental-features).\n\nRelated issues: [#33](https://github.com/damnever/pigar/issues/33), [#103](https://github.com/damnever/pigar/issues/103)\n</details>\n\n\n### More\n\n`pigar` does not use regular expressions in such a violent way. Instead, it uses AST, which is a better method for extracting imported names from arguments of `exec`/`eval`/`importlib`, doctest of docstring, etc. However, `pigar` can not solve all the tricky problems, see [FAQ](https://github.com/damnever/pigar#faq).\n\nAlso, `pigar` can detect the difference between different Python versions. For example, you can find `concurrent.futures` from the Python 3.2 standard library, but you will need install `futures` in earlier versions of Python to get `concurrent.futures`, this is not a hardcode.\n\nIf you have any issues or suggestions, [please submit an issue on GitHub](https://github.com/damnever/pigar/issues). [**All contributions are appreciated!**](https://github.com/damnever/pigar/graphs/contributors)\n\n\n### LICENSE\n\n[The BSD 3-Clause License](https://github.com/damnever/pigar/blob/master/LICENSE)\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "A tool to generate requirements.txt for Python project.",
    "version": "2.1.4",
    "project_urls": {
        "Documentation": "https://github.com/damnever/pigar",
        "Source": "https://github.com/damnever/pigar"
    },
    "split_keywords": [
        "requirements.txt",
        "automation",
        "tool",
        "module-search"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1e2b5353d94f7e4f24f279169453c06a66ca1a3c8d5ddd3daa65a628087a8747",
                "md5": "edf2a6cdbc2325a00bbcb1c03a758c14",
                "sha256": "c83800e55bfe9dfa0546ccf893ae06b9faed7092f3052b45684177d73fa9d28e"
            },
            "downloads": -1,
            "filename": "pigar-2.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "edf2a6cdbc2325a00bbcb1c03a758c14",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 26338386,
            "upload_time": "2024-03-09T07:37:20",
            "upload_time_iso_8601": "2024-03-09T07:37:20.826944Z",
            "url": "https://files.pythonhosted.org/packages/1e/2b/5353d94f7e4f24f279169453c06a66ca1a3c8d5ddd3daa65a628087a8747/pigar-2.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "34e7e9f40fe0b2cfb5a8cc9ef0a7bc56dfb9c53f02001b73ce4a46337ec51318",
                "md5": "18a28420fc2cbc671f1e19f596022630",
                "sha256": "6306d0b4175e4ec9d9209b4156711b46ef479ef2b2ce0423991f0966166d45de"
            },
            "downloads": -1,
            "filename": "pigar-2.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "18a28420fc2cbc671f1e19f596022630",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26054285,
            "upload_time": "2024-03-09T07:37:24",
            "upload_time_iso_8601": "2024-03-09T07:37:24.471472Z",
            "url": "https://files.pythonhosted.org/packages/34/e7/e9f40fe0b2cfb5a8cc9ef0a7bc56dfb9c53f02001b73ce4a46337ec51318/pigar-2.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-09 07:37:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "damnever",
    "github_project": "pigar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pigar"
}
        
Elapsed time: 0.19596s