-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
peotry version doesn't bump the value in __version__ #144
Comments
At the moment this is not possible no.
|
I really wish that the |
Setuptoos has solved this problem for 2 years:
https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files
You can put all metadata in setup.cfg instead of setup.py. For the version, you can specify:
version = attr: src.__version__
Which will load the version from the package directly, this way you have it in one place only. It works as long as you has setuptools >= 30.3 (current version is 38.5.1) so basically any package with a setup.py can already benefit from that without using any additional tool.
Le 27/05/2018 à 07:28, Victor-Nicolae Savu a écrit :
… I really wish that the |version| field in the |.toml| ended up
superseding the |__version__| string in |__init__.py|. This would reduce
the burden of having to keep multiple places in the code in sync.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#144 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANivj7pFmuXBG79h1VOEG9_SM0V4Tj1ks5t2jl7gaJpZM4UO8xi>.
|
@ksamuel Thanks for pointing that out! I use that |
you may use that
|
Now that doesn't work when the file system is not available, or when the project file is not shiped.
Le 27/05/2018 à 20:21, jgirardet a écrit :
… you may use that
|import toml from pathlib import Path def get_version(): path =
Path(__file__).resolve().parents[1] / 'pyproject.toml' pyproject =
toml.loads(open(str(path)).read()) return
pyproject['tool']['poetry']['version'] __version__ = get_version() |
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#144 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANivtdMQKQ53fmYDl0RaC2Wh-ZviBhlks5t2u6TgaJpZM4UO8xi>.
|
Personally I think storing a
If used with:
This will work even when developing locally (it requires the egg-info). |
It doesn't work with vendoring, or anything using sys.path.append. And it's way harder to type in an interpretter. Who remember that ?
Le 30/05/2018 à 19:54, Bert JW Regeer a écrit :
… Personally I think storing a |__version__| in |__init__.py| seems
duplicative. You can use |pkg_resources| to retrieve the version for the
installed package using:
|pkg_resources.get_distribution("packagename").version |
If used with:
|poetry develop |
This will work even when developing locally (it requires the egg-info).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#144 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANivn9NPZz_2OgTFG4OPozzcHa3zB_xks5t3tzvgaJpZM4UO8xi>.
|
Using |
Currently workaround can be to use For my package
To bump the version: Provided configuration will also commit the modification and create tag. This (and many more features) are configurable. A little problem is, that currently it requires extra configuration file The tool seems rather mature, has many features and is used for quite some time. To implement bumping versions in poetry, it may serve at least as nice inspiration. |
Apart from poetry itself, import configparser
parser = configparser.ConfigParser()
parser.read("pyproject.toml")
__version__ = parser["tool.poetry"]["version"]
__all__ = ["__version__"] |
One thing to keep in mind with the automatisms like that is that they will access the disk on importing the library. Code execution on import is not that uncommon in Python, but not desireable to keep down import times and minimize side effects. Does the pyproject.toml file even ship with wheels? |
@pmav99 you can't do that unless you also ship |
I also think this is something very important. Another example is when you integrate it with a tool like Sentry, you are willing to know for which version it applies. Currently, I couldn't find a proper way to include it except writing a |
Depending on your build process, one solution is to use a shell script for bumping the version instead of running
This command can be run as follows: If you dislike specifying the version(type) that way, this could just as easily be implemented as a shell script such as: poetry version $1
new_vers=$(cat pyproject.toml | grep "^version = \"*\"" | cut -d'"' -f2)
sed -i "" "s/__version__ = .*/__version__ = \"${new_vers}\"/g" x12_utils/__init__.py |
this will be improved after poetry fixed issue python-poetry/poetry#144
In my case reading from |
I would also like to see
Since |
Added a dry-run option to version command and logic to replace current version strings with next version in: - pyproject.toml - python source ( assignments & comparisons ) - markdown | restructured text | plain text
I've prototyped this feature and would like some feedback. I consider this an 80% solution that will make most people happy. In addition to updating
The updated command syntax is: poetry version <rule> [--dry-run] |
@JnyJny If I understand correctly, your current approach for text files is just replacing the version string wherever it occurs in any file with a matching extension. I feel like that has a relatively high potential for false positives, e.g. if you list required versions for dependencies anywhere in your documentation. I haven't dug into your implementation for python files at all but in principle I think it would be less likely to cause problems there (given you can analyze code more deeply than documentation, and code is less likely to include unrelated version strings). Also, I think this would be a nice quality-of-life improvement even if it was only applied to |
Reading this thread, it seems to me that for now it's best to keep both the So my process is just to stop me accidentally forgetting to update one. I've got a simple test that checks that those two are in alignment and fails if not. import toml
from pathlib import Path
import my_package
def test_versions_are_in_sync():
"""Checks if the pyproject.toml and package.__init__.py __version__ are in sync."""
path = Path(__file__).resolve().parents[2] / "pyproject.toml"
pyproject = toml.loads(open(str(path)).read())
pyproject_version = pyproject["tool"]["poetry"]["version"]
package_init_version = my_package.__version__
assert package_init_version == pyproject_version Seems to do the job without having to resort to some of the convoluted solutions above which may be hard to maintain |
Here is my suggestion. First, #v0.1.0 ( its a hashtag. pun intended. xD )
The following code can be used inside #!/usr/bin/env python3
import re
from pathlib import Path
HERE = Path(__file__).parent
version_file = HERE / "CloudflareAPI/__version__.py"
version_file = version_file.resolve(strict=True).read_text()
version = re.search(r'#v(.+)', version_file).group(1)
print(version) It can also be used in test files where the version is required. Any thoughts? |
I'm coming in here in Jan 2022, and I'm actually just looking for the canonical answer. Where is the single source of truth spot to put the version string (or where in the docs as poetry version doesn't seem to be the place). I ran across this: which seems to show that others have this issue and are solving it with plugins but if I missed this a pointer in the right direction is appreciated. |
this will be improved after poetry fixed issue python-poetry/poetry#144
I'd also like some clarification. I'm not sure what to follow. There are still several different plugins floating around:
I'm fine to use |
Does this work for packages in development mode? Can you point me to tests? |
Well FWIW in jsonvice I solved the problem by adding: and this in the master source code file: import pkg_resources # part of setuptools Now there is only one place the version is only specified in pyproject.toml and the string is available at runtime so the program can self-report its version number when queried. |
I have published poetry-bumpversion plugin to update version in other files when poetry upgrades the package version. To update [tool.poetry_bumpversion.file."your_package/__init__.py"] |
FWIW I'm using this: import importlib.metadata
__version__= importlib.metadata.version('<package name>') Works fine 👍 |
I also switched to My Take Away for Pros: Cons: BonusHere is the github action snippet code to trigger a package publish for version 1.0.0
I use manually gh cli
|
We now specify the package version in a single place: pyproject.toml so it's not necessary to dynamically figure it out in setup.py. Copped the new contents of __version__.py from the Poetry github issue tracker here: python-poetry/poetry#144 (comment) Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]> (2/x) Move package description from setup.py Signed-off-by: Jesse Whitehouse <[email protected]> (3/x) Move package author from setup.py to pyproject.toml Signed-off-by: Jesse Whitehouse <[email protected]> (4/x) Move classifiers from setup.py to pyproject.toml Signed-off-by: Jesse Whitehouse <[email protected]> squash with 56005dc Signed-off-by: Jesse Whitehouse <[email protected]> (5/x) Move long description from setup.py to pyproject.toml Poetry will take the configured readme and set the long_description to its contents and the long_description_content_type to "text/markdown" automatically. Ref: python-poetry/poetry#1979 Signed-off-by: Jesse Whitehouse <[email protected]> (6/x) Move python dependency spec from setup.py to pyproject.toml Signed-off-by: Jesse Whitehouse <[email protected]> (7/x) Move package version from setup.py to pyproject.toml We now specify the package version in a single place: pyproject.toml so it's not necessary to dynamically figure it out in setup.py. Copped the new contents of __version__.py from the Poetry github issue tracker here: python-poetry/poetry#144 (comment) Signed-off-by: Jesse Whitehouse <[email protected]> (8/x) Move namespace package inclusion from setup.py to pyproject.toml Note that per poetry docs [^1] > Poetry is clever enough to detect Python subpackages. > > Thus, you only have to specify the directory where your root package resides. [1]: https://python-poetry.org/docs/pyproject/ Signed-off-by: Jesse Whitehouse <[email protected]> (9/x) Move homepage from setup.py to pyproject.toml Also add the repository metadata which appears in the Pypi sidebar Signed-off-by: Jesse Whitehouse <[email protected]> (10/x) Entirely remove zip_safe config It's obsolete: https://setuptools.pypa.io/en/latest/deprecated/zip_safe.html and not required by poetry python-poetry/poetry#928 (comment) Signed-off-by: Jesse Whitehouse <[email protected]> (11/x) Move project dependencies from setup.py and requirements.txt (where they were duplicated) into pyproject.toml This adds the locked dependencies in poetry.lock Signed-off-by: Jesse Whitehouse <[email protected]> (12/x) Entirely remove setup.py Signed-off-by: Jesse Whitehouse <[email protected]> (13/x) Move dev dependencies from dev-requirements.txt Re-lock the dependencies Signed-off-by: Jesse Whitehouse <[email protected]> (14/x) Completely remove MANIFEST.in It's not needed by poetry Ref: https: //stackoverflow.com/questions/64654860/replacing-manifest-in-with-pyproject-toml Signed-off-by: Jesse Whitehouse <[email protected]> (15/x) Entirely remove /scripts This script is to be replaced with `poetry build` Signed-off-by: Jesse Whitehouse <[email protected]> I compared a build from `poetry build` to the output from `python setup.py sdist bdist_wheel` and then ran a diff against the generated files. Here's what I found. I added line numbers that I can reference below. ``` 1 Only in dbt-databricks-1.6.1-pypi: MANIFEST.in 2 Files dbt-databricks-1.6.1-pypi/PKG-INFO and dbt_databricks-1.6.1-poetry/PKG-INFO differ 3 Files dbt-databricks-1.6.1-pypi/dbt/adapters/databricks/__version__.py and dbt_databricks-1.6.1-poetry/dbt/adapters/databricks/__version__.py differ 4 Only in dbt-databricks-1.6.1-pypi: dbt_databricks.egg-info 5 Only in dbt_databricks-1.6.1-poetry: pyproject.toml 6 Only in dbt-databricks-1.6.1-pypi: setup.cfg 7 Only in dbt-databricks-1.6.1-pypi: setup.py ``` 1: OK see e55e261 2: OK differences are because poetry writes an extra classifier and includes the new homepage 3: OK difference is because we now automatically fetch the package version set by pyproject.toml 4: OK we're not uploading eggs anymore. They're about to be deprecated by pypi anyway https://blog.pypi.org/posts/2023-06-26-deprecate-egg-uploads/ 5: OK to add pyproject.toml to the output distribution. This is standard for poetry. 6: OK this is egg-related. See diff 4. 7: OK since we don't use setup.py anymore Signed-off-by: Jesse Whitehouse <[email protected]> moving linting to nox (and eventually everything from tox) unit tests to nox migrating integration tests typo use cluster http path Replace build_dist.sh to perform build checks Signed-off-by: Jesse Whitehouse <[email protected]> Preliminary GitHub Action to publish to test-pypi with poetry Signed-off-by: Jesse Whitehouse <[email protected]>
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I don't know if it's intended or not. A way to do that safely is to parse the root
__init__.py
, detect__version__
, back it up, extract the ast, bump the version string and replace it, then extract the new ast and compare the result. If both ast are the same, except for the version, the file semantics have been preserved. Otherwise, rollback the change and display an error message stating we can't bump the version safely.The text was updated successfully, but these errors were encountered: