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

Crash when running snakefmt 0.1.4 #65

Closed
kpj opened this issue Sep 8, 2020 · 4 comments
Closed

Crash when running snakefmt 0.1.4 #65

kpj opened this issue Sep 8, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@kpj
Copy link
Contributor

kpj commented Sep 8, 2020

I am using snakefmt v0.1.4 on macOS 10.15.6. When simply running the script, it crashes:

$ snakefmt
Traceback (most recent call last):
  File "/Python/3.8/bin/snakefmt", line 5, in <module>
    from snakefmt.snakefmt import main
  File "/Python/3.8/lib/python/site-packages/snakefmt/__init__.py", line 6, in <module>
    __version__ = toml.load(project_fpath)["tool"]["poetry"]["version"]
  File "/Python/3.8/lib/python/site-packages/toml/decoder.py", line 133, in load
    with io.open(_getpath(f), encoding='utf-8') as ffile:
FileNotFoundError: [Errno 2] No such file or directory: '/Python/3.8/lib/python/site-packages/pyproject.toml'

This seems to be due to the following two lines:

project_fpath = Path(__file__).parent.parent / "pyproject.toml"
__version__ = toml.load(project_fpath)["tool"]["poetry"]["version"]

@mbhall88
Copy link
Member

mbhall88 commented Sep 8, 2020

Yes, I'm also having this problem in bioconda/bioconda-recipes#24238. @bricoletc I think we might need to change the way the version number is gathered back to what it was before?

@mbhall88 mbhall88 added the bug Something isn't working label Sep 8, 2020
bricoletc added a commit that referenced this issue Sep 9, 2020
pyproject.toml file is not distributed, so version extraction was
failing on package distributions.
@bricoletc
Copy link
Collaborator

Thanks for this @kpj , I should totally have looked into this when trying to have single version specification in pyproject.toml.
Problem is pip install does not distribute pyproject.toml. This was really handy to find a fix: python-poetry/poetry#273
Running poetry build to distribute package creates PKG_INFO, pyproject.toml and setup.py files which all have the version from pyproject.toml. Then if you distribute sources and pip install you get a .dist-info directory which contains a METADATA file and that has version in it.

I added fix recommended in python-poetry/poetry#273 by using importlib.metadata.version

I confirmed this works from both pip install snakefmt and poetry install from a local copy of the sources.

@mbhall88 i almost feel like we need to push this change to test pypi or something and pip install to confirm this works?

bricoletc added a commit that referenced this issue Sep 9, 2020
pyproject.toml file is not distributed, so version extraction was
failing on package distributions.
bricoletc added a commit that referenced this issue Sep 9, 2020
@bricoletc
Copy link
Collaborator

@mbhall88 importlib.metadata was only added to Python standard library in 3.8 so my proposed fix now uses a backport called importlibs_metadata. This adds a dependency to snakefmt but I quite like it, you can do a lot more package introspection than just getting the version

@bricoletc
Copy link
Collaborator

This seems to have worked, closing!

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

No branches or pull requests

3 participants