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

Can't download default style with nitpick #115

Closed
Skrierz opened this issue Nov 9, 2019 · 8 comments · Fixed by #124
Closed

Can't download default style with nitpick #115

Skrierz opened this issue Nov 9, 2019 · 8 comments · Fixed by #124
Labels
bug Something isn't working released Feature/fix is released

Comments

@Skrierz
Copy link

Skrierz commented Nov 9, 2019

Expected Behavior

I expect nitpick to download default style file.

Current Behavior

I get Requests exception about invalid url.

Traceback (most recent call last):
  File "C:\Users\Sleip\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Sleip\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Sleip\Desktop\Git\poe_gems_requirements\venv\Scripts\flake8.exe\__main__.py", line 9, in <module>
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\main\cli.py", line 18, in main
    app.run(argv)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\main\application.py", line 393, in run
    self._run(argv)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\main\application.py", line 381, in _run
    self.run_checks()
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\main\application.py", line 300, in run_checks
    self.file_checker_manager.run()
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\checker.py", line 331, in run
    self.run_serial()
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\checker.py", line 315, in run_serial
    checker.run_checks()
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\checker.py", line 598, in run_checks
    self.run_ast_checks()
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\flake8\checker.py", line 502, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\plugin.py", line 50, in run
    Nitpick.current_app().config.merge_styles(), self.check_files(True), self.check_files(False)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\config.py", line 65, in merge_styles
    style.find_initial_styles(configured_styles)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\style.py", line 61, in find_initial_styles
    self.include_multiple_styles(chosen_styles)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\style.py", line 97, in include_multiple_styles
    self.include_multiple_styles(sub_styles)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\style.py", line 76, in include_multiple_styles
    style_path = self.get_style_path(style_uri)  # type: Optional[Path]
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\style.py", line 105, in get_style_path
    style_path = self.fetch_style_from_url(clean_style_uri)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\nitpick\style.py", line 134, in fetch_style_from_url
    response = requests.get(new_url)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\models.py", line 313, in prepare
    self.prepare_url(url, params)
  File "c:\users\sleip\desktop\git\poe_gems_requirements\venv\lib\site-packages\requests\models.py", line 390, in prepare_url
    raise InvalidURL("Invalid URL %r: No host supplied" % url)
requests.exceptions.InvalidURL: Invalid URL 'https:///C:\\raw.githubusercontent.com\\andreoliwa\\nitpick\\v0.21.2\\styles\\python37.toml': No host supplied

Possible Solution

I think that problem is due to resolving domain_plus_url in style.fetch_style_from_url.
I don't understand why it's done for but it's looks like that problem can accure on Linux too.

>>> url = PosixPath('\\raw.githubusercontent.com\\andreoliwa\\nitpick\\v0.21.2\\styles\\python37')
>>> url.resolve()
PosixPath('/home/.anon-737a48732c124779a7a9e587/\\raw.githubusercontent.com\\andreoliwa\\nitpick\\v0.21.2\
\styles\\python37')

>>> url = WindowsPath('\\raw.githubusercontent.com\\andreoliwa\\nitpick\\v0.21.2\\styles\\python37')
>>> url.resolve()
WindowsPath('C:/raw.githubusercontent.com/andreoliwa/nitpick/v0.21.2/styles/python37')

Steps to Reproduce

  1. Install nitpick.
  2. Open project without any configs for flake8/nitpick.
  3. Run flake8 in project root.
  4. Get exception.

