Skip to content

Commit

Permalink
Rename the default publishing plugin from pypi to the more generic …
Browse files Browse the repository at this point in the history
…`index` (#342)
  • Loading branch information
ofek authored Jul 10, 2022
1 parent 9b9dbd5 commit 3d0326a
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 55 deletions.
4 changes: 4 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Unreleased

***Changed:***

- Rename the default publishing plugin from `pypi` to the more generic `index`

***Added:***

- Support the absence of `pyproject.toml` files, as is the case for apps and non-Python projects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# PyPI publisher
# Index publisher

-----

See the documentation for [publishing](../../publish.md).

## Configuration

The publisher plugin name is `pypi`.
The publisher plugin name is `index`.

=== ":octicons-file-code-16: config.toml"

```toml
[publish.pypi]
[publish.index]
```

## Options
Expand Down
16 changes: 8 additions & 8 deletions docs/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

After your project is [built](build.md), you can distribute it using the [`publish`](cli/reference.md#hatch-publish) command.

The `-p`/`--publisher` option controls which publisher to use, with the default being [pypi](plugins/publisher/pypi.md).
The `-p`/`--publisher` option controls which publisher to use, with the default being [index](plugins/publisher/index.md).

## Artifact selection

Expand All @@ -29,14 +29,14 @@ Only files ending with `.whl` or `.tar.gz` will be published.

## Repository

You can select the repository (package index) with which to upload using the `-r`/`--repo` option or by setting the `HATCH_PYPI_REPO` environment variable.
You can select the repository with which to upload using the `-r`/`--repo` option or by setting the `HATCH_INDEX_REPO` environment variable.

Rather than specifying the full URL of a repository, you can use a named repository from a `publish.pypi.repos` table defined in Hatch's [config file](config/hatch.md):
Rather than specifying the full URL of a repository, you can use a named repository from a `publish.index.repos` table defined in Hatch's [config file](config/hatch.md):

=== ":octicons-file-code-16: config.toml"

```toml
[publish.pypi.repos]
[publish.index.repos]
repo1 = "url1"
...
```
Expand All @@ -52,7 +52,7 @@ The `main` repository is used by default.

## Authentication

The first time you publish to a repository you need to authenticate using the `-u`/`--user` (environment variable `HATCH_PYPI_USER`) and `-a`/`--auth` (environment variable `HATCH_PYPI_AUTH`) options. You will be prompted if either option is not provided.
The first time you publish to a repository you need to authenticate using the `-u`/`--user` (environment variable `HATCH_INDEX_USER`) and `-a`/`--auth` (environment variable `HATCH_INDEX_AUTH`) options. You will be prompted if either option is not provided.

The user that most recently published to the chosen repository is [cached](config/hatch.md#cache), with their credentials saved to the system [keyring](https://github.com/jaraco/keyring), so that they will no longer need to provide authentication information.

Expand All @@ -65,20 +65,20 @@ You can require a confirmation prompt or use of the `-y`/`--yes` flag by setting
=== ":octicons-file-code-16: config.toml"

```toml
[publish.pypi]
[publish.index]
disable = true
```

=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.publish.pypi]
[tool.hatch.publish.index]
disable = true
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[publish.pypi]
[publish.index]
disable = true
```
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ nav:
- Default: plugins/environment-collector/default.md
- Publisher:
- Reference: plugins/publisher/reference.md
- PyPI: plugins/publisher/pypi.md
- Index: plugins/publisher/index.md
- Version source:
- Reference: plugins/version-source/reference.md
- Regex: plugins/version-source/regex.md
Expand Down
14 changes: 7 additions & 7 deletions src/hatch/cli/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
@click.command(short_help='Publish build artifacts')
@click.argument('artifacts', nargs=-1)
@click.option(
'--user', '-u', envvar=PublishEnvVars.USER, help='The user with which to authenticate [env var: `HATCH_PYPI_USER`]'
'--user', '-u', envvar=PublishEnvVars.USER, help='The user with which to authenticate [env var: `HATCH_INDEX_USER`]'
)
@click.option(
'--auth',
'-a',
envvar=PublishEnvVars.AUTH,
help='The credentials to use for authentication [env var: `HATCH_PYPI_AUTH`]',
help='The credentials to use for authentication [env var: `HATCH_INDEX_AUTH`]',
)
@click.option(
'--repo',
'-r',
envvar=PublishEnvVars.REPO,
help='The repository with which to publish artifacts [env var: `HATCH_PYPI_REPO`]',
help='The repository with which to publish artifacts [env var: `HATCH_INDEX_REPO`]',
)
@click.option('--no-prompt', '-n', is_flag=True, help='Disable prompts, such as for missing required fields')
@click.option(
'--publisher',
'-p',
'publisher_name',
envvar=PublishEnvVars.PUBLISHER,
default='pypi',
help='The publisher plugin to use (default is `pypi`) [env var: `HATCH_PUBLISHER`]',
default='index',
help='The publisher plugin to use (default is `index`) [env var: `HATCH_PUBLISHER`]',
)
@click.option(
'--option',
Expand All @@ -45,9 +45,9 @@
def publish(app, artifacts, user, auth, repo, no_prompt, publisher_name, options, yes):
"""Publish build artifacts."""
option_map = {'no_prompt': no_prompt}
if publisher_name == 'pypi':
if publisher_name == 'index':
if options:
app.abort('Use the standard CLI flags rather than passing explicit options when using the `pypi` plugin')
app.abort('Use the standard CLI flags rather than passing explicit options when using the `index` plugin')

if user:
option_map['user'] = user
Expand Down
6 changes: 3 additions & 3 deletions src/hatch/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ConfigEnvVars:


class PublishEnvVars:
USER = 'HATCH_PYPI_USER'
AUTH = 'HATCH_PYPI_AUTH'
REPO = 'HATCH_PYPI_REPO'
USER = 'HATCH_INDEX_USER'
AUTH = 'HATCH_INDEX_AUTH'
REPO = 'HATCH_INDEX_REPO'
PUBLISHER = 'HATCH_PUBLISHER'
OPTIONS = 'HATCH_PUBLISHER_OPTIONS'
2 changes: 1 addition & 1 deletion src/hatch/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def publish(self):

self._field_publish = publish
else:
self._field_publish = self.raw_data['publish'] = {'pypi': {'user': '', 'auth': ''}}
self._field_publish = self.raw_data['publish'] = {'index': {'user': '', 'auth': ''}}

return self._field_publish

Expand Down
4 changes: 2 additions & 2 deletions src/hatch/publish/pypi.py → src/hatch/publish/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
RENAMED_METADATA_FIELDS = {'classifier': 'classifiers', 'project_url': 'project_urls'}


class PyPIPublisher(PublisherInterface):
PLUGIN_NAME = 'pypi'
class IndexPublisher(PublisherInterface):
PLUGIN_NAME = 'index'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/hatch/publish/plugin/hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hatch.publish.pypi import PyPIPublisher
from hatch.publish.index import IndexPublisher
from hatchling.plugin import hookimpl


@hookimpl
def hatch_register_publisher():
return PyPIPublisher
return IndexPublisher
14 changes: 7 additions & 7 deletions tests/cli/config/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ def test_standard_complex_map(hatch, config_file, helpers):


def test_standard_hidden(hatch, config_file, helpers):
result = hatch('config', 'set', 'publish.pypi.auth', 'foo')
result = hatch('config', 'set', 'publish.index.auth', 'foo')

assert result.exit_code == 0, result.output
assert result.output == helpers.dedent(
"""
New setting:
[publish.pypi]
[publish.index]
auth = "<...>"
"""
)

config_file.load()
assert config_file.model.publish['pypi']['auth'] == 'foo'
assert config_file.model.publish['index']['auth'] == 'foo'


def test_prompt(hatch, config_file, helpers):
Expand All @@ -96,20 +96,20 @@ def test_prompt(hatch, config_file, helpers):


def test_prompt_hidden(hatch, config_file, helpers):
result = hatch('config', 'set', 'publish.pypi.auth', input='foo')
result = hatch('config', 'set', 'publish.index.auth', input='foo')

assert result.exit_code == 0, result.output
assert result.output == helpers.dedent(
f"""
Value for `publish.pypi.auth`:{' '}
Value for `publish.index.auth`:{' '}
New setting:
[publish.pypi]
[publish.index]
auth = "<...>"
"""
)

config_file.load()
assert config_file.model.publish['pypi']['auth'] == 'foo'
assert config_file.model.publish['index']['auth'] == 'foo'


def test_prevent_invalid_config(hatch, config_file, helpers):
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/config/test_show.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def test_default_scrubbed(hatch, config_file, helpers, default_cache_dir, default_data_dir):
config_file.model.project = 'foo'
config_file.model.publish['pypi']['auth'] = 'bar'
config_file.model.publish['index']['auth'] = 'bar'
config_file.save()

result = hatch('config', 'show')
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_default_scrubbed(hatch, config_file, helpers, default_cache_dir, defaul

def test_reveal(hatch, config_file, helpers, default_cache_dir, default_data_dir):
config_file.model.project = 'foo'
config_file.model.publish['pypi']['auth'] = 'bar'
config_file.model.publish['index']['auth'] = 'bar'
config_file.save()

result = hatch('config', 'show', '-a')
Expand All @@ -79,7 +79,7 @@ def test_reveal(hatch, config_file, helpers, default_cache_dir, default_data_dir
[projects]
[publish.pypi]
[publish.index]
user = ""
auth = "bar"
Expand Down
30 changes: 15 additions & 15 deletions tests/cli/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_explicit_options(hatch, temp_dir):

assert result.exit_code == 1, result.output
assert result.output == (
'Use the standard CLI flags rather than passing explicit options when using the `pypi` plugin\n'
'Use the standard CLI flags rather than passing explicit options when using the `index` plugin\n'
)


Expand All @@ -131,7 +131,7 @@ def test_unknown_publisher(hatch, temp_dir):


def test_disabled(hatch, temp_dir, config_file):
config_file.model.publish['pypi']['disable'] = True
config_file.model.publish['index']['disable'] = True
config_file.save()

project_name = 'My App'
Expand All @@ -146,7 +146,7 @@ def test_disabled(hatch, temp_dir, config_file):
result = hatch('publish', '-n')

assert result.exit_code == 1, result.output
assert result.output == 'Publisher is disabled: pypi\n'
assert result.output == 'Publisher is disabled: index\n'


def test_missing_user(hatch, temp_dir):
Expand Down Expand Up @@ -216,9 +216,9 @@ def test_flags(hatch, temp_dir_cache, helpers, published_project_name):


def test_plugin_config(hatch, temp_dir_cache, helpers, published_project_name, config_file):
config_file.model.publish['pypi']['user'] = '__token__'
config_file.model.publish['pypi']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['pypi']['repo'] = 'test'
config_file.model.publish['index']['user'] = '__token__'
config_file.model.publish['index']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['index']['repo'] = 'test'
config_file.save()

with temp_dir_cache.as_cwd():
Expand Down Expand Up @@ -426,10 +426,10 @@ def test_no_artifacts(hatch, temp_dir_cache, helpers, published_project_name):


def test_enable_with_flag(hatch, temp_dir_cache, helpers, published_project_name, config_file):
config_file.model.publish['pypi']['user'] = '__token__'
config_file.model.publish['pypi']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['pypi']['repo'] = 'test'
config_file.model.publish['pypi']['disable'] = True
config_file.model.publish['index']['user'] = '__token__'
config_file.model.publish['index']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['index']['repo'] = 'test'
config_file.model.publish['index']['disable'] = True
config_file.save()

with temp_dir_cache.as_cwd():
Expand Down Expand Up @@ -466,10 +466,10 @@ def test_enable_with_flag(hatch, temp_dir_cache, helpers, published_project_name


def test_enable_with_prompt(hatch, temp_dir_cache, helpers, published_project_name, config_file):
config_file.model.publish['pypi']['user'] = '__token__'
config_file.model.publish['pypi']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['pypi']['repo'] = 'test'
config_file.model.publish['pypi']['disable'] = True
config_file.model.publish['index']['user'] = '__token__'
config_file.model.publish['index']['auth'] = PUBLISHER_TOKEN
config_file.model.publish['index']['repo'] = 'test'
config_file.model.publish['index']['disable'] = True
config_file.save()

with temp_dir_cache.as_cwd():
Expand All @@ -496,7 +496,7 @@ def test_enable_with_prompt(hatch, temp_dir_cache, helpers, published_project_na
assert result.exit_code == 0, result.output
assert result.output == helpers.dedent(
f"""
Confirm `pypi` publishing [y/N]: y
Confirm `index` publishing [y/N]: y
{artifacts[0].relative_to(path)} ... success
{artifacts[1].relative_to(path)} ... success
Expand Down
6 changes: 3 additions & 3 deletions tests/config/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_default(default_cache_dir, default_data_dir):
'cache': str(default_cache_dir),
},
'projects': {},
'publish': {'pypi': {'user': '', 'auth': ''}},
'publish': {'index': {'user': '', 'auth': ''}},
'template': {
'name': 'Foo Bar',
'email': 'foo@bar.baz',
Expand Down Expand Up @@ -722,8 +722,8 @@ class TestPublish:
def test_default(self):
config = RootConfig({})

assert config.publish == config.publish == {'pypi': {'user': '', 'auth': ''}}
assert config.raw_data == {'publish': {'pypi': {'user': '', 'auth': ''}}}
assert config.publish == config.publish == {'index': {'user': '', 'auth': ''}}
assert config.raw_data == {'publish': {'index': {'user': '', 'auth': ''}}}

def test_defined(self):
config = RootConfig({'publish': {'foo': {'username': '', 'password': ''}}})
Expand Down

0 comments on commit 3d0326a

Please sign in to comment.