def test_packages_distributions_example2(self): """ Test packages_distributions on a wheel built by trampolim. """ self._fixture_on_path('example2-1.0.0-py3-none-any.whl') assert packages_distributions()['example2'] == ['example2']
def test_packages_distributions_neither_toplevel_nor_files(self): """ Test a package built without 'top-level.txt' or a file list. """ fixtures.build_files( { 'trim_example-1.0.0.dist-info': { 'METADATA': """ Name: trim_example Version: 1.0.0 """, } }, prefix=self.site_dir, ) packages_distributions()
def minversion(module, version, inclusive=True, version_path='__version__'): """ Returns `True` if the specified Python module satisfies a minimum version requirement, and `False` if not. .. deprecated:: ``version_path`` is not used anymore and is deprecated in ``astropy`` 5.0. Parameters ---------- module : module or `str` An imported module of which to check the version, or the name of that module (in which case an import of that module is attempted-- if this fails `False` is returned). version : `str` The version as a string that this module must have at a minimum (e.g. ``'0.12'``). inclusive : `bool` The specified version meets the requirement inclusively (i.e. ``>=``) as opposed to strictly greater than (default: `True`). Examples -------- >>> import astropy >>> minversion(astropy, '0.4.4') True """ if isinstance(module, types.ModuleType): module_name = module.__name__ elif isinstance(module, str): module_name = module try: module = resolve_name(module_name) except ImportError: return False else: raise ValueError('module argument must be an actual imported ' 'module, or the import name of the module; ' f'got {repr(module)}') try: module_version = metadata.version(module_name) except metadata.PackageNotFoundError: # Maybe the distribution name is different from package name. # Calling packages_distributions is costly so we do it only # if necessary, as only a few packages don't have the same # distribution name. dist_names = packages_distributions() module_version = metadata.version(dist_names[module_name][0]) if inclusive: return Version(module_version) >= Version(version) else: return Version(module_version) > Version(version)
async def jsk(self, ctx: commands.Context): # pylint: disable=too-many-branches """ The Jishaku debug and diagnostic commands. This command on its own gives a status brief. All other functionality is within its subcommands. """ package_name = packages_distributions()['discord'][0] summary = [ f"Jishaku v{package_version('jishaku')}, {package_name} `{package_version(package_name)}`, " f"`Python {sys.version}` on `{sys.platform}`".replace("\n", ""), f"Module was loaded <t:{self.load_time.timestamp():.0f}:R>, " f"cog was loaded <t:{self.start_time.timestamp():.0f}:R>.", "" ] # detect if [procinfo] feature is installed if psutil: try: proc = psutil.Process() with proc.oneshot(): try: mem = proc.memory_full_info() summary.append( f"Using {natural_size(mem.rss)} physical memory and " f"{natural_size(mem.vms)} virtual memory, " f"{natural_size(mem.uss)} of which unique to this process." ) except psutil.AccessDenied: pass try: name = proc.name() pid = proc.pid thread_count = proc.num_threads() summary.append( f"Running on PID {pid} (`{name}`) with {thread_count} thread(s)." ) except psutil.AccessDenied: pass summary.append("") # blank line except psutil.AccessDenied: summary.append( "psutil is installed, but this process does not have high enough access rights " "to query process information.") summary.append("") # blank line cache_summary = f"{len(self.bot.guilds)} guild(s) and {len(self.bot.users)} user(s)" # Show shard settings to summary if isinstance(self.bot, discord.AutoShardedClient): if len(self.bot.shards) > 20: summary.append( f"This bot is automatically sharded ({len(self.bot.shards)} shards of {self.bot.shard_count})" f" and can see {cache_summary}.") else: shard_ids = ', '.join(str(i) for i in self.bot.shards.keys()) summary.append( f"This bot is automatically sharded (Shards {shard_ids} of {self.bot.shard_count})" f" and can see {cache_summary}.") elif self.bot.shard_count: summary.append( f"This bot is manually sharded (Shard {self.bot.shard_id} of {self.bot.shard_count})" f" and can see {cache_summary}.") else: summary.append( f"This bot is not sharded and can see {cache_summary}.") # pylint: disable=protected-access if self.bot._connection.max_messages: message_cache = f"Message cache capped at {self.bot._connection.max_messages}" else: message_cache = "Message cache is disabled" if discord.version_info >= (1, 5, 0): presence_intent = f"presence intent is {'enabled' if self.bot.intents.presences else 'disabled'}" members_intent = f"members intent is {'enabled' if self.bot.intents.members else 'disabled'}" summary.append( f"{message_cache}, {presence_intent} and {members_intent}.") else: guild_subscriptions = f"guild subscriptions are {'enabled' if self.bot._connection.guild_subscriptions else 'disabled'}" summary.append(f"{message_cache} and {guild_subscriptions}.") # pylint: enable=protected-access # Show websocket latency in milliseconds summary.append( f"Average websocket latency: {round(self.bot.latency * 1000, 2)}ms" ) await ctx.send("\n".join(summary))
async def jsk(self, ctx: Context): """ The Jishaku debug and diagnostic commands. This command on its own gives a status brief. All other functionality is within its subcommands. """ distributions = [ dist for dist in packages_distributions()["discord"] if any(file.parts == ("discord", "__init__.py") for file in distribution(dist).files) ] if distributions: dist_version = f"{distributions[0]} `{package_version(distributions[0])}`" else: dist_version = f"unknown `{discord.__version__}`" summary = [ f"Jishaku `v{package_version('jishaku')}`, {dist_version}, " f"Python `{sys.version}` on `{sys.platform}`, ".replace("\n", ""), f"Jishaku was loaded {format_dt(self.load_time, 'R')} " f"and cog was loaded {format_dt(self.start_time, 'R')}.", "", ] if psutil: try: proc = psutil.Process() with proc.oneshot(): try: mem = proc.memory_full_info() summary.append( f"This process is using {naturalsize(mem.rss)} physical memory and " f"{naturalsize(mem.vms)} virtual memory, " f"{naturalsize(mem.uss)} of which is unique to this process." ) except psutil.AccessDenied: pass try: name = proc.name() pid = proc.pid tc = proc.num_threads() summary.append(f"This process is running on PID `{pid}` (`{name}`) with {tc} threads.") except psutil.AccessDenied: pass summary.append("") except psutil.AccessDenied: summary.append("psutil is installed but this process does not have access to display this information") summary.append("") guilds = f"{len(self.bot.guilds):,} guilds" humans = f"{sum(not m.bot for m in self.bot.users):,} humans" bots = f"{sum(m.bot for m in self.bot.users):,} bots" users = f"{len(self.bot.users):,} users" cache_summary = f"can see {guilds}, {humans}, and {bots}, totaling to {users}." if isinstance(self.bot, discord.AutoShardedClient): if len(self.bot.shards) > 20: summary.append( f"This bot is automatically sharded ({len(self.bot.shards)} shards of {self.bot.shard_count}) " f"and {cache_summary}" ) else: shard_ids = ", ".join(str(i) for i in self.bot.shards.keys()) summary.append( f"This bot is automatically sharded (Shards {shard_ids} of {self.bot.shard_count})" f"and {cache_summary}" ) elif self.bot.shard_count: summary.append( f"This bot is manually sharded (Shard {self.bot.shard_id} of {self.bot.shard_count})" f"and {cache_summary}" ) else: summary.append(f"This bot is not sharded and {cache_summary}") if self.bot._connection.max_messages: message_cache = f"Message cache is capped at {self.bot._connection.max_messages}." else: message_cache = "Message cache is not enabled." summary.append(message_cache) presence_intent = f"Presences intent `{'enabled' if self.bot.intents.presences else 'disabled'}`" members_intent = f"Members intent `{'enabled' if self.bot.intents.members else 'disabled'}`" message_intent = f"Message intent `{'enabled' if self.bot.intents.message_content else 'disabled'}`" summary.append(f"{presence_intent}, {members_intent} and {message_intent}.") summary.append("") summary.append(f"Average websocket latency: `{round(self.bot.latency * 1000)}ms`") jishaku_embed = discord.Embed(description="\n".join(summary)) await ctx.send(embed=jishaku_embed)
def test_packages_distributions_example(self): self._fixture_on_path('example-21.12-py3-none-any.whl') assert packages_distributions()['example'] == ['example']