Skip to content

Commit

Permalink
Add User-Agent "pypi-cleanup/<version> (requests/<requests version>)"…
Browse files Browse the repository at this point in the history
… to the request headers

Add LICENSE to the package.
Add version to the --help header.

fixes #34
  • Loading branch information
arcivanov committed Jun 24, 2024
1 parent e205f17 commit 7c1baa7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use_plugin("python.coverage")
use_plugin("python.distutils")
use_plugin("python.pycharm")
use_plugin("copy_resources")
use_plugin("filter_resources")


name = "pypi-cleanup"
version = "0.1.7.dev"
Expand Down Expand Up @@ -57,7 +60,10 @@ def set_properties(project):
project.set_property("flake8_max_line_length", 130)

project.set_property("copy_resources_target", "$dir_dist/pypi_cleanup")
project.get_property("copy_resources_glob").append("LICENSE")
project.include_file("pypi_cleanup", "LICENSE")
project.set_property("filter_resources_target", "$dir_dist")
project.get_property("filter_resources_glob").append("pypi_cleanup/__version__.py")

project.set_property("distutils_readme_description", True)
project.set_property("distutils_description_overwrite", True)
Expand Down
7 changes: 6 additions & 1 deletion src/main/python/pypi_cleanup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
from urllib.parse import urlparse

import requests
from requests.__version__ import __version__ as requests_version
from requests.exceptions import RequestException

from pypi_cleanup.__version__ import __version__

DEFAULT_PATTERNS = [re.compile(r".*\.dev\d+$")]


Expand Down Expand Up @@ -97,6 +100,8 @@ def run(self):
logging.info(f"Will use the following patterns {self.patterns} on package {self.package!r}")

with requests.Session() as s:
s.headers.update({"User-Agent": f"pypi-cleanup/{__version__} (requests/{requests_version})"})

with s.get(f"{self.url}/simple/{self.package}/",
headers={"Accept": "application/vnd.pypi.simple.v1+json"}) as r:
try:
Expand Down Expand Up @@ -251,7 +256,7 @@ def main():
logging.basicConfig(level=logging.INFO)

try:
parser = argparse.ArgumentParser(description="PyPi Package Cleanup Utility",
parser = argparse.ArgumentParser(description=f"PyPi Package Cleanup Utility v{__version__}",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-u", "--username", help="authentication username")
parser.add_argument("-p", "--package", required=True, help="PyPI package name")
Expand Down
17 changes: 17 additions & 0 deletions src/main/python/pypi_cleanup/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2024 Arcadiy Ivanov <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

__version__ = "${dist_version}"

0 comments on commit 7c1baa7

Please sign in to comment.