Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior (or misunderstanding) of nitpick quickstart steps #138

Closed
tolusonaike opened this issue Feb 17, 2020 · 10 comments
Closed
Labels
bug Something isn't working released Feature/fix is released

Comments

@tolusonaike
Copy link

tolusonaike commented Feb 17, 2020

Not sure i misunderstood the out-of-the-box behavior of nitpick or there is a bug. I except that nitpick should report missing files when ran inside an empty project folder, and the default style file should be downloaded

Expected Behavior

In a folder, with poetry, pyproject.toml, and venv setup, install nitpick and run flake8:

  • Default style file is downloaded into folder (nitpick-style.toml)
  • "Missing" files are reported by flake8 command (e.g missing toml files, setup.cfg)

Current Behavior

In an empty folder, while running in a venv, install nitpick and run flake8:

  • nothing happens. You get another command prompt

Possible Solution

Not sure if this is the correct behavior or my misinterpretation of nitpick's functionality/docs

Steps to Reproduce

  • mkdir test && cd test
  • poetry init
  • poetry add nitpick
  • poetry shell
  • flake8

Your Environment

  • nitpick version used:0.21.3

  • Python version: 3.7

  • Operating System and version: macos

  • Run the following commands and paste the output:
    Python 3.7.3
    attrs==19.3.0
    certifi==2019.11.28
    chardet==3.0.4
    Click==7.0
    dictdiffer==0.8.1
    entrypoints==0.3
    flake8==3.7.9
    idna==2.8
    jmespath==0.9.4
    marshmallow==3.4.0
    marshmallow-polyfield==5.8
    mccabe==0.6.1
    nitpick==0.21.3
    pycodestyle==2.5.0
    pyflakes==2.1.1
    python-slugify==4.0.0
    requests==2.22.0
    ruamel.yaml==0.16.10
    ruamel.yaml.clib==0.2.0
    sortedcontainers==2.1.0
    text-unidecode==1.3
    toml==0.10.0
    urllib3==1.25.8
    #~/.asdf/installs/python/3.7.3/bin/python3.7

-- coding: utf-8 --

import re
import sys

from flake8.main.cli import main

if name == 'main':
sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
sys.exit(main())

@tolusonaike tolusonaike added the bug Something isn't working label Feb 17, 2020
@tolusonaike
Copy link
Author

After some trial and error and following the auto-detection docs, here where the results i got after running the flake8 command

  • added a setup.cfg file (no difference)
  • added a test.py file (NIP102 No Python file was found under the root dir)
  • added a setup.py file (this worked! started getting missing errors)
  • added a app.py file (this worked! started getting missing errors)

@andreoliwa
Copy link
Owner

Hi @tolusonaike.

Indeed, the documentation doesn't say anything about an empty project.
On an empty project, Nitpick will actually report no errors, as you found out.

Turns out that flake8 needs Python files to run; so Nitpick also needs at least one .py.

I will add this information to the quick start.

Thanks for pointing it.

@tolusonaike
Copy link
Author

tolusonaike commented Feb 20, 2020

Not only that, currently, it only recognizes setup.py , app.py, and autoapp.py . Other py files throw a NIP102: No Python file was found under the root dir

@joegnis
Copy link

joegnis commented Mar 19, 2020

I am facing similar issue. In the beginning, I was using this wonderful tool as usual, but out of sudden, flake8 started to give me nothing about nitpick but only linting error. I made sure that nitpick didn't run by deliberately adding a non-existing style file to [tool.nitpick] and still getting no complaints. After touch setup.py, I could magically get back output from nitpick.

Weird thing is that when I tried on my another project which uses setup.py, I can get complaints even after removing setup.py. Both projects have same structure, which has its all source files in package_name and tests directory, and has no Python source files in root directory.

@andreoliwa
Copy link
Owner

Hi @joegnis, thanks for the report.

Both projects have same structure, which has its all source files in package_name and tests directory, and has no Python source files in root directory.

Could you run tree for both projects and post the output here?
So I can try to reproduce the problem you're having.

Example output for the problem reported by @tolusonaike:

$ tree
.
├── poetry.lock
├── pyproject.toml
└── test.py

@joegnis
Copy link

joegnis commented Mar 25, 2020

Unfortunately, I can't reproduce the issue now. Everything looks good even after I check out to the commit on that day (Mar. 19). It might be related to the Python environment that time. Anyway, I am posting my project structure for any future reference.

➜ tree . -L 3
.
├── README.md
├── poetry.lock
├── my_package
│   ├── __init__.py
│   ├── __main__.py
│   ├── source1.py
│   └── source2.py
├── pyproject.toml
├── setup.cfg
└── tox.ini

andreoliwa pushed a commit that referenced this issue Mar 26, 2020
# [0.22.0](v0.21.4...v0.22.0) (2020-03-26)

### Bug Fixes

* consider any Python file (thanks [@tolusonaike](https://github.com/tolusonaike)) ([55c0965](55c0965)), closes [#138](#138)
* remove setup.py (thanks [@sobolevn](https://github.com/sobolevn) and [@bibz](https://github.com/bibz)) ([5d03744](5d03744))

### Features

* add flag for offline mode ([#129](#129)) ([3650575](3650575))
@andreoliwa
Copy link
Owner

🎉 This issue has been resolved in version 0.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@andreoliwa andreoliwa added the released Feature/fix is released label Mar 26, 2020
@Phil-Barber
Copy link

Phil-Barber commented Apr 30, 2020

Hi - this seemed like the most appropriate place to ask since I'm sure it's just a configuration but I'm also unclear on the quickstart.
The problem I think is that my repository is structured like so:

.
│─ Dockerfile
│─ pyproject.toml
│─ poetry.lock
│─ nitpick-style.toml
│─ project
    └── session # my actual python package
               └ app.py
                 |─ more .py files

flake8 is running fine but poetry run nitpick gives:

[FileNotFoundError]
[Errno 2] No such file or directory

If I create ./app.py it still doesn't work (I'm completely guessing if that's not clear!)

As a side note - I found this part of the setup really unclear. https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/nitpick.html#project-repository
Do I still need a nitpick-style.toml if I've added style = "..." to my pyproject?

Thanks folks!

EDIT:
realised I should probably include my pyproject.toml

[tool.poetry]
name = "session"
version = "0.1.0"
description = ""

[tool.nitpick]
style = "https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/nitpick-style.toml"

[tool.poetry.dependencies]
python = "^3.7"

[tool.poetry.dev-dependencies]
flakehell = "^0.3.3"
nitpick = "^0.22.1"
wemake-python-styleguide = "^0.14.0"


[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

@andreoliwa
Copy link
Owner

Hey @Phil-Barber,

flake8 is running fine but poetry run nitpick gives [FileNotFoundError]

Nitpick is (for now) a flake8 plugin, it still doesn't have its own executable script, so poetry run nitpick doesn't work indeed.
You should use poetry run flake8 instead.

You should see nitpick: 0.22.1 listed when you run poetry run flake8 --version.

As a side note - I found this part of the setup really unclear. https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/nitpick.html#project-repository

This documentation page is from WeMake, not from Nitpick... 😄

Do I still need a nitpick-style.toml if I've added style = "..." to my pyproject?

No, it's one or the other.
Check the default search order for a style.


I hope that helps.
Let me know if you still have questions.
Cheers!

@Phil-Barber
Copy link

Thanks for the reply @andreoliwa - Apologies for the misunderstanding, that's really cleared things up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Feature/fix is released
Projects
None yet
Development

No branches or pull requests

4 participants