How to evaluate PEP-508-style platform markers?
up vote
2
down vote
favorite
I'd like to programmatically evaluate PEP-508-style platform markers such as platform_system == 'Windows'
. It's not terribly challenging to implement a parser, but I assume there is one in pip. What is it called and how can I import & use it in my own script?
python pip
add a comment |
up vote
2
down vote
favorite
I'd like to programmatically evaluate PEP-508-style platform markers such as platform_system == 'Windows'
. It's not terribly challenging to implement a parser, but I assume there is one in pip. What is it called and how can I import & use it in my own script?
python pip
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'd like to programmatically evaluate PEP-508-style platform markers such as platform_system == 'Windows'
. It's not terribly challenging to implement a parser, but I assume there is one in pip. What is it called and how can I import & use it in my own script?
python pip
I'd like to programmatically evaluate PEP-508-style platform markers such as platform_system == 'Windows'
. It's not terribly challenging to implement a parser, but I assume there is one in pip. What is it called and how can I import & use it in my own script?
python pip
python pip
asked Nov 21 at 17:54
Tamás Szelei
13.9k1377146
13.9k1377146
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08
add a comment |
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
pkg_resources
pkg_resources
(part of the setuptools
package) provides marker evaluation function.
In [1]: from pkg_resources import evaluate_marker
In [2]: evaluate_marker('sys_platform == "darwin"')
Out[2]: True
In [3]: evaluate_marker('python_version > "3.7"')
Out[3]: False
In [4]: evaluate_marker('implementation_name == "cpython"')
Out[4]: True
In [5]: evaluate_marker('garbage')
Traceback (most recent call last):
File "/Users/hoefling/Library/Python/3.7/lib/python/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-69434540d2ec>", line 1, in <module>
evaluate_marker('garbage')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1372, in evaluate_marker
raise SyntaxError(e)
File "<string>", line unknown
SyntaxError: Invalid marker: 'garbage', parse error at 'garbage'
etc.
packaging
Under the hood, pkg_resources.evaluate_marker
uses packaging.markers.Marker.evaluate
from the packaging
package, so you can use that instead:
In [6]: from packaging.markers import Marker
In [7]: Marker('"linux" in sys_platform').evaluate()
Out[7]: False
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
pkg_resources
pkg_resources
(part of the setuptools
package) provides marker evaluation function.
In [1]: from pkg_resources import evaluate_marker
In [2]: evaluate_marker('sys_platform == "darwin"')
Out[2]: True
In [3]: evaluate_marker('python_version > "3.7"')
Out[3]: False
In [4]: evaluate_marker('implementation_name == "cpython"')
Out[4]: True
In [5]: evaluate_marker('garbage')
Traceback (most recent call last):
File "/Users/hoefling/Library/Python/3.7/lib/python/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-69434540d2ec>", line 1, in <module>
evaluate_marker('garbage')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1372, in evaluate_marker
raise SyntaxError(e)
File "<string>", line unknown
SyntaxError: Invalid marker: 'garbage', parse error at 'garbage'
etc.
packaging
Under the hood, pkg_resources.evaluate_marker
uses packaging.markers.Marker.evaluate
from the packaging
package, so you can use that instead:
In [6]: from packaging.markers import Marker
In [7]: Marker('"linux" in sys_platform').evaluate()
Out[7]: False
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
add a comment |
up vote
2
down vote
accepted
pkg_resources
pkg_resources
(part of the setuptools
package) provides marker evaluation function.
In [1]: from pkg_resources import evaluate_marker
In [2]: evaluate_marker('sys_platform == "darwin"')
Out[2]: True
In [3]: evaluate_marker('python_version > "3.7"')
Out[3]: False
In [4]: evaluate_marker('implementation_name == "cpython"')
Out[4]: True
In [5]: evaluate_marker('garbage')
Traceback (most recent call last):
File "/Users/hoefling/Library/Python/3.7/lib/python/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-69434540d2ec>", line 1, in <module>
evaluate_marker('garbage')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1372, in evaluate_marker
raise SyntaxError(e)
File "<string>", line unknown
SyntaxError: Invalid marker: 'garbage', parse error at 'garbage'
etc.
packaging
Under the hood, pkg_resources.evaluate_marker
uses packaging.markers.Marker.evaluate
from the packaging
package, so you can use that instead:
In [6]: from packaging.markers import Marker
In [7]: Marker('"linux" in sys_platform').evaluate()
Out[7]: False
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
pkg_resources
pkg_resources
(part of the setuptools
package) provides marker evaluation function.
In [1]: from pkg_resources import evaluate_marker
In [2]: evaluate_marker('sys_platform == "darwin"')
Out[2]: True
In [3]: evaluate_marker('python_version > "3.7"')
Out[3]: False
In [4]: evaluate_marker('implementation_name == "cpython"')
Out[4]: True
In [5]: evaluate_marker('garbage')
Traceback (most recent call last):
File "/Users/hoefling/Library/Python/3.7/lib/python/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-69434540d2ec>", line 1, in <module>
evaluate_marker('garbage')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1372, in evaluate_marker
raise SyntaxError(e)
File "<string>", line unknown
SyntaxError: Invalid marker: 'garbage', parse error at 'garbage'
etc.
packaging
Under the hood, pkg_resources.evaluate_marker
uses packaging.markers.Marker.evaluate
from the packaging
package, so you can use that instead:
In [6]: from packaging.markers import Marker
In [7]: Marker('"linux" in sys_platform').evaluate()
Out[7]: False
pkg_resources
pkg_resources
(part of the setuptools
package) provides marker evaluation function.
In [1]: from pkg_resources import evaluate_marker
In [2]: evaluate_marker('sys_platform == "darwin"')
Out[2]: True
In [3]: evaluate_marker('python_version > "3.7"')
Out[3]: False
In [4]: evaluate_marker('implementation_name == "cpython"')
Out[4]: True
In [5]: evaluate_marker('garbage')
Traceback (most recent call last):
File "/Users/hoefling/Library/Python/3.7/lib/python/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-69434540d2ec>", line 1, in <module>
evaluate_marker('garbage')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1372, in evaluate_marker
raise SyntaxError(e)
File "<string>", line unknown
SyntaxError: Invalid marker: 'garbage', parse error at 'garbage'
etc.
packaging
Under the hood, pkg_resources.evaluate_marker
uses packaging.markers.Marker.evaluate
from the packaging
package, so you can use that instead:
In [6]: from packaging.markers import Marker
In [7]: Marker('"linux" in sys_platform').evaluate()
Out[7]: False
edited Nov 22 at 2:46
answered Nov 22 at 2:39
hoefling
11.2k42759
11.2k42759
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
add a comment |
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Perfect, thank you very much! This is exactly what I needed.
– Tamás Szelei
Nov 22 at 10:31
Glad I could help!
– hoefling
Nov 22 at 12:27
Glad I could help!
– hoefling
Nov 22 at 12:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417969%2fhow-to-evaluate-pep-508-style-platform-markers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
pip does not have a public library API, and the pip devs don't want people importing & using the code in their own scripts. See the documentation for more information.
– jwodder
Nov 21 at 17:58
Thanks for the heads-up. I kinda remembered that and since I'm controlling the whole environment, I'm fine with ignoring that.
– Tamás Szelei
Nov 21 at 18:08