Skip to content

Commit 5caecd3

Browse files
committed
deployment starter code.
1 parent 8e80a6c commit 5caecd3

File tree

160 files changed

+5982
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+5982
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0.0
2+
---
3+
4+
- Initial version.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt *.ini *.cfg *.rst
2+
recursive-include pypi *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Python Package Index
2+
====================
3+
4+
Getting Started
5+
---------------
6+
7+
- Change directory into your newly created project.
8+
9+
cd pypi
10+
11+
- Create a Python virtual environment.
12+
13+
python3 -m venv env
14+
15+
- Upgrade packaging tools.
16+
17+
env/bin/pip install --upgrade pip setuptools
18+
19+
- Install the project in editable mode with its testing requirements.
20+
21+
env/bin/pip install -e ".[testing]"
22+
23+
- Run your project's tests.
24+
25+
env/bin/pytest
26+
27+
- Run your project.
28+
29+
env/bin/pserve development.ini
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# timezone to use when rendering the date
11+
# within the migration file as well as the filename.
12+
# string value is passed to dateutil.tz.gettz()
13+
# leave blank for localtime
14+
# timezone =
15+
16+
# max length of characters to apply to the
17+
# "slug" field
18+
#truncate_slug_length = 40
19+
20+
# set to 'true' to run the environment during
21+
# the 'revision' command, regardless of autogenerate
22+
# revision_environment = false
23+
24+
# set to 'true' to allow .pyc and .pyo files without
25+
# a source .py file to be detected as revisions in the
26+
# versions/ directory
27+
# sourceless = false
28+
29+
# version location specification; this defaults
30+
# to alembic/versions. When using multiple version
31+
# directories, initial revisions must be specified with --version-path
32+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
33+
34+
# the output encoding used when revision files
35+
# are written from script.py.mako
36+
# output_encoding = utf-8
37+
38+
sqlalchemy.url = sqlite:///./pypi/db/pypi.sqlite
39+
40+
41+
# Logging configuration
42+
[loggers]
43+
keys = root,sqlalchemy,alembic
44+
45+
[handlers]
46+
keys = console
47+
48+
[formatters]
49+
keys = generic
50+
51+
[logger_root]
52+
level = WARN
53+
handlers = console
54+
qualname =
55+
56+
[logger_sqlalchemy]
57+
level = WARN
58+
handlers =
59+
qualname = sqlalchemy.engine
60+
61+
[logger_alembic]
62+
level = INFO
63+
handlers =
64+
qualname = alembic
65+
66+
[handler_console]
67+
class = StreamHandler
68+
args = (sys.stderr,)
69+
level = NOTSET
70+
formatter = generic
71+
72+
[formatter_generic]
73+
format = %(levelname)-5.5s [%(name)s] %(message)s
74+
datefmt = %H:%M:%S
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from alembic import op
2+
from sqlalchemy import engine_from_config
3+
from sqlalchemy.engine import reflection
4+
5+
6+
def table_has_column(table, column):
7+
config = op.get_context().config
8+
engine = engine_from_config(
9+
config.get_section(config.config_ini_section), prefix='sqlalchemy.')
10+
insp = reflection.Inspector.from_engine(engine)
11+
has_column = False
12+
for col in insp.get_columns(table):
13+
if column not in col['name']:
14+
continue
15+
has_column = True
16+
return has_column
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from __future__ import with_statement
2+
from alembic import context
3+
from sqlalchemy import engine_from_config, pool
4+
from logging.config import fileConfig
5+
6+
from pypi.data.modelbase import SqlAlchemyBase
7+
# noinspection PyUnresolvedReferences
8+
from pypi.data import *
9+
10+
# this is the Alembic Config object, which provides
11+
# access to the values within the .ini file in use.
12+
config = context.config
13+
14+
# Interpret the config file for Python logging.
15+
# This line sets up loggers basically.
16+
fileConfig(config.config_file_name)
17+
18+
# add your model's MetaData object here
19+
# for 'autogenerate' support
20+
# from myapp import mymodel
21+
# target_metadata = mymodel.Base.metadata
22+
target_metadata = SqlAlchemyBase.metadata
23+
24+
# other values from the config, defined by the needs of env.py,
25+
# can be acquired:
26+
# my_important_option = config.get_main_option("my_important_option")
27+
# ... etc.
28+
29+
30+
def run_migrations_offline():
31+
"""Run migrations in 'offline' mode.
32+
33+
This configures the context with just a URL
34+
and not an Engine, though an Engine is acceptable
35+
here as well. By skipping the Engine creation
36+
we don't even need a DBAPI to be available.
37+
38+
Calls to context.execute() here emit the given string to the
39+
script output.
40+
41+
"""
42+
url = config.get_main_option("sqlalchemy.url")
43+
context.configure(
44+
url=url, target_metadata=target_metadata, literal_binds=True)
45+
46+
with context.begin_transaction():
47+
context.run_migrations()
48+
49+
50+
def run_migrations_online():
51+
"""Run migrations in 'online' mode.
52+
53+
In this scenario we need to create an Engine
54+
and associate a connection with the context.
55+
56+
"""
57+
connectable = engine_from_config(
58+
config.get_section(config.config_ini_section),
59+
prefix='sqlalchemy.',
60+
poolclass=pool.NullPool)
61+
62+
with connectable.connect() as connection:
63+
context.configure(
64+
connection=connection,
65+
target_metadata=target_metadata
66+
)
67+
68+
with context.begin_transaction():
69+
context.run_migrations()
70+
71+
if context.is_offline_mode():
72+
run_migrations_offline()
73+
else:
74+
run_migrations_online()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""last updated on package
2+
3+
Revision ID: 2fe1ec85206c
4+
Revises:
5+
Create Date: 2018-07-04 12:21:05.994401
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '2fe1ec85206c'
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('packages', sa.Column('last_updated', sa.DateTime(), nullable=True))
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.drop_column('packages', 'last_updated')
28+
# ### end Alembic commands ###
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Adding auditing
2+
3+
Revision ID: f289bc6bf8bc
4+
Revises: 2fe1ec85206c
5+
Create Date: 2018-07-04 12:25:10.377131
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
# revision identifiers, used by Alembic.
12+
revision = 'f289bc6bf8bc'
13+
down_revision = '2fe1ec85206c'
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.create_table('auditing',
21+
sa.Column('id', sa.String(), nullable=False),
22+
sa.Column('created_date', sa.DateTime(), nullable=True),
23+
sa.Column('description', sa.String(), nullable=True),
24+
sa.PrimaryKeyConstraint('id')
25+
)
26+
op.create_index(op.f('ix_auditing_created_date'), 'auditing', ['created_date'], unique=False)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_index(op.f('ix_auditing_created_date'), table_name='auditing')
33+
op.drop_table('auditing')
34+
# ### end Alembic commands ###
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
###
2+
# app configuration
3+
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:pypi
8+
9+
pyramid.reload_templates = true
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
pyramid.includes =
15+
pyramid_debugtoolbar
16+
17+
# By default, the toolbar only appears for clients from IP addresses
18+
# '127.0.0.1' and '::1'.
19+
# debugtoolbar.hosts = 127.0.0.1 ::1
20+
21+
###
22+
# wsgi server configuration
23+
###
24+
25+
[server:main]
26+
use = egg:waitress#main
27+
listen = localhost:6543
28+
29+
###
30+
# logging configuration
31+
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
32+
###
33+
34+
[loggers]
35+
keys = root, pypi
36+
37+
[handlers]
38+
keys = console
39+
40+
[formatters]
41+
keys = generic
42+
43+
[logger_root]
44+
level = INFO
45+
handlers = console
46+
47+
[logger_pypi]
48+
level = DEBUG
49+
handlers =
50+
qualname = pypi
51+
52+
[handler_console]
53+
class = StreamHandler
54+
args = (sys.stderr,)
55+
level = NOTSET
56+
formatter = generic
57+
58+
[formatter_generic]
59+
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s

0 commit comments

Comments
 (0)