├── .idea
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── poetry-version.iml
├── README.md
├── pyproject.toml
├── poetry_version
└── __init__.py
├── setup.py
├── poetry.lock
├── .gitignore
└── LICENSE
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/poetry-version.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # poetry-version (deprecated)
2 |
3 | ## What to use instead
4 |
5 | Now there is a better way to extract the version of the package.
6 |
7 | Assuming your package is named `mypackage`:
8 | ```python
9 | import importlib.metadata
10 |
11 | __version__ = importlib.metadata.version("mypackage")
12 | ```
13 |
14 | This code should work as is if you are using Python >= 3.8.
15 |
16 | For Python 3.6 and 3.7 you need to install a backport: https://pypi.org/project/importlib-metadata/
17 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.poetry]
2 | name = "poetry-version"
3 | version = "0.2.0"
4 | description = "Python library for extracting version from poetry pyproject.toml file (deprecated)"
5 | authors = ["Roman Inflianskas "]
6 | license = "Apache-2.0"
7 | readme = "README.md"
8 | keywords = ["poetry", "version"]
9 | classifiers = [
10 | "Topic :: Software Development :: Build Tools",
11 | "Topic :: Software Development :: Libraries :: Python Modules",
12 | "Development Status :: 7 - Inactive"
13 | ]
14 | repository = "https://github.com/rominf/poetry-version"
15 |
16 | [tool.poetry.dependencies]
17 | python = "~2.7 || ^3.4"
18 | tomlkit = "^0.4.6 || ^0.5.0"
19 |
20 | [tool.poetry.dev-dependencies]
21 |
22 | [build-system]
23 | requires = ["poetry>=0.12"]
24 | build-backend = "poetry.masonry.api"
25 |
--------------------------------------------------------------------------------
/poetry_version/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from pathlib import Path
4 |
5 | import tomlkit
6 |
7 |
8 | def extract(source_file):
9 | d = Path(source_file)
10 | result = None
11 | while d.parent != d and result is None:
12 | d = d.parent
13 | pyproject_toml_path = d / 'pyproject.toml'
14 | if pyproject_toml_path.exists():
15 | with open(file=str(pyproject_toml_path)) as f:
16 | pyproject_toml = tomlkit.parse(string=f.read())
17 | if 'tool' in pyproject_toml and 'poetry' in pyproject_toml['tool']:
18 | # noinspection PyUnresolvedReferences
19 | result = pyproject_toml['tool']['poetry']['version']
20 | return result
21 |
22 |
23 | if __name__ == '__main__':
24 | print(extract(__file__))
25 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from distutils.core import setup
3 |
4 | packages = \
5 | ['poetry_version']
6 |
7 | package_data = \
8 | {'': ['*']}
9 |
10 | install_requires = \
11 | ['tomlkit>=0.4.6,<0.6.0']
12 |
13 | setup_kwargs = {
14 | 'name': 'poetry-version',
15 | 'version': '0.1.5',
16 | 'description': 'Python library for extracting version from poetry pyproject.toml file',
17 | 'long_description': '# poetry-version\nPython library for extracting version from poetry pyproject.toml file\n\n## Installation\nTo install `poetry-version` from [PyPI](https://pypi.org/project/poetry-version/) run:\n```shell\n$ pip install poetry-version\n```\n\n## Usage\nPut these lines somewhere in the main module:\n```python\nimport poetry_version\n\n__version__ = poetry_version.extract(source_file=__file__)\n```\n',
18 | 'author': 'Roman Inflianskas',
19 | 'author_email': 'infroma@gmail.com',
20 | 'url': 'https://github.com/rominf/poetry-version',
21 | 'packages': packages,
22 | 'package_data': package_data,
23 | 'install_requires': install_requires,
24 | 'python_requires': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
25 | }
26 |
27 |
28 | setup(**setup_kwargs)
29 |
--------------------------------------------------------------------------------
/poetry.lock:
--------------------------------------------------------------------------------
1 | [[package]]
2 | category = "main"
3 | description = "Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4"
4 | marker = "python_version >= \"2.7\" and python_version < \"2.8\""
5 | name = "enum34"
6 | optional = false
7 | python-versions = "*"
8 | version = "1.1.6"
9 |
10 | [[package]]
11 | category = "main"
12 | description = "Backport of the functools module from Python 3.2.3 for use on 2.7 and PyPy."
13 | marker = "python_version >= \"2.7\" and python_version < \"2.8\""
14 | name = "functools32"
15 | optional = false
16 | python-versions = "*"
17 | version = "3.2.3-2"
18 |
19 | [[package]]
20 | category = "main"
21 | description = "Style preserving TOML library"
22 | name = "tomlkit"
23 | optional = false
24 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
25 | version = "0.4.6"
26 |
27 | [package.dependencies]
28 | [package.dependencies.enum34]
29 | python = ">=2.7,<2.8"
30 | version = ">=1.1,<2.0"
31 |
32 | [package.dependencies.functools32]
33 | python = ">=2.7,<2.8"
34 | version = ">=3.2.3,<4.0.0"
35 |
36 | [package.dependencies.typing]
37 | python = ">=2.7,<2.8 || >=3.4,<3.5"
38 | version = ">=3.6,<4.0"
39 |
40 | [[package]]
41 | category = "main"
42 | description = "Type Hints for Python"
43 | marker = "python_version >= \"2.7\" and python_version < \"2.8\" or python_version >= \"3.4\" and python_version < \"3.5\""
44 | name = "typing"
45 | optional = false
46 | python-versions = "*"
47 | version = "3.6.6"
48 |
49 | [metadata]
50 | content-hash = "09a37efc86da3983c41621274fa2fbdec3eff603192afad34286d940df462b54"
51 | python-versions = "~2.7 || ^3.4"
52 |
53 | [metadata.hashes]
54 | enum34 = ["2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850", "644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a", "6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79", "8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1"]
55 | functools32 = ["89d824aa6c358c421a234d7f9ee0bd75933a67c29588ce50aaa3acdf4d403fa0", "f6253dfbe0538ad2e387bd8fdfd9293c925d63553f5813c4e587745416501e6d"]
56 | tomlkit = ["27ddd2796855428a0316057884ec081a1c967c8d29c3d489fcfccd1bb2976ede", "8f857398aefa2c6a488c824f1e7f757e73a4f68246f1874f9df5eb53903231de"]
57 | typing = ["4027c5f6127a6267a435201981ba156de91ad0d1d98e9ddc2aa173453453492d", "57dcf675a99b74d64dacf6fba08fb17cf7e3d5fdff53d4a30ea2a5e7e52543d4", "a4c8473ce11a65999c8f59cb093e70686b6c84c98df58c1dae9b3b196089858a"]
58 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/python,pycharm
3 |
4 | ### PyCharm ###
5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7 |
8 | # User-specific stuff
9 | .idea/**/workspace.xml
10 | .idea/**/tasks.xml
11 | .idea/**/usage.statistics.xml
12 | .idea/**/dictionaries
13 | .idea/**/shelf
14 |
15 | # Generated files
16 | .idea/**/contentModel.xml
17 |
18 | # Sensitive or high-churn files
19 | .idea/**/dataSources/
20 | .idea/**/dataSources.ids
21 | .idea/**/dataSources.local.xml
22 | .idea/**/sqlDataSources.xml
23 | .idea/**/dynamic.xml
24 | .idea/**/uiDesigner.xml
25 | .idea/**/dbnavigator.xml
26 |
27 | # Gradle
28 | .idea/**/gradle.xml
29 | .idea/**/libraries
30 |
31 | # Gradle and Maven with auto-import
32 | # When using Gradle or Maven with auto-import, you should exclude module files,
33 | # since they will be recreated, and may cause churn. Uncomment if using
34 | # auto-import.
35 | # .idea/modules.xml
36 | # .idea/*.iml
37 | # .idea/modules
38 |
39 | # CMake
40 | cmake-build-*/
41 |
42 | # Mongo Explorer plugin
43 | .idea/**/mongoSettings.xml
44 |
45 | # File-based project format
46 | *.iws
47 |
48 | # IntelliJ
49 | out/
50 |
51 | # mpeltonen/sbt-idea plugin
52 | .idea_modules/
53 |
54 | # JIRA plugin
55 | atlassian-ide-plugin.xml
56 |
57 | # Cursive Clojure plugin
58 | .idea/replstate.xml
59 |
60 | # Crashlytics plugin (for Android Studio and IntelliJ)
61 | com_crashlytics_export_strings.xml
62 | crashlytics.properties
63 | crashlytics-build.properties
64 | fabric.properties
65 |
66 | # Editor-based Rest Client
67 | .idea/httpRequests
68 |
69 | # Android studio 3.1+ serialized cache file
70 | .idea/caches/build_file_checksums.ser
71 |
72 | ### PyCharm Patch ###
73 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
74 |
75 | # *.iml
76 | # modules.xml
77 | # .idea/misc.xml
78 | # *.ipr
79 |
80 | # Sonarlint plugin
81 | .idea/sonarlint
82 |
83 | ### Python ###
84 | # Byte-compiled / optimized / DLL files
85 | __pycache__/
86 | *.py[cod]
87 | *$py.class
88 |
89 | # C extensions
90 | *.so
91 |
92 | # Distribution / packaging
93 | .Python
94 | build/
95 | develop-eggs/
96 | dist/
97 | downloads/
98 | eggs/
99 | .eggs/
100 | lib/
101 | lib64/
102 | parts/
103 | sdist/
104 | var/
105 | wheels/
106 | *.egg-info/
107 | .installed.cfg
108 | *.egg
109 | MANIFEST
110 |
111 | # PyInstaller
112 | # Usually these files are written by a python script from a template
113 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
114 | *.manifest
115 | *.spec
116 |
117 | # Installer logs
118 | pip-log.txt
119 | pip-delete-this-directory.txt
120 |
121 | # Unit test / coverage reports
122 | htmlcov/
123 | .tox/
124 | .nox/
125 | .coverage
126 | .coverage.*
127 | .cache
128 | nosetests.xml
129 | coverage.xml
130 | *.cover
131 | .hypothesis/
132 | .pytest_cache/
133 |
134 | # Translations
135 | *.mo
136 | *.pot
137 |
138 | # Django stuff:
139 | *.log
140 | local_settings.py
141 | db.sqlite3
142 |
143 | # Flask stuff:
144 | instance/
145 | .webassets-cache
146 |
147 | # Scrapy stuff:
148 | .scrapy
149 |
150 | # Sphinx documentation
151 | docs/_build/
152 |
153 | # PyBuilder
154 | target/
155 |
156 | # Jupyter Notebook
157 | .ipynb_checkpoints
158 |
159 | # IPython
160 | profile_default/
161 | ipython_config.py
162 |
163 | # pyenv
164 | .python-version
165 |
166 | # celery beat schedule file
167 | celerybeat-schedule
168 |
169 | # SageMath parsed files
170 | *.sage.py
171 |
172 | # Environments
173 | .env
174 | .venv
175 | env/
176 | venv/
177 | ENV/
178 | env.bak/
179 | venv.bak/
180 |
181 | # Spyder project settings
182 | .spyderproject
183 | .spyproject
184 |
185 | # Rope project settings
186 | .ropeproject
187 |
188 | # mkdocs documentation
189 | /site
190 |
191 | # mypy
192 | .mypy_cache/
193 | .dmypy.json
194 | dmypy.json
195 |
196 | ### Python Patch ###
197 | .venv/
198 |
199 | ### Python.VirtualEnv Stack ###
200 | # Virtualenv
201 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
202 | [Bb]in
203 | [Ii]nclude
204 | [Ll]ib
205 | [Ll]ib64
206 | [Ll]ocal
207 | [Ss]cripts
208 | pyvenv.cfg
209 | pip-selfcheck.json
210 |
211 |
212 | # End of https://www.gitignore.io/api/python,pycharm
213 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------