Your Environment

  • nitpick version used: 0.21.2

  • Python version: Python 3.7.4

  • Operating System and version: Windows 10

  • Run the following commands and paste the output:

    (venv) C:\Users\Sleip\Desktop\Git\poe_gems_requirements>where python
    C:\Users\Sleip\Desktop\Git\poe_gems_requirements\venv\Scripts\python.exe
    C:\Users\Sleip\AppData\Local\Programs\Python\Python37-32\python.exe
    
    (venv) C:\Users\Sleip\Desktop\Git\poe_gems_requirements>python -V
    Python 3.7.4
    
    (venv) C:\Users\Sleip\Desktop\Git\poe_gems_requirements>pip freeze
    altgraph==0.16.1
    astor==0.8.0
    atomicwrites==1.3.0
    attrs==19.2.0
    bandit==1.6.2
    certifi==2019.9.11
    chardet==3.0.4
    Click==7.0
    colorama==0.3.9
    dictdiffer==0.8.0
    docutils==0.15.2
    entrypoints==0.3
    eradicate==1.0
    flake8==3.7.8
    flake8-annotations-complexity==0.0.2
    flake8-bandit==2.1.2
    flake8-broken-line==0.1.1
    flake8-bugbear==19.8.0
    flake8-builtins==1.4.1
    flake8-coding==1.3.2
    flake8-commas==2.0.0
    flake8-comprehensions==2.2.0
    flake8-debugger==3.1.1
    flake8-docstrings==1.5.0
    flake8-eradicate==0.2.2
    flake8-executable==2.0.3
    flake8-isort==2.7.0
    flake8-logging-format==0.6.0
    flake8-pep3101==1.2.1
    flake8-polyfill==1.0.2
    flake8-print==3.1.1
    flake8-quotes==2.1.0
    flake8-rst-docstrings==0.0.11
    flake8-string-format==0.2.3
    future==0.18.0
    gitdb2==2.0.6
    GitPython==3.0.3
    idna==2.8
    importlib-metadata==0.23
    isort==4.3.21
    jmespath==0.9.4
    mando==0.6.4
    marshmallow==3.2.1
    marshmallow-polyfield==5.7
    mccabe==0.6.1
    more-itertools==7.2.0
    nitpick==0.21.2
    packaging==19.2
    pbr==5.4.3
    pefile==2019.4.18
    pep8-naming==0.8.2
    pluggy==0.13.0
    py==1.8.0
    pycodestyle==2.5.0
    pydocstyle==4.0.1
    pyflakes==2.1.1
    Pygments==2.4.2
    PyInstaller==3.5
    pyparsing==2.4.2
    pytest==5.2.1
    python-slugify==3.0.6
    pywin32-ctypes==0.2.0
    PyYAML==5.1.2
    radon==2.4.0
    requests==2.22.0
    restructuredtext-lint==1.3.0
    ruamel.yaml==0.16.5
    ruamel.yaml.clib==0.2.0
    six==1.12.0
    smmap2==2.0.5
    snowballstemmer==2.0.0
    sortedcontainers==2.1.0
    stevedore==1.31.0
    testfixtures==6.10.0
    text-unidecode==1.3
    toml==0.10.0
    typing-extensions==3.7.4
    urllib3==1.25.6
    wcwidth==0.1.7
    wemake-python-styleguide==0.12.5
    zipp==0.6.0
@Skrierz Skrierz added the bug Something isn't working label Nov 9, 2019
@andreoliwa
Copy link
Owner

Hi @Skrierz. Thanks for this new bug report, thanks for using nitpick on Windows.

I think that problem is due to resolving domain_plus_url in style.fetch_style_from_url.
I don't understand why it's done for but it looks like that problem can occur on Linux too.

The code Path(rest) / url should work on Linux because the URL path separator is the same as the file path separator (/).
But this doesn't work on Windows, because the file path separator is \.

I need to improve this logic and do something generic that can also work on Windows.
I will keep you posted. 😉

@andreoliwa
Copy link
Owner

@Skrierz could you try this branch and tell me if it works?

https://github.com/andreoliwa/nitpick/tree/fix-fetch-url
#124

@Skrierz
Copy link
Author

Skrierz commented Dec 1, 2019

Hi @andreoliwa.
Thanks for update!

I checked fix and unfortunately it doesn't work. I get pathlib exception:

NotImplementedError: cannot instantiate 'PosixPath' on your system

@andreoliwa
Copy link
Owner

Damn... the quick fix didn't work as I expected.
So I will rewrite that part of the code and let you know.

Thanks for testing it!

@andreoliwa
Copy link
Owner

@Skrierz could you try again and tell me if it works now?

https://github.com/andreoliwa/nitpick/tree/fix-fetch-url
#124

@Skrierz
Copy link
Author

Skrierz commented Dec 7, 2019

@andreoliwa
It works!
Thanks for fix!

@andreoliwa
Copy link
Owner

Nice! I will release a new version soon.
Thanks for testing it on Windows!

andreoliwa added a commit that referenced this issue Dec 8, 2019
andreoliwa pushed a commit that referenced this issue Dec 8, 2019
## [0.21.3](v0.21.2...v0.21.3) (2019-12-08)

### Bug Fixes

* concatenate URL manually instead of using Path ([5491b39](5491b39)), closes [#115](#115)
@andreoliwa
Copy link
Owner

🎉 This issue has been resolved in version 0.21.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@andreoliwa andreoliwa added the released Feature/fix is released label Dec 8, 2019
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

Successfully merging a pull request may close this issue.

2 participants