您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

57 行
2.3 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorro - Compute The Next Ephemerides
  3. # Copyright (C) 2019 Jérôme Deuchnord <jerome@deuchnord.fr>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import os
  18. import toml
  19. class Dependency:
  20. def __init__(self, package: str, required_version: [str] = None):
  21. self.package = package
  22. self.required_version = required_version
  23. def get_setup_format(self):
  24. return '%s%s%s' % (self.package,
  25. '=' if self.required_version is not None and len(self.required_version) == 1 else '',
  26. ','.join(self.required_version) if self.required_version is not None else '')
  27. def __str__(self):
  28. return '%s%s' % (self.package,
  29. (' (%s)' % ', '.join(self.required_version)) if self.required_version is not None else '')
  30. def get_dependencies(dev: bool = False) -> [Dependency]:
  31. """
  32. Read the Pipfile and return a dictionary with the project dependencies
  33. :param bool dev: if true, return the development dependencies instead of the production ones. False by default.
  34. :return: a dictionary where the key is the name of the dependency package, and the value is the version(s) accepted.
  35. """
  36. with open('%s/../Pipfile' % os.path.dirname(__file__), mode='r') as file:
  37. pipfile = ''.join(file.readlines())
  38. packages = toml.loads(pipfile)['packages' if not dev else 'dev-packages']
  39. dependencies = []
  40. for package in packages:
  41. version = packages[package].split(',')
  42. dependencies.append(Dependency(package,
  43. version if version != ['*'] else None))
  44. return dependencies