Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ Create a command line entry point `pipenv-setup`, and add `pipenv-setup` as a `d
package in `Pipfile`:

```bash
pipenv install --dev pipenv-setup
pipenv install --dev pipenv-setup black
```

> Note: you can use `autopep8` rather than black if you wish to.

## Features

### Beautiful pipenv flavored help

`$ pipenv-setup`

![help](https://raw.githubusercontent.com/Madoshakalaka/pipenv-setup/master/readme_assets/help.PNG)
![help](https://raw.githubusercontent.com/Madoshakalaka/pipenv-setup/master/readme_assets/help.PNG)

### Sync to `setup.py`

- supports assorted package configuration. You can have a pipfile as ugly as you want:
- supports assorted package configuration. You can have a pipfile as ugly as you want:

```Pipfile
[package]
Expand Down Expand Up @@ -75,7 +77,7 @@ pipenv install --dev pipenv-setup
)
```

- provide `--dev` flag to sync development packages with `extras_require`:
- provide `--dev` flag to sync development packages with `extras_require`:

```bash
$ pipenv-setup sync --dev
Expand All @@ -92,10 +94,10 @@ pipenv install --dev pipenv-setup
)
```

- produce beautiful [Blackened](https://github.com/psf/black) `setup.py` file
- produce beautiful [Blackened](https://github.com/psf/black) `setup.py` file

- [Template](https://github.com/pypa/sampleproject/blob/master/setup.py) generation with
filled dependencies in the absence of a setup file.
- [Template](https://github.com/pypa/sampleproject/blob/master/setup.py) generation with
filled dependencies in the absence of a setup file.

```bash
$ pipenv-setup sync
Expand Down Expand Up @@ -126,13 +128,13 @@ setup.py was successfully updated

run `$ pipenv-setup check`

- checks four items
- local package in default pipfile packages
- Package version requirements in `install_requires` in setup.py that potentially violates Pipfile
- Package version requirements in `dependency_links` in setup.py that differs from Pipfile
- Default package in pipfile missing in `install_requires` or `dependency_links` in setup.py
- exits with non-zero code when conflict found (can be used in travis-ci)
- here is a somewhat extreme example:
- checks four items
- local package in default pipfile packages
- Package version requirements in `install_requires` in setup.py that potentially violates Pipfile
- Package version requirements in `dependency_links` in setup.py that differs from Pipfile
- Default package in pipfile missing in `install_requires` or `dependency_links` in setup.py
- exits with non-zero code when conflict found (can be used in travis-ci)
- here is a somewhat extreme example:

```bash
$ pipenv-setup check
Expand All @@ -145,7 +147,7 @@ run `$ pipenv-setup check`
(exits with 1)
```

- provide `--ignore-local` flag to allow local packages in pipfile
- provide `--ignore-local` flag to allow local packages in pipfile

```bash
$ pipenv-setup check
Expand All @@ -160,13 +162,13 @@ run `$ pipenv-setup check`
(exits with 0)
```

- provide `--strict` flag to only pass identical version requirements
- provide `--strict` flag to only pass identical version requirements

By default `pipenv-setup check` passes when the version `setup.py` specifies is
"compatible" with `Pipfile`, i.e. is a subset of it. For example, a Pipfile
specifying `django~=1.1` with `setup.py` requiring `django==1.2` is such a case.
specifying `django~=1.1` with `setup.py` requiring `django==1.2` is such a case.

Provide `--strict` to allow only identical requirements; *i.e.* for `Pipfile`'s
Provide `--strict` to allow only identical requirements; _i.e._ for `Pipfile`'s
`django~=1.1`, `setup.py` must require `django>=1.1,<2.0`

Example output:
Expand All @@ -180,17 +182,16 @@ run `$ pipenv-setup check`
(exits with 1)
```

- provide `--lockfile` flag to check `setup.py` against `Pipfile.lock` instead of `Pipfile`
- provide `--lockfile` flag to check `setup.py` against `Pipfile.lock` instead of `Pipfile`

By default, `pipenv-setup check` compares the dependencies from `setup.py` against
the dependencies listed in `Pipfile`. This works well for most cases, but there
the dependencies listed in `Pipfile`. This works well for most cases, but there
are some exceptions that break this strategy, including (but not necessarily limited to):

* VCS dependencies with a mutable `ref` (e.g. - git branch name instead of a tag or commit sha)
* Because these resolve to an immutable pointer (e.g. - commit sha) in `setup.py`, the
dependency will no longer match between `setup.py` and `Pipfile`. However, `Pipfile.lock`
will contain the same resolved pointer as `setup.py`.

- VCS dependencies with a mutable `ref` (e.g. - git branch name instead of a tag or commit sha)
- Because these resolve to an immutable pointer (e.g. - commit sha) in `setup.py`, the
dependency will no longer match between `setup.py` and `Pipfile`. However, `Pipfile.lock`
will contain the same resolved pointer as `setup.py`.

## Contributing

Expand Down
13 changes: 8 additions & 5 deletions pipenv_setup/setup_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,21 @@ def format_file(file): # type: (Path) -> None
try:
# noinspection PyPackageRequirements
import black

else:
with Popen(
[sys.executable, "-m", "black", str(file)], stdout=PIPE, stderr=PIPE
) as p:
p.communicate()

except ImportError:
# use autopep8
import autopep8

code = autopep8.fix_code(file.read_text())
file.write_text(code)
try:
import autopep8
else:
code = autopep8.fix_code(file.read_text())
file.write_text(code)
except ImportError:
raise RuntimeError("Either black or autopep8 must be installed.")
Comment on lines +150 to +164
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else before except block is a syntax error; I'd recommend the following:

    except ImportError:
        # use autopep8
        try:
            # third party
            import autopep8
        except ImportError:
            raise RuntimeError("Either black or autopep8 must be installed.")
        else:
            code = autopep8.fix_code(file.read_text())
            file.write_text(code)
    else:
        with Popen(
            [sys.executable, "-m", "black", str(file)], stdout=PIPE, stderr=PIPE
        ) as p:
            p.communicate()



def insert_at_lineno_col_offset(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@
"pytest-xdist~=1.29",
"tox~=3.14",
"autopep8~=1.4",
"black~=20.8b1; python_version >= '3.6'",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that an update to the latest version would not be a problem!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black formats differently based on its version, so black should probably be pinned in the projects using this library, not here. If it must be here, then probably having it be any version makes more sense?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Madoshakalaka thoughts? This issue (#34) is causing problems for us.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grizz I've moved the requirement to the dev requirements in this PR, so it won't attempt to install black at all when you use it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also running into this issue. Wouldn't upgrading the dev black dependency require reformatting this code base (though I suppose a follow-up PR would be appropriate for that)?

Aside from that, I def like this solution, FWIW.

]
},
install_requires=[
"pipfile~=0.0",
"black==19.10b0; python_version >= '3.6'",
"colorama~=0.4",
"packaging~=20.0",
"requirementslib~=1.5",
Expand Down