That being said if your package depends on ros_environment the following environment variables are set: ROS_VERSION (which is either 1 or 2), ROS_DISTRO (e.g. dashing or melodic), etc.