Skip to content
New issue

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

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

Already on GitHub? # to your account

towncrier assumes working on a python package #320

Closed
mihai-unity opened this issue Feb 5, 2021 · 15 comments
Closed

towncrier assumes working on a python package #320

mihai-unity opened this issue Feb 5, 2021 · 15 comments
Labels

Comments

@mihai-unity
Copy link

I'm trying to run towncrier on an npm package but I think it assumes a python package even though README implies it's an optional requirement.

How to reproduce
From an empty git repo.

  1. Create a basic config file:
[tool.towncrier]
directory = "changes"
  1. Create your first fragment.
$ towncrier create 123.feature                                                                                                                                                                                                                                      
Created news fragment at ~/src/repo/changes/123.feature
  1. Then try build
$ towncrier build --draft
Loading template...
Finding news fragments...
Rendering news fragments...
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/towncrier/build.py", line 63, in _main
    return __main(
  File "/usr/local/lib/python3.8/site-packages/towncrier/build.py", line 122, in __main
    project_version = get_version(
  File "/usr/local/lib/python3.8/site-packages/towncrier/_project.py", line 45, in get_version
    module = _get_package(package_dir, package)
  File "/usr/local/lib/python3.8/site-packages/towncrier/_project.py", line 25, in _get_package
    module = import_module(package)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1011, in _gcd_import
  File "<frozen importlib._bootstrap>", line 950, in _sanity_check
ValueError: Empty module name
Traceback (most recent call last):
  File "/usr/local/bin/towncrier", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/towncrier/build.py", line 63, in _main
    return __main(
  File "/usr/local/lib/python3.8/site-packages/towncrier/build.py", line 122, in __main
    project_version = get_version(
  File "/usr/local/lib/python3.8/site-packages/towncrier/_project.py", line 45, in get_version
    module = _get_package(package_dir, package)
  File "/usr/local/lib/python3.8/site-packages/towncrier/_project.py", line 25, in _get_package
    module = import_module(package)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1011, in _gcd_import
  File "<frozen importlib._bootstrap>", line 950, in _sanity_check
ValueError: Empty module name
@mihai-unity
Copy link
Author

great idea btw, we would really like to switch using it

@mihai-unity
Copy link
Author

Apparently you need to pass --version. Seems like we could do an easy fix.

@altendky
Copy link
Member

altendky commented Feb 5, 2021

There have been some changes which have not yet been released that relate to using towncrier with non-Python projects. There are some infrastructure problems I'm working on before releasing but if you wanted to you could try installing the latest from Git. howeveryourefertopip install https://github.com/twisted/towncrier/archive/master.zip for example.

But, yes, I get a similar traceback. I'll look some more before committing to changing it but it does seem like this is a reasonable case for a more descriptive error message. Thanks for reporting this.

@altendky altendky added the bug label Feb 5, 2021
@jfinkhaeuser
Copy link

This has been sitting around for almost a year. Is there a release that supports non-Python projects yet?

I mean, you can always hack it by adding an empty Python module to your sources.

@adiroiban
Copy link
Member

adiroiban commented Feb 10, 2022

We have the 21.9.0 release candidate done in Sept 2021 at #360

But until 11 days ago, nobody had time to check the package and report if all is ok.

so @jfinkhaeuser you can give that release a try and see if its fixed.

it would be nice to send a report here :)

@jfinkhaeuser
Copy link

Seems to work the way I'm using it.

@adiroiban
Copy link
Member

The public release will be out soon (tm) :)

@adiroiban
Copy link
Member

so I guess that this can be closed as this is fixed.

@jaller94
Copy link

Still doesn't work for me if pyproject.toml doesn't have a [tool.towncrier]package.

[jaller94@Jaller-L490 matrix-appservice-slack]$ pip install --upgrade --user towncrier
Requirement already satisfied: towncrier in /home/jaller94/.local/lib/python3.10/site-packages (21.9.0)
Collecting towncrier
  Using cached towncrier-21.9.0-py2.py3-none-any.whl (32 kB)
  Downloading towncrier-21.3.0-py2.py3-none-any.whl (32 kB)
Requirement already satisfied: incremental in /home/jaller94/.local/lib/python3.10/site-packages (from towncrier) (21.3.0)
Requirement already satisfied: setuptools in /usr/lib/python3.10/site-packages (from towncrier) (59.3.0)
Requirement already satisfied: tomli in /usr/lib/python3.10/site-packages (from towncrier) (2.0.0)
Requirement already satisfied: jinja2 in /usr/lib/python3.10/site-packages (from towncrier) (3.0.3)
Requirement already satisfied: click-default-group in /home/jaller94/.local/lib/python3.10/site-packages (from towncrier) (1.2.2)
Requirement already satisfied: click in /usr/lib/python3.10/site-packages (from towncrier) (8.0.4)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/lib/python3.10/site-packages (from jinja2->towncrier) (2.0.1)
[jaller94@Jaller-L490 matrix-appservice-slack]$ towncrier --version
towncrier, version 21.9.0
[jaller94@Jaller-L490 matrix-appservice-slack]$ towncrier build
Loading template...
Finding news fragments...
Rendering news fragments...
Traceback (most recent call last):
  File "/home/jaller94/.local/bin/towncrier", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/jaller94/.local/lib/python3.10/site-packages/towncrier/build.py", line 62, in _main
    return __main(
  File "/home/jaller94/.local/lib/python3.10/site-packages/towncrier/build.py", line 120, in __main
    project_version = get_version(
  File "/home/jaller94/.local/lib/python3.10/site-packages/towncrier/_project.py", line 41, in get_version
    module = _get_package(package_dir, package)
  File "/home/jaller94/.local/lib/python3.10/site-packages/towncrier/_project.py", line 20, in _get_package
    module = import_module(package)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1047, in _gcd_import
  File "<frozen importlib._bootstrap>", line 981, in _sanity_check
ValueError: Empty module name

@adiroiban
Copy link
Member

adiroiban commented Mar 21, 2022

I think that you need to call it like this:

$ towncrier build --config towncrier.toml --version 1.2.3

Since no version was passed from the command line, towncrier tries to load the python project and extract the version from there.


I agree that the error message is not the best. PR welcomed :)


What is the expected result for your build command?
What version should be used for that release?
From where should towncrier pick that version?

Cheers

@jaller94
Copy link

Yes, we forgot the --version 1.0 in towncrier build --version $VERSION.

@jfinkhaeuser
Copy link

Maybe more as a feature request, it would be nice to teach towncrier to grab this version from some file that has nothing to do with a python project.

@adiroiban
Copy link
Member

Maybe more as a feature request, it would be nice to teach towncrier to grab this version from some file that has nothing to do with a python project.

I am not familiar with how other programming languages are versioned,
As long there is "a standard way" to declare the version, I don't see why towncrier should not use that.

PR welcomed :)


I guess that you can always update your release script to grab the version via some external command and then pass that version to towncrier.

I have python project, but the in release process I have a script that does various other things to prepare the release, including the release notes, and it always explicitly passed the version via CLI.

@jfinkhaeuser
Copy link

There is no standard way for many languages (for some there is).

I was thinking more along the lines of grepping for a pattern in a file to extract the version, making both configurable.

I'm not really touching Python code since the Rust desaster in which a maintainer discriminated against me. Make of that what you will, but unfortunately that means I won't invest time in a PR. And I accept that this may mean that I never see this change.

@jaller94
Copy link

For NodeJS/NPM projects, this works:

VERSION=`python3 -c "import json; f = open('./package.json', 'r'); v = json.loads(f.read())['version']; f.close(); print(v)"`

package.json should have the top-level property version.

{
  "name": "matrix-appservice-slack",
  "version": "1.10.0",
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants