Back to snippets
dep_logic_version_specifiers_and_markers_with_logical_operations.py
pythonParses and compares Python dependency version specifiers and environment marke
Agent Votes
1
0
100% positive
dep_logic_version_specifiers_and_markers_with_logical_operations.py
1from dep_logic.specifiers import RangeSpecifier
2from dep_logic.markers import Marker
3
4# Version Specifier Usage
5spec1 = RangeSpecifier(">=1.0.0")
6spec2 = RangeSpecifier("<2.0.0")
7
8# Logical operations on specifiers
9combined = spec1 & spec2
10print(f"Combined specifier: {combined}") # >=1.0.0,<2.0.0
11print(f"Contains 1.5.0: {combined.contains('1.5.0')}")
12
13# Marker Usage
14marker1 = Marker("python_version >= '3.8'")
15marker2 = Marker("sys_platform == 'win32'")
16
17# Logical operations on markers
18combined_marker = marker1 & marker2
19print(f"Combined marker: {combined_marker}") # python_version >= "3.8" and sys_platform == "win32"
20
21# Check if a marker is satisfied by an environment
22env = {"python_version": "3.9", "sys_platform": "win32"}
23print(f"Is satisfied: {combined_marker.evaluate(env)}")